summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael W <baddaemon87@gmail.com>2019-01-13 14:05:37 +0100
committerMichael Bestas <mkbestas@lineageos.org>2019-02-27 16:11:02 +0100
commitd13658a639b5b01ff59e031407b8815021d5c8aa (patch)
tree09c08ebb9806d91eb806922c642ed0e8a2d75e3d
parent25a391f5b1e234bf5b116e374d4f60a5d6646839 (diff)
downloadcm_crowdin-d13658a639b5b01ff59e031407b8815021d5c8aa.tar.gz
cm_crowdin-d13658a639b5b01ff59e031407b8815021d5c8aa.tar.bz2
cm_crowdin-d13658a639b5b01ff59e031407b8815021d5c8aa.zip
crowdin: Add option to submit all translation changes
* After a successful build, all changes have to be merged * Instead of doing so manually or using own scripts, integrate such a functionality into the existing script * Do the submit-check right at the beginning as we probably want to be able to submit on branches we haven't synced and we don't need all the files for this, anyway Change-Id: I78b21608e2495f946be7cf6354d0136372b71187
-rw-r--r--README.mkdn2
-rwxr-xr-xcrowdin_sync.py53
2 files changed, 54 insertions, 1 deletions
diff --git a/README.mkdn b/README.mkdn
index ac6dbf6..6dc56e8 100644
--- a/README.mkdn
+++ b/README.mkdn
@@ -44,7 +44,7 @@ Example:
Execute:
- ./crowdin_sync.py --username your_gerrit_username --branch lineage_version [--upload-sources] [--upload-translations] [--download]
+ ./crowdin_sync.py --username your_gerrit_username --branch lineage_version [--upload-sources] [--upload-translations] [--download] [--submit]
Bugs
----
diff --git a/crowdin_sync.py b/crowdin_sync.py
index 165596b..2817fb2 100755
--- a/crowdin_sync.py
+++ b/crowdin_sync.py
@@ -93,6 +93,50 @@ def push_as_commit(base_path, path, name, branch, username):
_COMMITS_CREATED = True
+def submit_gerrit(branch, username):
+ # Find all open translation changes
+ cmd = ['ssh', '-p', '29418',
+ '{}@review.lineageos.org'.format(username),
+ 'gerrit', 'query',
+ 'status:open',
+ 'branch:{}'.format(branch),
+ 'message:"Automatic translation import"',
+ 'topic:translation',
+ '--current-patch-set']
+ commits = []
+ msg, code = run_subprocess(cmd)
+ if code != 0:
+ print('Failed: {0}'.format(msg[1]))
+ return
+
+ for line in msg[0].split('\n'):
+ if "revision:" not in line:
+ continue;
+ elements = line.split(': ');
+ if len(elements) != 2:
+ print('Unexpected line found: {0}'.format(line))
+ commits.append(elements[1])
+
+ if len(commits) == 0:
+ print("Nothing to submit!")
+ return
+
+ for commit in commits:
+ # Add Code-Review +2 and Verified+1 labels and submit
+ cmd = ['ssh', '-p', '29418',
+ '{}@review.lineageos.org'.format(username),
+ 'gerrit', 'review',
+ '--verified +1',
+ '--code-review +2',
+ '--submit', commit]
+ msg, code = run_subprocess(cmd, True)
+ if code != 0:
+ errorText = msg[1].replace('\n\n', '; ').replace('\n', '')
+ print('Submitting commit {0} failed: {1}'.format(commit, errorText))
+ else:
+ print('Success when submitting commit {0}'.format(commit))
+
+
def check_run(cmd):
p = subprocess.Popen(cmd, stdout=sys.stdout, stderr=sys.stderr)
ret = p.wait()
@@ -123,6 +167,8 @@ def parse_args():
help='Upload translations to Crowdin')
parser.add_argument('--download', action='store_true',
help='Download translations from Crowdin')
+ parser.add_argument('-s', '--submit', action='store_true',
+ help='Merge open translation commits')
return parser.parse_args()
# ################################# PREPARE ################################## #
@@ -290,6 +336,13 @@ def main():
args = parse_args()
default_branch = args.branch
+ if args.submit:
+ if args.username is None:
+ print('Argument -u/--username is required for submitting!')
+ sys.exit(1)
+ submit_gerrit(default_branch, args.username)
+ sys.exit(0)
+
base_path_branch_suffix = default_branch.replace('-', '_').replace('.', '_').upper()
base_path_env = 'LINEAGE_CROWDIN_BASE_PATH_%s' % base_path_branch_suffix
base_path = os.getenv(base_path_env)