crowdin_sync: Add support for custom yaml config
* In some cases we need to sync specific projects only.
With this change we can provide a custom yaml config
to the sync script.
Change-Id: I03ff175c2b0a90cb6832902249c27ea665e7994d
diff --git a/crowdin_sync.py b/crowdin_sync.py
index 526b7de..ed6a0d9 100755
--- a/crowdin_sync.py
+++ b/crowdin_sync.py
@@ -114,6 +114,7 @@
required=True)
parser.add_argument('-b', '--branch', help='CyanogenMod branch',
required=True)
+ parser.add_argument('-c', '--config', help='Custom yaml config')
sync.add_argument('--no-upload', action='store_true',
help='Only download CM translations from Crowdin')
sync.add_argument('--no-download', action='store_true',
@@ -144,11 +145,7 @@
return None
-def check_files(branch):
- files = ['%s/crowdin/extra_packages_%s.xml' % (_DIR, branch),
- '%s/crowdin/crowdin_%s.yaml' % (_DIR, branch),
- '%s/crowdin/crowdin_%s_aosp.yaml' % (_DIR, branch)
- ]
+def check_files(files):
for f in files:
if not os.path.isfile(f):
print('You have no %s.' % f, file=sys.stderr)
@@ -158,37 +155,52 @@
# ################################### MAIN ################################### #
-def upload_crowdin(branch, no_upload=False):
+def upload_crowdin(branch, config, no_upload=False):
if no_upload:
print('Skipping source translations upload')
return
- print('\nUploading Crowdin source translations (AOSP supported languages)')
- check_run(['crowdin-cli',
- '--config=%s/crowdin/crowdin_%s.yaml' % (_DIR, branch),
- 'upload', 'sources'])
+ if config:
+ print('\nUploading Crowdin source translations (custom config)')
+ check_run(['crowdin-cli',
+ '--config=%s/crowdin/%s' % (_DIR, config),
+ 'upload', 'sources'])
+ else:
+ print('\nUploading Crowdin source translations '
+ '(AOSP supported languages)')
+ check_run(['crowdin-cli',
+ '--config=%s/crowdin/crowdin_%s.yaml' % (_DIR, branch),
+ 'upload', 'sources'])
- print('\nUploading Crowdin source translations '
- '(non-AOSP supported languages)')
- check_run(['crowdin-cli',
- '--config=%s/crowdin/crowdin_%s_aosp.yaml' % (_DIR, branch),
- 'upload', 'sources'])
+ print('\nUploading Crowdin source translations '
+ '(non-AOSP supported languages)')
+ check_run(['crowdin-cli',
+ '--config=%s/crowdin/crowdin_%s_aosp.yaml' % (_DIR, branch),
+ 'upload', 'sources'])
-def download_crowdin(base_path, branch, xml, username, no_download=False):
+def download_crowdin(base_path, branch, xml, username, config,
+ no_download=False):
if no_download:
print('Skipping translations download')
return
- print('\nDownloading Crowdin translations (AOSP supported languages)')
- check_run(['crowdin-cli',
- '--config=%s/crowdin/crowdin_%s.yaml' % (_DIR, branch),
- 'download', '--ignore-match'])
+ if config:
+ print('\nDownloading Crowdin translations (custom config)')
+ check_run(['crowdin-cli',
+ '--config=%s/crowdin/%s' % (_DIR, config),
+ 'download', '--ignore-match'])
+ else:
+ print('\nDownloading Crowdin translations (AOSP supported languages)')
+ check_run(['crowdin-cli',
+ '--config=%s/crowdin/crowdin_%s.yaml' % (_DIR, branch),
+ 'download', '--ignore-match'])
- print('\nDownloading Crowdin translations (non-AOSP supported languages)')
- check_run(['crowdin-cli',
- '--config=%s/crowdin/crowdin_%s_aosp.yaml' % (_DIR, branch),
- 'download', '--ignore-match'])
+ print('\nDownloading Crowdin translations '
+ '(non-AOSP supported languages)')
+ check_run(['crowdin-cli',
+ '--config=%s/crowdin/crowdin_%s_aosp.yaml' % (_DIR, branch),
+ 'download', '--ignore-match'])
print('\nRemoving useless empty translation files')
empty_contents = {
@@ -214,10 +226,12 @@
print('\nCreating a list of pushable translations')
# Get all files that Crowdin pushed
paths = []
- files = [
- ('%s/crowdin/crowdin_%s.yaml' % (_DIR, branch)),
- ('%s/crowdin/crowdin_%s_aosp.yaml' % (_DIR, branch))
- ]
+ if config:
+ files = ['%s/crowdin/%s' % (_DIR, config)]
+ else:
+ files = ['%s/crowdin/crowdin_%s.yaml' % (_DIR, branch),
+ '%s/crowdin/crowdin_%s_aosp.yaml' % (_DIR, branch)
+ ]
for c in files:
cmd = ['crowdin-cli', '--config=%s' % c, 'list', 'sources']
comm, ret = run_subprocess(cmd)
@@ -301,12 +315,18 @@
if xml_extra is None:
sys.exit(1)
- if not check_files(default_branch):
+ if args.config:
+ files = ['%s/crowdin/%s' % (_DIR, args.config)]
+ else:
+ files = ['%s/crowdin/crowdin_%s.yaml' % (_DIR, default_branch),
+ '%s/crowdin/crowdin_%s_aosp.yaml' % (_DIR, default_branch)
+ ]
+ if not check_files(files):
sys.exit(1)
- upload_crowdin(default_branch, args.no_upload)
+ upload_crowdin(default_branch, args.config, args.no_upload)
download_crowdin(base_path, default_branch, (xml_android, xml_extra),
- args.username, args.no_download)
+ args.username, args.config, args.no_download)
print('\nDone!')
if __name__ == '__main__':