blob: 52f037115219198225a5a5799f14ff8509f1b15a [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
6# directly to CyanogenMod's Gerrit.
7#
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__))
37
Anthony Kingb8607632015-05-01 22:06:37 +030038# ################################ FUNCTIONS ################################# #
39
40
41def run_subprocess(cmd, silent=False):
42 p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
43 universal_newlines=True)
44 comm = p.communicate()
45 exit_code = p.returncode
46 if exit_code != 0 and not silent:
47 print("There was an error running the subprocess.\n"
48 "cmd: %s\n"
49 "exit code: %d\n"
50 "stdout: %s\n"
51 "stderr: %s" % (cmd, exit_code, comm[0], comm[1]),
52 file=sys.stderr)
53 return comm, exit_code
54
Marco Brohet6b6b4e52014-07-20 00:05:16 +020055
Michael Bestasdb69b932016-03-12 21:08:27 +020056def push_as_commit(base_path, path, name, branch, username, ticket):
Michael Bestas432919a2016-03-12 21:16:20 +020057 if 'stable/' in base_path:
58 branch = ''.join(('stable/', branch))
59
Anthony Kingb8607632015-05-01 22:06:37 +030060 print('Committing %s on branch %s' % (name, branch))
Marco Brohetcb5cdb42014-07-11 22:41:53 +020061
62 # Get path
Michael Bestas118fcaf2015-06-04 23:02:20 +030063 path = os.path.join(base_path, path)
Anthony Kingb8607632015-05-01 22:06:37 +030064 if not path.endswith('.git'):
65 path = os.path.join(path, '.git')
Marco Brohetcb5cdb42014-07-11 22:41:53 +020066
Marco Brohet6b6b4e52014-07-20 00:05:16 +020067 # Create repo object
Marco Brohetcb5cdb42014-07-11 22:41:53 +020068 repo = git.Repo(path)
Marco Brohet6b6b4e52014-07-20 00:05:16 +020069
70 # Remove previously deleted files from Git
Anthony Kingb8607632015-05-01 22:06:37 +030071 files = repo.git.ls_files(d=True).split('\n')
72 if files and files[0]:
73 repo.git.rm(files)
Marco Brohet6b6b4e52014-07-20 00:05:16 +020074
75 # Add all files to commit
Marco Brohetcb5cdb42014-07-11 22:41:53 +020076 repo.git.add('-A')
Marco Brohet6b6b4e52014-07-20 00:05:16 +020077
78 # Create commit; if it fails, probably empty so skipping
Michael Bestasdb69b932016-03-12 21:08:27 +020079 if ticket:
80 message = '''Automatic translation import
81
82Ticket: %s''' % ticket
83 else:
84 message = 'Automatic translation import'
85
Marco Brohetcb5cdb42014-07-11 22:41:53 +020086 try:
Michael Bestasdb69b932016-03-12 21:08:27 +020087 repo.git.commit(m=message)
Marco Brohetcb5cdb42014-07-11 22:41:53 +020088 except:
Anthony Kingb8607632015-05-01 22:06:37 +030089 print('Failed to create commit for %s, probably empty: skipping'
90 % name, file=sys.stderr)
Marco Brohetcb5cdb42014-07-11 22:41:53 +020091 return
Marco Brohet6b6b4e52014-07-20 00:05:16 +020092
93 # Push commit
Michael Bestasf96f67b2014-10-21 00:43:37 +030094 try:
Anthony Kingb8607632015-05-01 22:06:37 +030095 repo.git.push('ssh://%s@review.cyanogenmod.org:29418/%s' % (username, name),
96 'HEAD:refs/for/%s%%topic=translation' % branch)
97 print('Successfully pushed commit for %s' % name)
Michael Bestasf96f67b2014-10-21 00:43:37 +030098 except:
Anthony Kingb8607632015-05-01 22:06:37 +030099 print('Failed to push commit for %s' % name, file=sys.stderr)
Marco Brohetcb5cdb42014-07-11 22:41:53 +0200100
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(
121 description="Synchronising CyanogenMod's translations with Crowdin")
Michael Bestasfd5d1362015-12-18 20:34:32 +0200122 parser.add_argument('-u', '--username', help='Gerrit username')
Anthony Kingb8607632015-05-01 22:06:37 +0300123 parser.add_argument('-b', '--branch', help='CyanogenMod branch',
124 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 Bestas432919a2016-03-12 21:16:20 +0200321 if 'stable/' in default_branch:
322 base_path_env = 'CM_CROWDIN_STABLE_BASE_PATH'
323 base_path = os.getenv(base_path_env)
324 default_branch = default_branch.replace('stable/', '')
325 else:
326 base_path_env = 'CM_CROWDIN_BASE_PATH'
327 base_path = os.getenv(base_path_env)
Michael Bestas118fcaf2015-06-04 23:02:20 +0300328 if base_path is None:
Anthony Kingd0d56cf2015-06-05 10:48:38 +0100329 cwd = os.getcwd()
Michael Bestas432919a2016-03-12 21:16:20 +0200330 print('You have not set %s. Defaulting to %s' % (base_path_env, cwd))
Michael Bestas118fcaf2015-06-04 23:02:20 +0300331 base_path = cwd
332 else:
333 base_path = os.path.join(os.path.realpath(base_path), default_branch)
334 if not os.path.isdir(base_path):
Michael Bestas432919a2016-03-12 21:16:20 +0200335 print('%s + branch is not a real directory: %s'
336 % (base_path_env, base_path))
Michael Bestas118fcaf2015-06-04 23:02:20 +0300337 sys.exit(1)
Anthony Kingb8607632015-05-01 22:06:37 +0300338
Michael Bestas99f5fce2015-06-04 22:07:51 +0300339 if not check_dependencies():
340 sys.exit(1)
Anthony Kingb8607632015-05-01 22:06:37 +0300341
Michael Bestas118fcaf2015-06-04 23:02:20 +0300342 xml_android = load_xml(x='%s/android/default.xml' % base_path)
Anthony Kingb8607632015-05-01 22:06:37 +0300343 if xml_android is None:
344 sys.exit(1)
345
Michael Bestas42e25e32016-03-12 20:18:39 +0200346 xml_extra = load_xml(x='%s/config/%s_extra_packages.xml'
Anthony Kingd0d56cf2015-06-05 10:48:38 +0100347 % (_DIR, default_branch))
Anthony Kingb8607632015-05-01 22:06:37 +0300348 if xml_extra is None:
349 sys.exit(1)
350
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300351 if args.config:
Michael Bestas03bc7052016-03-12 03:19:10 +0200352 files = ['%s/config/%s' % (_DIR, args.config)]
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300353 else:
Michael Bestas03bc7052016-03-12 03:19:10 +0200354 files = ['%s/config/%s.yaml' % (_DIR, default_branch),
355 '%s/config/%s_aosp.yaml' % (_DIR, default_branch)]
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300356 if not check_files(files):
Anthony Kingb8607632015-05-01 22:06:37 +0300357 sys.exit(1)
358
Michael Bestasfd5d1362015-12-18 20:34:32 +0200359 if args.download and args.username is None:
360 print('Argument -u/--username is required for translations download')
361 sys.exit(1)
362
363 if args.upload_sources:
364 upload_sources_crowdin(default_branch, args.config)
365 if args.upload_translations:
366 upload_translations_crowdin(default_branch, args.config)
367 if args.download:
368 download_crowdin(base_path, default_branch, (xml_android, xml_extra),
Michael Bestasdb69b932016-03-12 21:08:27 +0200369 args.username, args.config, args.ticket)
Anthony Kingb8607632015-05-01 22:06:37 +0300370 print('\nDone!')
371
372if __name__ == '__main__':
373 main()