blob: 54c77a7f62535efed31fc31143c2c2021d8fc8ef [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):
Michael Bestas432919a2016-03-12 21:16:20 +020058 if 'stable/' in base_path:
59 branch = ''.join(('stable/', branch))
60
Anthony Kingb8607632015-05-01 22:06:37 +030061 print('Committing %s on branch %s' % (name, branch))
Marco Brohetcb5cdb42014-07-11 22:41:53 +020062
63 # Get path
Michael Bestas118fcaf2015-06-04 23:02:20 +030064 path = os.path.join(base_path, path)
Anthony Kingb8607632015-05-01 22:06:37 +030065 if not path.endswith('.git'):
66 path = os.path.join(path, '.git')
Marco Brohetcb5cdb42014-07-11 22:41:53 +020067
Marco Brohet6b6b4e52014-07-20 00:05:16 +020068 # Create repo object
Marco Brohetcb5cdb42014-07-11 22:41:53 +020069 repo = git.Repo(path)
Marco Brohet6b6b4e52014-07-20 00:05:16 +020070
71 # Remove previously deleted files from Git
Anthony Kingb8607632015-05-01 22:06:37 +030072 files = repo.git.ls_files(d=True).split('\n')
73 if files and files[0]:
74 repo.git.rm(files)
Marco Brohet6b6b4e52014-07-20 00:05:16 +020075
76 # Add all files to commit
Marco Brohetcb5cdb42014-07-11 22:41:53 +020077 repo.git.add('-A')
Marco Brohet6b6b4e52014-07-20 00:05:16 +020078
79 # Create commit; if it fails, probably empty so skipping
Michael Bestasdb69b932016-03-12 21:08:27 +020080 if ticket:
81 message = '''Automatic translation import
82
83Ticket: %s''' % ticket
84 else:
85 message = 'Automatic translation import'
86
Marco Brohetcb5cdb42014-07-11 22:41:53 +020087 try:
Michael Bestasdb69b932016-03-12 21:08:27 +020088 repo.git.commit(m=message)
Marco Brohetcb5cdb42014-07-11 22:41:53 +020089 except:
Anthony Kingb8607632015-05-01 22:06:37 +030090 print('Failed to create commit for %s, probably empty: skipping'
91 % name, file=sys.stderr)
Marco Brohetcb5cdb42014-07-11 22:41:53 +020092 return
Marco Brohet6b6b4e52014-07-20 00:05:16 +020093
94 # Push commit
Michael Bestasf96f67b2014-10-21 00:43:37 +030095 try:
Abhisek Devkotab78def42016-12-27 13:06:52 -080096 repo.git.push('ssh://%s@review.lineageos.org:29418/%s' % (username, name),
Anthony Kingb8607632015-05-01 22:06:37 +030097 'HEAD:refs/for/%s%%topic=translation' % branch)
98 print('Successfully pushed commit for %s' % name)
Michael Bestasf96f67b2014-10-21 00:43:37 +030099 except:
Anthony Kingb8607632015-05-01 22:06:37 +0300100 print('Failed to push commit for %s' % name, file=sys.stderr)
Marco Brohetcb5cdb42014-07-11 22:41:53 +0200101
Tom Powell44256852016-07-06 15:23:25 -0700102 _COMMITS_CREATED = True
103
Anthony Kingb8607632015-05-01 22:06:37 +0300104
105def check_run(cmd):
Michael Bestas97677e12015-02-08 13:11:59 +0200106 p = subprocess.Popen(cmd, stdout=sys.stdout, stderr=sys.stderr)
107 ret = p.wait()
108 if ret != 0:
Anthony Kingb8607632015-05-01 22:06:37 +0300109 print('Failed to run cmd: %s' % ' '.join(cmd), file=sys.stderr)
Michael Bestas97677e12015-02-08 13:11:59 +0200110 sys.exit(ret)
111
Marco Brohet6b6b4e52014-07-20 00:05:16 +0200112
Michael Bestas118fcaf2015-06-04 23:02:20 +0300113def find_xml(base_path):
114 for dp, dn, file_names in os.walk(base_path):
Anthony Kingb8607632015-05-01 22:06:37 +0300115 for f in file_names:
116 if os.path.splitext(f)[1] == '.xml':
117 yield os.path.join(dp, f)
Marco Brohet6b6b4e52014-07-20 00:05:16 +0200118
Anthony Kingb8607632015-05-01 22:06:37 +0300119# ############################################################################ #
Marco Brohet6b6b4e52014-07-20 00:05:16 +0200120
Michael Bestas6b6db122015-02-08 13:22:22 +0200121
Anthony Kingb8607632015-05-01 22:06:37 +0300122def parse_args():
123 parser = argparse.ArgumentParser(
Abhisek Devkotab78def42016-12-27 13:06:52 -0800124 description="Synchronising LineageOS' translations with Crowdin")
Michael Bestasfd5d1362015-12-18 20:34:32 +0200125 parser.add_argument('-u', '--username', help='Gerrit username')
Abhisek Devkotab78def42016-12-27 13:06:52 -0800126 parser.add_argument('-b', '--branch', help='LineageOS branch',
Anthony Kingb8607632015-05-01 22:06:37 +0300127 required=True)
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300128 parser.add_argument('-c', '--config', help='Custom yaml config')
Michael Bestasdb69b932016-03-12 21:08:27 +0200129 parser.add_argument('-t', '--ticket', help='JIRA ticket')
Michael Bestasfd5d1362015-12-18 20:34:32 +0200130 parser.add_argument('--upload-sources', action='store_true',
131 help='Upload sources to Crowdin')
132 parser.add_argument('--upload-translations', action='store_true',
133 help='Upload translations to Crowdin')
134 parser.add_argument('--download', action='store_true',
135 help='Download translations from Crowdin')
Anthony Kingb8607632015-05-01 22:06:37 +0300136 return parser.parse_args()
Michael Bestas6b6db122015-02-08 13:22:22 +0200137
Anthony Kingb8607632015-05-01 22:06:37 +0300138# ################################# PREPARE ################################## #
Marco Brohet6b6b4e52014-07-20 00:05:16 +0200139
Anthony Kingb8607632015-05-01 22:06:37 +0300140
141def check_dependencies():
Anthony Kingb8607632015-05-01 22:06:37 +0300142 # Check for Ruby version of crowdin-cli
143 cmd = ['gem', 'list', 'crowdin-cli', '-i']
144 if run_subprocess(cmd, silent=True)[1] != 0:
145 print('You have not installed crowdin-cli.', file=sys.stderr)
146 return False
Anthony Kingb8607632015-05-01 22:06:37 +0300147 return True
Marco Brohetcb5cdb42014-07-11 22:41:53 +0200148
Marco Brohetcb5cdb42014-07-11 22:41:53 +0200149
Michael Bestas118fcaf2015-06-04 23:02:20 +0300150def load_xml(x):
Anthony Kingb8607632015-05-01 22:06:37 +0300151 try:
152 return minidom.parse(x)
153 except IOError:
154 print('You have no %s.' % x, file=sys.stderr)
155 return None
156 except Exception:
157 # TODO: minidom should not be used.
158 print('Malformed %s.' % x, file=sys.stderr)
159 return None
Marco Brohet6b6b4e52014-07-20 00:05:16 +0200160
Michael Bestas4b26c4e2014-10-23 23:21:59 +0300161
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300162def check_files(files):
Anthony Kingb8607632015-05-01 22:06:37 +0300163 for f in files:
164 if not os.path.isfile(f):
165 print('You have no %s.' % f, file=sys.stderr)
166 return False
Anthony Kingb8607632015-05-01 22:06:37 +0300167 return True
Michael Bestas4b26c4e2014-10-23 23:21:59 +0300168
Anthony Kingb8607632015-05-01 22:06:37 +0300169# ################################### MAIN ################################### #
Michael Bestas4b26c4e2014-10-23 23:21:59 +0300170
Michael Bestas4b26c4e2014-10-23 23:21:59 +0300171
Michael Bestasfd5d1362015-12-18 20:34:32 +0200172def upload_sources_crowdin(branch, config):
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300173 if config:
Michael Bestasfd5d1362015-12-18 20:34:32 +0200174 print('\nUploading sources to Crowdin (custom config)')
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300175 check_run(['crowdin-cli',
Michael Bestas03bc7052016-03-12 03:19:10 +0200176 '--config=%s/config/%s' % (_DIR, config),
Michael Bestas44fbb352015-12-17 02:01:42 +0200177 'upload', 'sources', '--branch=%s' % branch])
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300178 else:
Michael Bestasfd5d1362015-12-18 20:34:32 +0200179 print('\nUploading sources to Crowdin (AOSP supported languages)')
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300180 check_run(['crowdin-cli',
Michael Bestas03bc7052016-03-12 03:19:10 +0200181 '--config=%s/config/%s.yaml' % (_DIR, branch),
Michael Bestas44fbb352015-12-17 02:01:42 +0200182 'upload', 'sources', '--branch=%s' % branch])
Anthony King69a95382015-02-08 18:44:10 +0000183
Michael Bestasfd5d1362015-12-18 20:34:32 +0200184 print('\nUploading sources to Crowdin (non-AOSP supported languages)')
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300185 check_run(['crowdin-cli',
Michael Bestas03bc7052016-03-12 03:19:10 +0200186 '--config=%s/config/%s_aosp.yaml' % (_DIR, branch),
Michael Bestas44fbb352015-12-17 02:01:42 +0200187 'upload', 'sources', '--branch=%s' % branch])
Anthony Kingb8607632015-05-01 22:06:37 +0300188
189
Michael Bestasfd5d1362015-12-18 20:34:32 +0200190def upload_translations_crowdin(branch, config):
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300191 if config:
Michael Bestasfd5d1362015-12-18 20:34:32 +0200192 print('\nUploading translations to Crowdin (custom config)')
193 check_run(['crowdin-cli',
Michael Bestas03bc7052016-03-12 03:19:10 +0200194 '--config=%s/config/%s' % (_DIR, config),
Michael Bestasfd5d1362015-12-18 20:34:32 +0200195 'upload', 'translations', '--branch=%s' % branch,
196 '--no-import-duplicates', '--import-eq-suggestions',
197 '--auto-approve-imported'])
198 else:
199 print('\nUploading translations to Crowdin '
200 '(AOSP supported languages)')
201 check_run(['crowdin-cli',
Michael Bestas03bc7052016-03-12 03:19:10 +0200202 '--config=%s/config/%s.yaml' % (_DIR, branch),
Michael Bestasfd5d1362015-12-18 20:34:32 +0200203 'upload', 'translations', '--branch=%s' % branch,
204 '--no-import-duplicates', '--import-eq-suggestions',
205 '--auto-approve-imported'])
206
207 print('\nUploading translations to Crowdin '
208 '(non-AOSP supported languages)')
209 check_run(['crowdin-cli',
Michael Bestas03bc7052016-03-12 03:19:10 +0200210 '--config=%s/config/%s_aosp.yaml' % (_DIR, branch),
Michael Bestasfd5d1362015-12-18 20:34:32 +0200211 'upload', 'translations', '--branch=%s' % branch,
212 '--no-import-duplicates', '--import-eq-suggestions',
213 '--auto-approve-imported'])
214
215
Michael Bestasdb69b932016-03-12 21:08:27 +0200216def download_crowdin(base_path, branch, xml, username, config, ticket):
Michael Bestasfd5d1362015-12-18 20:34:32 +0200217 if config:
218 print('\nDownloading translations from Crowdin (custom config)')
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300219 check_run(['crowdin-cli',
Michael Bestas03bc7052016-03-12 03:19:10 +0200220 '--config=%s/config/%s' % (_DIR, config),
Michael Bestas44fbb352015-12-17 02:01:42 +0200221 'download', '--branch=%s' % branch])
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300222 else:
Michael Bestasfd5d1362015-12-18 20:34:32 +0200223 print('\nDownloading translations from Crowdin '
224 '(AOSP supported languages)')
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300225 check_run(['crowdin-cli',
Michael Bestas03bc7052016-03-12 03:19:10 +0200226 '--config=%s/config/%s.yaml' % (_DIR, branch),
Michael Bestas44fbb352015-12-17 02:01:42 +0200227 'download', '--branch=%s' % branch])
Michael Bestas50579d22014-08-09 17:49:14 +0300228
Michael Bestasfd5d1362015-12-18 20:34:32 +0200229 print('\nDownloading translations from Crowdin '
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300230 '(non-AOSP supported languages)')
231 check_run(['crowdin-cli',
Michael Bestas03bc7052016-03-12 03:19:10 +0200232 '--config=%s/config/%s_aosp.yaml' % (_DIR, branch),
Michael Bestas44fbb352015-12-17 02:01:42 +0200233 'download', '--branch=%s' % branch])
Marco Brohetcb5cdb42014-07-11 22:41:53 +0200234
Michael Bestas99f5fce2015-06-04 22:07:51 +0300235 print('\nRemoving useless empty translation files')
Anthony Kingb8607632015-05-01 22:06:37 +0300236 empty_contents = {
237 '<resources/>',
238 '<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"/>',
239 ('<resources xmlns:android='
240 '"http://schemas.android.com/apk/res/android"/>'),
241 ('<resources xmlns:android="http://schemas.android.com/apk/res/android"'
242 ' xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"/>'),
243 ('<resources xmlns:tools="http://schemas.android.com/tools"'
244 ' xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"/>')
245 }
246 xf = None
Michael Bestas118fcaf2015-06-04 23:02:20 +0300247 for xml_file in find_xml(base_path):
Anthony Kingb8607632015-05-01 22:06:37 +0300248 xf = open(xml_file).read()
Michael Bestas919053f2014-10-20 23:30:54 +0300249 for line in empty_contents:
Anthony Kingb8607632015-05-01 22:06:37 +0300250 if line in xf:
Michael Bestas919053f2014-10-20 23:30:54 +0300251 print('Removing ' + xml_file)
252 os.remove(xml_file)
253 break
Anthony Kingb8607632015-05-01 22:06:37 +0300254 del xf
Marco Brohetcb5cdb42014-07-11 22:41:53 +0200255
Michael Bestas99f5fce2015-06-04 22:07:51 +0300256 print('\nCreating a list of pushable translations')
Michael Bestas919053f2014-10-20 23:30:54 +0300257 # Get all files that Crowdin pushed
Anthony Kingb8607632015-05-01 22:06:37 +0300258 paths = []
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300259 if config:
Michael Bestas03bc7052016-03-12 03:19:10 +0200260 files = ['%s/config/%s' % (_DIR, config)]
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300261 else:
Michael Bestas03bc7052016-03-12 03:19:10 +0200262 files = ['%s/config/%s.yaml' % (_DIR, branch),
263 '%s/config/%s_aosp.yaml' % (_DIR, branch)]
Michael Bestas6c327e62015-05-02 01:58:01 +0300264 for c in files:
Michael Bestas44fbb352015-12-17 02:01:42 +0200265 cmd = ['crowdin-cli', '--config=%s' % c, 'list', 'project',
266 '--branch=%s' % branch]
Anthony Kingb8607632015-05-01 22:06:37 +0300267 comm, ret = run_subprocess(cmd)
268 if ret != 0:
269 sys.exit(ret)
270 for p in str(comm[0]).split("\n"):
271 paths.append(p.replace('/%s' % branch, ''))
Michael Bestas50579d22014-08-09 17:49:14 +0300272
Michael Bestas99f5fce2015-06-04 22:07:51 +0300273 print('\nUploading translations to Gerrit')
Anthony Kingb8607632015-05-01 22:06:37 +0300274 items = [x for sub in xml for x in sub.getElementsByTagName('project')]
Michael Bestas919053f2014-10-20 23:30:54 +0300275 all_projects = []
276
Anthony Kingb8607632015-05-01 22:06:37 +0300277 for path in paths:
278 path = path.strip()
Michael Bestas919053f2014-10-20 23:30:54 +0300279 if not path:
280 continue
281
Anthony Kingb8607632015-05-01 22:06:37 +0300282 if "/res" not in path:
283 print('WARNING: Cannot determine project root dir of '
284 '[%s], skipping.' % path)
Anthony King69a95382015-02-08 18:44:10 +0000285 continue
Anthony Kingb8607632015-05-01 22:06:37 +0300286 result = path.split('/res')[0].strip('/')
287 if result == path.strip('/'):
288 print('WARNING: Cannot determine project root dir of '
289 '[%s], skipping.' % path)
290 continue
Marco Brohet6b6b4e52014-07-20 00:05:16 +0200291
Michael Bestasc899b8c2015-03-03 00:53:19 +0200292 if result in all_projects:
Michael Bestasc899b8c2015-03-03 00:53:19 +0200293 continue
Michael Bestas50579d22014-08-09 17:49:14 +0300294
Anthony Kingb8607632015-05-01 22:06:37 +0300295 # When a project has multiple translatable files, Crowdin will
296 # give duplicates.
297 # We don't want that (useless empty commits), so we save each
298 # project in all_projects and check if it's already in there.
Michael Bestasc899b8c2015-03-03 00:53:19 +0200299 all_projects.append(result)
Anthony King69a95382015-02-08 18:44:10 +0000300
Michael Bestas42e25e32016-03-12 20:18:39 +0200301 # Search android/default.xml or config/%(branch)_extra_packages.xml
Anthony Kingb8607632015-05-01 22:06:37 +0300302 # for the project's name
303 for project in items:
304 path = project.attributes['path'].value
305 if not (result + '/').startswith(path +'/'):
Michael Bestasc899b8c2015-03-03 00:53:19 +0200306 continue
Anthony Kingb8607632015-05-01 22:06:37 +0300307 if result != path:
308 if path in all_projects:
309 break
310 result = path
311 all_projects.append(result)
Anthony King69a95382015-02-08 18:44:10 +0000312
Anthony Kingb8607632015-05-01 22:06:37 +0300313 br = project.getAttribute('revision') or branch
Anthony King69a95382015-02-08 18:44:10 +0000314
Michael Bestas118fcaf2015-06-04 23:02:20 +0300315 push_as_commit(base_path, result,
Michael Bestasdb69b932016-03-12 21:08:27 +0200316 project.getAttribute('name'), br, username, ticket)
Anthony Kingb8607632015-05-01 22:06:37 +0300317 break
Anthony King69a95382015-02-08 18:44:10 +0000318
Anthony King69a95382015-02-08 18:44:10 +0000319
Anthony Kingb8607632015-05-01 22:06:37 +0300320def main():
Anthony Kingb8607632015-05-01 22:06:37 +0300321 args = parse_args()
322 default_branch = args.branch
Michael Bestas118fcaf2015-06-04 23:02:20 +0300323
Michael Bestas432919a2016-03-12 21:16:20 +0200324 if 'stable/' in default_branch:
325 base_path_env = 'CM_CROWDIN_STABLE_BASE_PATH'
326 base_path = os.getenv(base_path_env)
327 default_branch = default_branch.replace('stable/', '')
328 else:
329 base_path_env = 'CM_CROWDIN_BASE_PATH'
330 base_path = os.getenv(base_path_env)
Michael Bestas118fcaf2015-06-04 23:02:20 +0300331 if base_path is None:
Anthony Kingd0d56cf2015-06-05 10:48:38 +0100332 cwd = os.getcwd()
Michael Bestas432919a2016-03-12 21:16:20 +0200333 print('You have not set %s. Defaulting to %s' % (base_path_env, cwd))
Michael Bestas118fcaf2015-06-04 23:02:20 +0300334 base_path = cwd
335 else:
336 base_path = os.path.join(os.path.realpath(base_path), default_branch)
337 if not os.path.isdir(base_path):
Michael Bestas432919a2016-03-12 21:16:20 +0200338 print('%s + branch is not a real directory: %s'
339 % (base_path_env, base_path))
Michael Bestas118fcaf2015-06-04 23:02:20 +0300340 sys.exit(1)
Anthony Kingb8607632015-05-01 22:06:37 +0300341
Michael Bestas99f5fce2015-06-04 22:07:51 +0300342 if not check_dependencies():
343 sys.exit(1)
Anthony Kingb8607632015-05-01 22:06:37 +0300344
Michael Bestas118fcaf2015-06-04 23:02:20 +0300345 xml_android = load_xml(x='%s/android/default.xml' % base_path)
Anthony Kingb8607632015-05-01 22:06:37 +0300346 if xml_android is None:
347 sys.exit(1)
348
Michael Bestas42e25e32016-03-12 20:18:39 +0200349 xml_extra = load_xml(x='%s/config/%s_extra_packages.xml'
Anthony Kingd0d56cf2015-06-05 10:48:38 +0100350 % (_DIR, default_branch))
Anthony Kingb8607632015-05-01 22:06:37 +0300351 if xml_extra is None:
352 sys.exit(1)
353
Michael Bestas687679f2016-12-07 23:20:12 +0200354 xml_cm = load_xml(x='%s/android/snippets/cm.xml' % base_path)
355 if xml_cm is None:
356 xml_cm = load_xml(x='%s/android/snippets/hal_cm_all.xml' % base_path)
357 if xml_cm is not None:
358 xml_files = (xml_android, xml_cm, xml_extra)
359 else:
360 xml_files = (xml_android, xml_extra)
361
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300362 if args.config:
Michael Bestas03bc7052016-03-12 03:19:10 +0200363 files = ['%s/config/%s' % (_DIR, args.config)]
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300364 else:
Michael Bestas03bc7052016-03-12 03:19:10 +0200365 files = ['%s/config/%s.yaml' % (_DIR, default_branch),
366 '%s/config/%s_aosp.yaml' % (_DIR, default_branch)]
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300367 if not check_files(files):
Anthony Kingb8607632015-05-01 22:06:37 +0300368 sys.exit(1)
369
Michael Bestasfd5d1362015-12-18 20:34:32 +0200370 if args.download and args.username is None:
371 print('Argument -u/--username is required for translations download')
372 sys.exit(1)
373
374 if args.upload_sources:
375 upload_sources_crowdin(default_branch, args.config)
376 if args.upload_translations:
377 upload_translations_crowdin(default_branch, args.config)
378 if args.download:
Michael Bestas687679f2016-12-07 23:20:12 +0200379 download_crowdin(base_path, default_branch, xml_files,
Michael Bestasdb69b932016-03-12 21:08:27 +0200380 args.username, args.config, args.ticket)
Tom Powell44256852016-07-06 15:23:25 -0700381
382 if _COMMITS_CREATED:
383 print('\nDone!')
384 sys.exit(0)
Tom Powellf42586f2016-07-11 11:02:54 -0700385 else:
Tom Powell44256852016-07-06 15:23:25 -0700386 print('\nNothing to commit')
387 sys.exit(-1)
Anthony Kingb8607632015-05-01 22:06:37 +0300388
389if __name__ == '__main__':
390 main()