blob: a7dae8b617af2eee1b0ba4e27fc3c3899d5e4ce3 [file] [log] [blame]
Anthony Kingb8607632015-05-01 22:06:37 +03001#!/usr/bin/env python
Marco Brohetcb5cdb42014-07-11 22:41:53 +02002# -*- coding: utf-8 -*-
Michael Bestas1ab959b2014-07-26 16:01:01 +03003# crowdin_sync.py
Marco Brohetcb5cdb42014-07-11 22:41:53 +02004#
5# Updates Crowdin source translations and pushes translations
Abhisek Devkotab78def42016-12-27 13:06:52 -08006# directly to LineageOS' Gerrit.
Marco Brohetcb5cdb42014-07-11 22:41:53 +02007#
Michael Bestas97677e12015-02-08 13:11:59 +02008# Copyright (C) 2014-2015 The CyanogenMod Project
Marco Brohetcb5cdb42014-07-11 22:41:53 +02009#
10# Licensed under the Apache License, Version 2.0 (the "License");
11# you may not use this file except in compliance with the License.
12# You may obtain a copy of the License at
13#
14# http://www.apache.org/licenses/LICENSE-2.0
15#
16# Unless required by applicable law or agreed to in writing, software
17# distributed under the License is distributed on an "AS IS" BASIS,
18# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19# See the License for the specific language governing permissions and
20# limitations under the License.
21
Anthony Kingb8607632015-05-01 22:06:37 +030022# ################################# IMPORTS ################################## #
23
24from __future__ import print_function
Marco Brohet6b6b4e52014-07-20 00:05:16 +020025
26import argparse
Marco Brohetcb5cdb42014-07-11 22:41:53 +020027import git
28import os
Marco Brohetcb5cdb42014-07-11 22:41:53 +020029import subprocess
30import sys
Anthony Kingb8607632015-05-01 22:06:37 +030031
Marco Brohetcb5cdb42014-07-11 22:41:53 +020032from xml.dom import minidom
33
Anthony Kingd0d56cf2015-06-05 10:48:38 +010034# ################################# GLOBALS ################################## #
35
36_DIR = os.path.dirname(os.path.realpath(__file__))
Tom Powell44256852016-07-06 15:23:25 -070037_COMMITS_CREATED = False
Anthony Kingd0d56cf2015-06-05 10:48:38 +010038
Anthony Kingb8607632015-05-01 22:06:37 +030039# ################################ FUNCTIONS ################################# #
40
41
42def run_subprocess(cmd, silent=False):
43 p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
44 universal_newlines=True)
45 comm = p.communicate()
46 exit_code = p.returncode
47 if exit_code != 0 and not silent:
48 print("There was an error running the subprocess.\n"
49 "cmd: %s\n"
50 "exit code: %d\n"
51 "stdout: %s\n"
52 "stderr: %s" % (cmd, exit_code, comm[0], comm[1]),
53 file=sys.stderr)
54 return comm, exit_code
55
Marco Brohet6b6b4e52014-07-20 00:05:16 +020056
Michael Bestasdb69b932016-03-12 21:08:27 +020057def push_as_commit(base_path, path, name, branch, username, ticket):
Anthony Kingb8607632015-05-01 22:06:37 +030058 print('Committing %s on branch %s' % (name, branch))
Marco Brohetcb5cdb42014-07-11 22:41:53 +020059
60 # Get path
Michael Bestas118fcaf2015-06-04 23:02:20 +030061 path = os.path.join(base_path, path)
Anthony Kingb8607632015-05-01 22:06:37 +030062 if not path.endswith('.git'):
63 path = os.path.join(path, '.git')
Marco Brohetcb5cdb42014-07-11 22:41:53 +020064
Marco Brohet6b6b4e52014-07-20 00:05:16 +020065 # Create repo object
Marco Brohetcb5cdb42014-07-11 22:41:53 +020066 repo = git.Repo(path)
Marco Brohet6b6b4e52014-07-20 00:05:16 +020067
68 # Remove previously deleted files from Git
Anthony Kingb8607632015-05-01 22:06:37 +030069 files = repo.git.ls_files(d=True).split('\n')
70 if files and files[0]:
71 repo.git.rm(files)
Marco Brohet6b6b4e52014-07-20 00:05:16 +020072
73 # Add all files to commit
Marco Brohetcb5cdb42014-07-11 22:41:53 +020074 repo.git.add('-A')
Marco Brohet6b6b4e52014-07-20 00:05:16 +020075
76 # Create commit; if it fails, probably empty so skipping
Michael Bestasdb69b932016-03-12 21:08:27 +020077 if ticket:
78 message = '''Automatic translation import
79
80Ticket: %s''' % ticket
81 else:
82 message = 'Automatic translation import'
83
Marco Brohetcb5cdb42014-07-11 22:41:53 +020084 try:
Michael Bestasdb69b932016-03-12 21:08:27 +020085 repo.git.commit(m=message)
Marco Brohetcb5cdb42014-07-11 22:41:53 +020086 except:
Anthony Kingb8607632015-05-01 22:06:37 +030087 print('Failed to create commit for %s, probably empty: skipping'
88 % name, file=sys.stderr)
Marco Brohetcb5cdb42014-07-11 22:41:53 +020089 return
Marco Brohet6b6b4e52014-07-20 00:05:16 +020090
91 # Push commit
Michael Bestasf96f67b2014-10-21 00:43:37 +030092 try:
Abhisek Devkotab78def42016-12-27 13:06:52 -080093 repo.git.push('ssh://%s@review.lineageos.org:29418/%s' % (username, name),
Anthony Kingb8607632015-05-01 22:06:37 +030094 'HEAD:refs/for/%s%%topic=translation' % branch)
95 print('Successfully pushed commit for %s' % name)
Michael Bestasf96f67b2014-10-21 00:43:37 +030096 except:
Anthony Kingb8607632015-05-01 22:06:37 +030097 print('Failed to push commit for %s' % name, file=sys.stderr)
Marco Brohetcb5cdb42014-07-11 22:41:53 +020098
Tom Powell44256852016-07-06 15:23:25 -070099 _COMMITS_CREATED = True
100
Anthony Kingb8607632015-05-01 22:06:37 +0300101
102def check_run(cmd):
Michael Bestas97677e12015-02-08 13:11:59 +0200103 p = subprocess.Popen(cmd, stdout=sys.stdout, stderr=sys.stderr)
104 ret = p.wait()
105 if ret != 0:
Anthony Kingb8607632015-05-01 22:06:37 +0300106 print('Failed to run cmd: %s' % ' '.join(cmd), file=sys.stderr)
Michael Bestas97677e12015-02-08 13:11:59 +0200107 sys.exit(ret)
108
Marco Brohet6b6b4e52014-07-20 00:05:16 +0200109
Michael Bestas118fcaf2015-06-04 23:02:20 +0300110def find_xml(base_path):
111 for dp, dn, file_names in os.walk(base_path):
Anthony Kingb8607632015-05-01 22:06:37 +0300112 for f in file_names:
113 if os.path.splitext(f)[1] == '.xml':
114 yield os.path.join(dp, f)
Marco Brohet6b6b4e52014-07-20 00:05:16 +0200115
Anthony Kingb8607632015-05-01 22:06:37 +0300116# ############################################################################ #
Marco Brohet6b6b4e52014-07-20 00:05:16 +0200117
Michael Bestas6b6db122015-02-08 13:22:22 +0200118
Anthony Kingb8607632015-05-01 22:06:37 +0300119def parse_args():
120 parser = argparse.ArgumentParser(
Abhisek Devkotab78def42016-12-27 13:06:52 -0800121 description="Synchronising LineageOS' translations with Crowdin")
Michael Bestasfd5d1362015-12-18 20:34:32 +0200122 parser.add_argument('-u', '--username', help='Gerrit username')
Abhisek Devkotab78def42016-12-27 13:06:52 -0800123 parser.add_argument('-b', '--branch', help='LineageOS branch',
Anthony Kingb8607632015-05-01 22:06:37 +0300124 required=True)
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300125 parser.add_argument('-c', '--config', help='Custom yaml config')
Michael Bestasdb69b932016-03-12 21:08:27 +0200126 parser.add_argument('-t', '--ticket', help='JIRA ticket')
Michael Bestasfd5d1362015-12-18 20:34:32 +0200127 parser.add_argument('--upload-sources', action='store_true',
128 help='Upload sources to Crowdin')
129 parser.add_argument('--upload-translations', action='store_true',
130 help='Upload translations to Crowdin')
131 parser.add_argument('--download', action='store_true',
132 help='Download translations from Crowdin')
Anthony Kingb8607632015-05-01 22:06:37 +0300133 return parser.parse_args()
Michael Bestas6b6db122015-02-08 13:22:22 +0200134
Anthony Kingb8607632015-05-01 22:06:37 +0300135# ################################# PREPARE ################################## #
Marco Brohet6b6b4e52014-07-20 00:05:16 +0200136
Anthony Kingb8607632015-05-01 22:06:37 +0300137
138def check_dependencies():
Anthony Kingb8607632015-05-01 22:06:37 +0300139 # Check for Ruby version of crowdin-cli
140 cmd = ['gem', 'list', 'crowdin-cli', '-i']
141 if run_subprocess(cmd, silent=True)[1] != 0:
142 print('You have not installed crowdin-cli.', file=sys.stderr)
143 return False
Anthony Kingb8607632015-05-01 22:06:37 +0300144 return True
Marco Brohetcb5cdb42014-07-11 22:41:53 +0200145
Marco Brohetcb5cdb42014-07-11 22:41:53 +0200146
Michael Bestas118fcaf2015-06-04 23:02:20 +0300147def load_xml(x):
Anthony Kingb8607632015-05-01 22:06:37 +0300148 try:
149 return minidom.parse(x)
150 except IOError:
151 print('You have no %s.' % x, file=sys.stderr)
152 return None
153 except Exception:
154 # TODO: minidom should not be used.
155 print('Malformed %s.' % x, file=sys.stderr)
156 return None
Marco Brohet6b6b4e52014-07-20 00:05:16 +0200157
Michael Bestas4b26c4e2014-10-23 23:21:59 +0300158
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300159def check_files(files):
Anthony Kingb8607632015-05-01 22:06:37 +0300160 for f in files:
161 if not os.path.isfile(f):
162 print('You have no %s.' % f, file=sys.stderr)
163 return False
Anthony Kingb8607632015-05-01 22:06:37 +0300164 return True
Michael Bestas4b26c4e2014-10-23 23:21:59 +0300165
Anthony Kingb8607632015-05-01 22:06:37 +0300166# ################################### MAIN ################################### #
Michael Bestas4b26c4e2014-10-23 23:21:59 +0300167
Michael Bestas4b26c4e2014-10-23 23:21:59 +0300168
Michael Bestasfd5d1362015-12-18 20:34:32 +0200169def upload_sources_crowdin(branch, config):
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300170 if config:
Michael Bestasfd5d1362015-12-18 20:34:32 +0200171 print('\nUploading sources to Crowdin (custom config)')
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300172 check_run(['crowdin-cli',
Michael Bestas03bc7052016-03-12 03:19:10 +0200173 '--config=%s/config/%s' % (_DIR, config),
Michael Bestas44fbb352015-12-17 02:01:42 +0200174 'upload', 'sources', '--branch=%s' % branch])
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300175 else:
Michael Bestasfd5d1362015-12-18 20:34:32 +0200176 print('\nUploading sources to Crowdin (AOSP supported languages)')
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300177 check_run(['crowdin-cli',
Michael Bestas03bc7052016-03-12 03:19:10 +0200178 '--config=%s/config/%s.yaml' % (_DIR, branch),
Michael Bestas44fbb352015-12-17 02:01:42 +0200179 'upload', 'sources', '--branch=%s' % branch])
Anthony King69a95382015-02-08 18:44:10 +0000180
Michael Bestasfd5d1362015-12-18 20:34:32 +0200181 print('\nUploading sources to Crowdin (non-AOSP supported languages)')
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300182 check_run(['crowdin-cli',
Michael Bestas03bc7052016-03-12 03:19:10 +0200183 '--config=%s/config/%s_aosp.yaml' % (_DIR, branch),
Michael Bestas44fbb352015-12-17 02:01:42 +0200184 'upload', 'sources', '--branch=%s' % branch])
Anthony Kingb8607632015-05-01 22:06:37 +0300185
186
Michael Bestasfd5d1362015-12-18 20:34:32 +0200187def upload_translations_crowdin(branch, config):
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300188 if config:
Michael Bestasfd5d1362015-12-18 20:34:32 +0200189 print('\nUploading translations to Crowdin (custom config)')
190 check_run(['crowdin-cli',
Michael Bestas03bc7052016-03-12 03:19:10 +0200191 '--config=%s/config/%s' % (_DIR, config),
Michael Bestasfd5d1362015-12-18 20:34:32 +0200192 'upload', 'translations', '--branch=%s' % branch,
193 '--no-import-duplicates', '--import-eq-suggestions',
194 '--auto-approve-imported'])
195 else:
196 print('\nUploading translations to Crowdin '
197 '(AOSP supported languages)')
198 check_run(['crowdin-cli',
Michael Bestas03bc7052016-03-12 03:19:10 +0200199 '--config=%s/config/%s.yaml' % (_DIR, branch),
Michael Bestasfd5d1362015-12-18 20:34:32 +0200200 'upload', 'translations', '--branch=%s' % branch,
201 '--no-import-duplicates', '--import-eq-suggestions',
202 '--auto-approve-imported'])
203
204 print('\nUploading translations to Crowdin '
205 '(non-AOSP supported languages)')
206 check_run(['crowdin-cli',
Michael Bestas03bc7052016-03-12 03:19:10 +0200207 '--config=%s/config/%s_aosp.yaml' % (_DIR, branch),
Michael Bestasfd5d1362015-12-18 20:34:32 +0200208 'upload', 'translations', '--branch=%s' % branch,
209 '--no-import-duplicates', '--import-eq-suggestions',
210 '--auto-approve-imported'])
211
212
Michael Bestasdb69b932016-03-12 21:08:27 +0200213def download_crowdin(base_path, branch, xml, username, config, ticket):
Michael Bestasfd5d1362015-12-18 20:34:32 +0200214 if config:
215 print('\nDownloading translations from Crowdin (custom config)')
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300216 check_run(['crowdin-cli',
Michael Bestas03bc7052016-03-12 03:19:10 +0200217 '--config=%s/config/%s' % (_DIR, config),
Michael Bestas44fbb352015-12-17 02:01:42 +0200218 'download', '--branch=%s' % branch])
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300219 else:
Michael Bestasfd5d1362015-12-18 20:34:32 +0200220 print('\nDownloading translations from Crowdin '
221 '(AOSP supported languages)')
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300222 check_run(['crowdin-cli',
Michael Bestas03bc7052016-03-12 03:19:10 +0200223 '--config=%s/config/%s.yaml' % (_DIR, branch),
Michael Bestas44fbb352015-12-17 02:01:42 +0200224 'download', '--branch=%s' % branch])
Michael Bestas50579d22014-08-09 17:49:14 +0300225
Michael Bestasfd5d1362015-12-18 20:34:32 +0200226 print('\nDownloading translations from Crowdin '
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300227 '(non-AOSP supported languages)')
228 check_run(['crowdin-cli',
Michael Bestas03bc7052016-03-12 03:19:10 +0200229 '--config=%s/config/%s_aosp.yaml' % (_DIR, branch),
Michael Bestas44fbb352015-12-17 02:01:42 +0200230 'download', '--branch=%s' % branch])
Marco Brohetcb5cdb42014-07-11 22:41:53 +0200231
Michael Bestas99f5fce2015-06-04 22:07:51 +0300232 print('\nRemoving useless empty translation files')
Anthony Kingb8607632015-05-01 22:06:37 +0300233 empty_contents = {
234 '<resources/>',
235 '<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"/>',
236 ('<resources xmlns:android='
237 '"http://schemas.android.com/apk/res/android"/>'),
238 ('<resources xmlns:android="http://schemas.android.com/apk/res/android"'
239 ' xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"/>'),
240 ('<resources xmlns:tools="http://schemas.android.com/tools"'
241 ' xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"/>')
242 }
243 xf = None
Michael Bestas118fcaf2015-06-04 23:02:20 +0300244 for xml_file in find_xml(base_path):
Anthony Kingb8607632015-05-01 22:06:37 +0300245 xf = open(xml_file).read()
Michael Bestas919053f2014-10-20 23:30:54 +0300246 for line in empty_contents:
Anthony Kingb8607632015-05-01 22:06:37 +0300247 if line in xf:
Michael Bestas919053f2014-10-20 23:30:54 +0300248 print('Removing ' + xml_file)
249 os.remove(xml_file)
250 break
Anthony Kingb8607632015-05-01 22:06:37 +0300251 del xf
Marco Brohetcb5cdb42014-07-11 22:41:53 +0200252
Michael Bestas99f5fce2015-06-04 22:07:51 +0300253 print('\nCreating a list of pushable translations')
Michael Bestas919053f2014-10-20 23:30:54 +0300254 # Get all files that Crowdin pushed
Anthony Kingb8607632015-05-01 22:06:37 +0300255 paths = []
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300256 if config:
Michael Bestas03bc7052016-03-12 03:19:10 +0200257 files = ['%s/config/%s' % (_DIR, config)]
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300258 else:
Michael Bestas03bc7052016-03-12 03:19:10 +0200259 files = ['%s/config/%s.yaml' % (_DIR, branch),
260 '%s/config/%s_aosp.yaml' % (_DIR, branch)]
Michael Bestas6c327e62015-05-02 01:58:01 +0300261 for c in files:
Michael Bestas44fbb352015-12-17 02:01:42 +0200262 cmd = ['crowdin-cli', '--config=%s' % c, 'list', 'project',
263 '--branch=%s' % branch]
Anthony Kingb8607632015-05-01 22:06:37 +0300264 comm, ret = run_subprocess(cmd)
265 if ret != 0:
266 sys.exit(ret)
267 for p in str(comm[0]).split("\n"):
268 paths.append(p.replace('/%s' % branch, ''))
Michael Bestas50579d22014-08-09 17:49:14 +0300269
Michael Bestas99f5fce2015-06-04 22:07:51 +0300270 print('\nUploading translations to Gerrit')
Anthony Kingb8607632015-05-01 22:06:37 +0300271 items = [x for sub in xml for x in sub.getElementsByTagName('project')]
Michael Bestas919053f2014-10-20 23:30:54 +0300272 all_projects = []
273
Anthony Kingb8607632015-05-01 22:06:37 +0300274 for path in paths:
275 path = path.strip()
Michael Bestas919053f2014-10-20 23:30:54 +0300276 if not path:
277 continue
278
Anthony Kingb8607632015-05-01 22:06:37 +0300279 if "/res" not in path:
280 print('WARNING: Cannot determine project root dir of '
281 '[%s], skipping.' % path)
Anthony King69a95382015-02-08 18:44:10 +0000282 continue
Anthony Kingb8607632015-05-01 22:06:37 +0300283 result = path.split('/res')[0].strip('/')
284 if result == path.strip('/'):
285 print('WARNING: Cannot determine project root dir of '
286 '[%s], skipping.' % path)
287 continue
Marco Brohet6b6b4e52014-07-20 00:05:16 +0200288
Michael Bestasc899b8c2015-03-03 00:53:19 +0200289 if result in all_projects:
Michael Bestasc899b8c2015-03-03 00:53:19 +0200290 continue
Michael Bestas50579d22014-08-09 17:49:14 +0300291
Anthony Kingb8607632015-05-01 22:06:37 +0300292 # When a project has multiple translatable files, Crowdin will
293 # give duplicates.
294 # We don't want that (useless empty commits), so we save each
295 # project in all_projects and check if it's already in there.
Michael Bestasc899b8c2015-03-03 00:53:19 +0200296 all_projects.append(result)
Anthony King69a95382015-02-08 18:44:10 +0000297
Michael Bestas42e25e32016-03-12 20:18:39 +0200298 # Search android/default.xml or config/%(branch)_extra_packages.xml
Anthony Kingb8607632015-05-01 22:06:37 +0300299 # for the project's name
300 for project in items:
301 path = project.attributes['path'].value
302 if not (result + '/').startswith(path +'/'):
Michael Bestasc899b8c2015-03-03 00:53:19 +0200303 continue
Anthony Kingb8607632015-05-01 22:06:37 +0300304 if result != path:
305 if path in all_projects:
306 break
307 result = path
308 all_projects.append(result)
Anthony King69a95382015-02-08 18:44:10 +0000309
Anthony Kingb8607632015-05-01 22:06:37 +0300310 br = project.getAttribute('revision') or branch
Anthony King69a95382015-02-08 18:44:10 +0000311
Michael Bestas118fcaf2015-06-04 23:02:20 +0300312 push_as_commit(base_path, result,
Michael Bestasdb69b932016-03-12 21:08:27 +0200313 project.getAttribute('name'), br, username, ticket)
Anthony Kingb8607632015-05-01 22:06:37 +0300314 break
Anthony King69a95382015-02-08 18:44:10 +0000315
Anthony King69a95382015-02-08 18:44:10 +0000316
Anthony Kingb8607632015-05-01 22:06:37 +0300317def main():
Anthony Kingb8607632015-05-01 22:06:37 +0300318 args = parse_args()
319 default_branch = args.branch
Michael Bestas118fcaf2015-06-04 23:02:20 +0300320
Michael Bestas602fab22018-11-14 23:14:33 +0200321 base_path = os.getenv('CM_CROWDIN_BASE_PATH')
Michael Bestas118fcaf2015-06-04 23:02:20 +0300322 if base_path is None:
Anthony Kingd0d56cf2015-06-05 10:48:38 +0100323 cwd = os.getcwd()
Michael Bestas602fab22018-11-14 23:14:33 +0200324 print('You have not set CM_CROWDIN_BASE_PATH. Defaulting to %s' % cwd)
Michael Bestas118fcaf2015-06-04 23:02:20 +0300325 base_path = cwd
326 else:
327 base_path = os.path.join(os.path.realpath(base_path), default_branch)
328 if not os.path.isdir(base_path):
Michael Bestas602fab22018-11-14 23:14:33 +0200329 print('CM_CROWDIN_BASE_PATH + branch is not a real directory: %s'
330 % base_path)
Michael Bestas118fcaf2015-06-04 23:02:20 +0300331 sys.exit(1)
Anthony Kingb8607632015-05-01 22:06:37 +0300332
Michael Bestas99f5fce2015-06-04 22:07:51 +0300333 if not check_dependencies():
334 sys.exit(1)
Anthony Kingb8607632015-05-01 22:06:37 +0300335
Michael Bestas118fcaf2015-06-04 23:02:20 +0300336 xml_android = load_xml(x='%s/android/default.xml' % base_path)
Anthony Kingb8607632015-05-01 22:06:37 +0300337 if xml_android is None:
338 sys.exit(1)
339
Michael Bestas42e25e32016-03-12 20:18:39 +0200340 xml_extra = load_xml(x='%s/config/%s_extra_packages.xml'
Anthony Kingd0d56cf2015-06-05 10:48:38 +0100341 % (_DIR, default_branch))
Anthony Kingb8607632015-05-01 22:06:37 +0300342 if xml_extra is None:
343 sys.exit(1)
344
Michael Bestas19dc3352018-02-03 20:24:00 +0200345 xml_snippet = load_xml(x='%s/android/snippets/lineage.xml' % base_path)
346 if xml_snippet is None:
347 xml_snippet = load_xml(x='%s/android/snippets/cm.xml' % base_path)
348 if xml_snippet is None:
349 xml_snippet = load_xml(x='%s/android/snippets/hal_cm_all.xml' % base_path)
350 if xml_snippet is not None:
351 xml_files = (xml_android, xml_snippet, xml_extra)
Michael Bestas687679f2016-12-07 23:20:12 +0200352 else:
353 xml_files = (xml_android, xml_extra)
354
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300355 if args.config:
Michael Bestas03bc7052016-03-12 03:19:10 +0200356 files = ['%s/config/%s' % (_DIR, args.config)]
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300357 else:
Michael Bestas03bc7052016-03-12 03:19:10 +0200358 files = ['%s/config/%s.yaml' % (_DIR, default_branch),
359 '%s/config/%s_aosp.yaml' % (_DIR, default_branch)]
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300360 if not check_files(files):
Anthony Kingb8607632015-05-01 22:06:37 +0300361 sys.exit(1)
362
Michael Bestasfd5d1362015-12-18 20:34:32 +0200363 if args.download and args.username is None:
364 print('Argument -u/--username is required for translations download')
365 sys.exit(1)
366
367 if args.upload_sources:
368 upload_sources_crowdin(default_branch, args.config)
369 if args.upload_translations:
370 upload_translations_crowdin(default_branch, args.config)
371 if args.download:
Michael Bestas687679f2016-12-07 23:20:12 +0200372 download_crowdin(base_path, default_branch, xml_files,
Michael Bestasdb69b932016-03-12 21:08:27 +0200373 args.username, args.config, args.ticket)
Tom Powell44256852016-07-06 15:23:25 -0700374
375 if _COMMITS_CREATED:
376 print('\nDone!')
377 sys.exit(0)
Tom Powellf42586f2016-07-11 11:02:54 -0700378 else:
Tom Powell44256852016-07-06 15:23:25 -0700379 print('\nNothing to commit')
380 sys.exit(-1)
Anthony Kingb8607632015-05-01 22:06:37 +0300381
382if __name__ == '__main__':
383 main()