blob: 369ec0ffdb69e58a80a260238256f0eb0a76ae0b [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 Bestas80b22ef2018-11-14 23:12:33 +020057def push_as_commit(base_path, path, name, branch, username):
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
Marco Brohetcb5cdb42014-07-11 22:41:53 +020077 try:
Michael Bestas80b22ef2018-11-14 23:12:33 +020078 repo.git.commit(m='Automatic translation import')
Marco Brohetcb5cdb42014-07-11 22:41:53 +020079 except:
Anthony Kingb8607632015-05-01 22:06:37 +030080 print('Failed to create commit for %s, probably empty: skipping'
81 % name, file=sys.stderr)
Marco Brohetcb5cdb42014-07-11 22:41:53 +020082 return
Marco Brohet6b6b4e52014-07-20 00:05:16 +020083
84 # Push commit
Michael Bestasf96f67b2014-10-21 00:43:37 +030085 try:
Abhisek Devkotab78def42016-12-27 13:06:52 -080086 repo.git.push('ssh://%s@review.lineageos.org:29418/%s' % (username, name),
Anthony Kingb8607632015-05-01 22:06:37 +030087 'HEAD:refs/for/%s%%topic=translation' % branch)
88 print('Successfully pushed commit for %s' % name)
Michael Bestasf96f67b2014-10-21 00:43:37 +030089 except:
Anthony Kingb8607632015-05-01 22:06:37 +030090 print('Failed to push commit for %s' % name, file=sys.stderr)
Marco Brohetcb5cdb42014-07-11 22:41:53 +020091
Tom Powell44256852016-07-06 15:23:25 -070092 _COMMITS_CREATED = True
93
Anthony Kingb8607632015-05-01 22:06:37 +030094
95def check_run(cmd):
Michael Bestas97677e12015-02-08 13:11:59 +020096 p = subprocess.Popen(cmd, stdout=sys.stdout, stderr=sys.stderr)
97 ret = p.wait()
98 if ret != 0:
Anthony Kingb8607632015-05-01 22:06:37 +030099 print('Failed to run cmd: %s' % ' '.join(cmd), file=sys.stderr)
Michael Bestas97677e12015-02-08 13:11:59 +0200100 sys.exit(ret)
101
Marco Brohet6b6b4e52014-07-20 00:05:16 +0200102
Michael Bestas118fcaf2015-06-04 23:02:20 +0300103def find_xml(base_path):
104 for dp, dn, file_names in os.walk(base_path):
Anthony Kingb8607632015-05-01 22:06:37 +0300105 for f in file_names:
106 if os.path.splitext(f)[1] == '.xml':
107 yield os.path.join(dp, f)
Marco Brohet6b6b4e52014-07-20 00:05:16 +0200108
Anthony Kingb8607632015-05-01 22:06:37 +0300109# ############################################################################ #
Marco Brohet6b6b4e52014-07-20 00:05:16 +0200110
Michael Bestas6b6db122015-02-08 13:22:22 +0200111
Anthony Kingb8607632015-05-01 22:06:37 +0300112def parse_args():
113 parser = argparse.ArgumentParser(
Abhisek Devkotab78def42016-12-27 13:06:52 -0800114 description="Synchronising LineageOS' translations with Crowdin")
Michael Bestasfd5d1362015-12-18 20:34:32 +0200115 parser.add_argument('-u', '--username', help='Gerrit username')
Abhisek Devkotab78def42016-12-27 13:06:52 -0800116 parser.add_argument('-b', '--branch', help='LineageOS branch',
Anthony Kingb8607632015-05-01 22:06:37 +0300117 required=True)
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300118 parser.add_argument('-c', '--config', help='Custom yaml config')
Michael Bestasfd5d1362015-12-18 20:34:32 +0200119 parser.add_argument('--upload-sources', action='store_true',
120 help='Upload sources to Crowdin')
121 parser.add_argument('--upload-translations', action='store_true',
122 help='Upload translations to Crowdin')
123 parser.add_argument('--download', action='store_true',
124 help='Download translations from Crowdin')
Anthony Kingb8607632015-05-01 22:06:37 +0300125 return parser.parse_args()
Michael Bestas6b6db122015-02-08 13:22:22 +0200126
Anthony Kingb8607632015-05-01 22:06:37 +0300127# ################################# PREPARE ################################## #
Marco Brohet6b6b4e52014-07-20 00:05:16 +0200128
Anthony Kingb8607632015-05-01 22:06:37 +0300129
130def check_dependencies():
Anthony Kingb8607632015-05-01 22:06:37 +0300131 # Check for Ruby version of crowdin-cli
132 cmd = ['gem', 'list', 'crowdin-cli', '-i']
133 if run_subprocess(cmd, silent=True)[1] != 0:
134 print('You have not installed crowdin-cli.', file=sys.stderr)
135 return False
Anthony Kingb8607632015-05-01 22:06:37 +0300136 return True
Marco Brohetcb5cdb42014-07-11 22:41:53 +0200137
Marco Brohetcb5cdb42014-07-11 22:41:53 +0200138
Michael Bestas118fcaf2015-06-04 23:02:20 +0300139def load_xml(x):
Anthony Kingb8607632015-05-01 22:06:37 +0300140 try:
141 return minidom.parse(x)
142 except IOError:
143 print('You have no %s.' % x, file=sys.stderr)
144 return None
145 except Exception:
146 # TODO: minidom should not be used.
147 print('Malformed %s.' % x, file=sys.stderr)
148 return None
Marco Brohet6b6b4e52014-07-20 00:05:16 +0200149
Michael Bestas4b26c4e2014-10-23 23:21:59 +0300150
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300151def check_files(files):
Anthony Kingb8607632015-05-01 22:06:37 +0300152 for f in files:
153 if not os.path.isfile(f):
154 print('You have no %s.' % f, file=sys.stderr)
155 return False
Anthony Kingb8607632015-05-01 22:06:37 +0300156 return True
Michael Bestas4b26c4e2014-10-23 23:21:59 +0300157
Anthony Kingb8607632015-05-01 22:06:37 +0300158# ################################### MAIN ################################### #
Michael Bestas4b26c4e2014-10-23 23:21:59 +0300159
Michael Bestas4b26c4e2014-10-23 23:21:59 +0300160
Michael Bestasfd5d1362015-12-18 20:34:32 +0200161def upload_sources_crowdin(branch, config):
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300162 if config:
Michael Bestasfd5d1362015-12-18 20:34:32 +0200163 print('\nUploading sources to Crowdin (custom config)')
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300164 check_run(['crowdin-cli',
Michael Bestas03bc7052016-03-12 03:19:10 +0200165 '--config=%s/config/%s' % (_DIR, config),
Michael Bestas44fbb352015-12-17 02:01:42 +0200166 'upload', 'sources', '--branch=%s' % branch])
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300167 else:
Michael Bestasfd5d1362015-12-18 20:34:32 +0200168 print('\nUploading sources to Crowdin (AOSP supported languages)')
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300169 check_run(['crowdin-cli',
Michael Bestas03bc7052016-03-12 03:19:10 +0200170 '--config=%s/config/%s.yaml' % (_DIR, branch),
Michael Bestas44fbb352015-12-17 02:01:42 +0200171 'upload', 'sources', '--branch=%s' % branch])
Anthony King69a95382015-02-08 18:44:10 +0000172
Michael Bestasfd5d1362015-12-18 20:34:32 +0200173 print('\nUploading sources to Crowdin (non-AOSP supported languages)')
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300174 check_run(['crowdin-cli',
Michael Bestas03bc7052016-03-12 03:19:10 +0200175 '--config=%s/config/%s_aosp.yaml' % (_DIR, branch),
Michael Bestas44fbb352015-12-17 02:01:42 +0200176 'upload', 'sources', '--branch=%s' % branch])
Anthony Kingb8607632015-05-01 22:06:37 +0300177
178
Michael Bestasfd5d1362015-12-18 20:34:32 +0200179def upload_translations_crowdin(branch, config):
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300180 if config:
Michael Bestasfd5d1362015-12-18 20:34:32 +0200181 print('\nUploading translations to Crowdin (custom config)')
182 check_run(['crowdin-cli',
Michael Bestas03bc7052016-03-12 03:19:10 +0200183 '--config=%s/config/%s' % (_DIR, config),
Michael Bestasfd5d1362015-12-18 20:34:32 +0200184 'upload', 'translations', '--branch=%s' % branch,
185 '--no-import-duplicates', '--import-eq-suggestions',
186 '--auto-approve-imported'])
187 else:
188 print('\nUploading translations to Crowdin '
189 '(AOSP supported languages)')
190 check_run(['crowdin-cli',
Michael Bestas03bc7052016-03-12 03:19:10 +0200191 '--config=%s/config/%s.yaml' % (_DIR, branch),
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
196 print('\nUploading translations to Crowdin '
197 '(non-AOSP supported languages)')
198 check_run(['crowdin-cli',
Michael Bestas03bc7052016-03-12 03:19:10 +0200199 '--config=%s/config/%s_aosp.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
Michael Bestas80b22ef2018-11-14 23:12:33 +0200205def download_crowdin(base_path, branch, xml, username, config):
Michael Bestasfd5d1362015-12-18 20:34:32 +0200206 if config:
207 print('\nDownloading translations from Crowdin (custom config)')
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300208 check_run(['crowdin-cli',
Michael Bestas03bc7052016-03-12 03:19:10 +0200209 '--config=%s/config/%s' % (_DIR, config),
Michael Bestas44fbb352015-12-17 02:01:42 +0200210 'download', '--branch=%s' % branch])
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300211 else:
Michael Bestasfd5d1362015-12-18 20:34:32 +0200212 print('\nDownloading translations from Crowdin '
213 '(AOSP supported languages)')
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300214 check_run(['crowdin-cli',
Michael Bestas03bc7052016-03-12 03:19:10 +0200215 '--config=%s/config/%s.yaml' % (_DIR, branch),
Michael Bestas44fbb352015-12-17 02:01:42 +0200216 'download', '--branch=%s' % branch])
Michael Bestas50579d22014-08-09 17:49:14 +0300217
Michael Bestasfd5d1362015-12-18 20:34:32 +0200218 print('\nDownloading translations from Crowdin '
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300219 '(non-AOSP supported languages)')
220 check_run(['crowdin-cli',
Michael Bestas03bc7052016-03-12 03:19:10 +0200221 '--config=%s/config/%s_aosp.yaml' % (_DIR, branch),
Michael Bestas44fbb352015-12-17 02:01:42 +0200222 'download', '--branch=%s' % branch])
Marco Brohetcb5cdb42014-07-11 22:41:53 +0200223
Michael Bestas99f5fce2015-06-04 22:07:51 +0300224 print('\nRemoving useless empty translation files')
Anthony Kingb8607632015-05-01 22:06:37 +0300225 empty_contents = {
226 '<resources/>',
227 '<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"/>',
228 ('<resources xmlns:android='
229 '"http://schemas.android.com/apk/res/android"/>'),
230 ('<resources xmlns:android="http://schemas.android.com/apk/res/android"'
231 ' xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"/>'),
232 ('<resources xmlns:tools="http://schemas.android.com/tools"'
233 ' xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"/>')
234 }
235 xf = None
Michael Bestas118fcaf2015-06-04 23:02:20 +0300236 for xml_file in find_xml(base_path):
Anthony Kingb8607632015-05-01 22:06:37 +0300237 xf = open(xml_file).read()
Michael Bestas919053f2014-10-20 23:30:54 +0300238 for line in empty_contents:
Anthony Kingb8607632015-05-01 22:06:37 +0300239 if line in xf:
Michael Bestas919053f2014-10-20 23:30:54 +0300240 print('Removing ' + xml_file)
241 os.remove(xml_file)
242 break
Anthony Kingb8607632015-05-01 22:06:37 +0300243 del xf
Marco Brohetcb5cdb42014-07-11 22:41:53 +0200244
Michael Bestas99f5fce2015-06-04 22:07:51 +0300245 print('\nCreating a list of pushable translations')
Michael Bestas919053f2014-10-20 23:30:54 +0300246 # Get all files that Crowdin pushed
Anthony Kingb8607632015-05-01 22:06:37 +0300247 paths = []
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300248 if config:
Michael Bestas03bc7052016-03-12 03:19:10 +0200249 files = ['%s/config/%s' % (_DIR, config)]
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300250 else:
Michael Bestas03bc7052016-03-12 03:19:10 +0200251 files = ['%s/config/%s.yaml' % (_DIR, branch),
252 '%s/config/%s_aosp.yaml' % (_DIR, branch)]
Michael Bestas6c327e62015-05-02 01:58:01 +0300253 for c in files:
Michael Bestas44fbb352015-12-17 02:01:42 +0200254 cmd = ['crowdin-cli', '--config=%s' % c, 'list', 'project',
255 '--branch=%s' % branch]
Anthony Kingb8607632015-05-01 22:06:37 +0300256 comm, ret = run_subprocess(cmd)
257 if ret != 0:
258 sys.exit(ret)
259 for p in str(comm[0]).split("\n"):
260 paths.append(p.replace('/%s' % branch, ''))
Michael Bestas50579d22014-08-09 17:49:14 +0300261
Michael Bestas99f5fce2015-06-04 22:07:51 +0300262 print('\nUploading translations to Gerrit')
Anthony Kingb8607632015-05-01 22:06:37 +0300263 items = [x for sub in xml for x in sub.getElementsByTagName('project')]
Michael Bestas919053f2014-10-20 23:30:54 +0300264 all_projects = []
265
Anthony Kingb8607632015-05-01 22:06:37 +0300266 for path in paths:
267 path = path.strip()
Michael Bestas919053f2014-10-20 23:30:54 +0300268 if not path:
269 continue
270
Anthony Kingb8607632015-05-01 22:06:37 +0300271 if "/res" not in path:
272 print('WARNING: Cannot determine project root dir of '
273 '[%s], skipping.' % path)
Anthony King69a95382015-02-08 18:44:10 +0000274 continue
Anthony Kingb8607632015-05-01 22:06:37 +0300275 result = path.split('/res')[0].strip('/')
276 if result == path.strip('/'):
277 print('WARNING: Cannot determine project root dir of '
278 '[%s], skipping.' % path)
279 continue
Marco Brohet6b6b4e52014-07-20 00:05:16 +0200280
Michael Bestasc899b8c2015-03-03 00:53:19 +0200281 if result in all_projects:
Michael Bestasc899b8c2015-03-03 00:53:19 +0200282 continue
Michael Bestas50579d22014-08-09 17:49:14 +0300283
Anthony Kingb8607632015-05-01 22:06:37 +0300284 # When a project has multiple translatable files, Crowdin will
285 # give duplicates.
286 # We don't want that (useless empty commits), so we save each
287 # project in all_projects and check if it's already in there.
Michael Bestasc899b8c2015-03-03 00:53:19 +0200288 all_projects.append(result)
Anthony King69a95382015-02-08 18:44:10 +0000289
Michael Bestas42e25e32016-03-12 20:18:39 +0200290 # Search android/default.xml or config/%(branch)_extra_packages.xml
Anthony Kingb8607632015-05-01 22:06:37 +0300291 # for the project's name
292 for project in items:
293 path = project.attributes['path'].value
294 if not (result + '/').startswith(path +'/'):
Michael Bestasc899b8c2015-03-03 00:53:19 +0200295 continue
Anthony Kingb8607632015-05-01 22:06:37 +0300296 if result != path:
297 if path in all_projects:
298 break
299 result = path
300 all_projects.append(result)
Anthony King69a95382015-02-08 18:44:10 +0000301
Anthony Kingb8607632015-05-01 22:06:37 +0300302 br = project.getAttribute('revision') or branch
Anthony King69a95382015-02-08 18:44:10 +0000303
Michael Bestas118fcaf2015-06-04 23:02:20 +0300304 push_as_commit(base_path, result,
Michael Bestas80b22ef2018-11-14 23:12:33 +0200305 project.getAttribute('name'), br, username)
Anthony Kingb8607632015-05-01 22:06:37 +0300306 break
Anthony King69a95382015-02-08 18:44:10 +0000307
Anthony King69a95382015-02-08 18:44:10 +0000308
Anthony Kingb8607632015-05-01 22:06:37 +0300309def main():
Anthony Kingb8607632015-05-01 22:06:37 +0300310 args = parse_args()
311 default_branch = args.branch
Michael Bestas118fcaf2015-06-04 23:02:20 +0300312
Michael Bestas602fab22018-11-14 23:14:33 +0200313 base_path = os.getenv('CM_CROWDIN_BASE_PATH')
Michael Bestas118fcaf2015-06-04 23:02:20 +0300314 if base_path is None:
Anthony Kingd0d56cf2015-06-05 10:48:38 +0100315 cwd = os.getcwd()
Michael Bestas602fab22018-11-14 23:14:33 +0200316 print('You have not set CM_CROWDIN_BASE_PATH. Defaulting to %s' % cwd)
Michael Bestas118fcaf2015-06-04 23:02:20 +0300317 base_path = cwd
318 else:
319 base_path = os.path.join(os.path.realpath(base_path), default_branch)
320 if not os.path.isdir(base_path):
Michael Bestas602fab22018-11-14 23:14:33 +0200321 print('CM_CROWDIN_BASE_PATH + branch is not a real directory: %s'
322 % base_path)
Michael Bestas118fcaf2015-06-04 23:02:20 +0300323 sys.exit(1)
Anthony Kingb8607632015-05-01 22:06:37 +0300324
Michael Bestas99f5fce2015-06-04 22:07:51 +0300325 if not check_dependencies():
326 sys.exit(1)
Anthony Kingb8607632015-05-01 22:06:37 +0300327
Michael Bestas118fcaf2015-06-04 23:02:20 +0300328 xml_android = load_xml(x='%s/android/default.xml' % base_path)
Anthony Kingb8607632015-05-01 22:06:37 +0300329 if xml_android is None:
330 sys.exit(1)
331
Michael Bestas42e25e32016-03-12 20:18:39 +0200332 xml_extra = load_xml(x='%s/config/%s_extra_packages.xml'
Anthony Kingd0d56cf2015-06-05 10:48:38 +0100333 % (_DIR, default_branch))
Anthony Kingb8607632015-05-01 22:06:37 +0300334 if xml_extra is None:
335 sys.exit(1)
336
Michael Bestas19dc3352018-02-03 20:24:00 +0200337 xml_snippet = load_xml(x='%s/android/snippets/lineage.xml' % base_path)
338 if xml_snippet is None:
339 xml_snippet = load_xml(x='%s/android/snippets/cm.xml' % base_path)
340 if xml_snippet is None:
341 xml_snippet = load_xml(x='%s/android/snippets/hal_cm_all.xml' % base_path)
342 if xml_snippet is not None:
343 xml_files = (xml_android, xml_snippet, xml_extra)
Michael Bestas687679f2016-12-07 23:20:12 +0200344 else:
345 xml_files = (xml_android, xml_extra)
346
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300347 if args.config:
Michael Bestas03bc7052016-03-12 03:19:10 +0200348 files = ['%s/config/%s' % (_DIR, args.config)]
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300349 else:
Michael Bestas03bc7052016-03-12 03:19:10 +0200350 files = ['%s/config/%s.yaml' % (_DIR, default_branch),
351 '%s/config/%s_aosp.yaml' % (_DIR, default_branch)]
Michael Bestas2f8c4a52015-08-05 21:33:50 +0300352 if not check_files(files):
Anthony Kingb8607632015-05-01 22:06:37 +0300353 sys.exit(1)
354
Michael Bestasfd5d1362015-12-18 20:34:32 +0200355 if args.download and args.username is None:
356 print('Argument -u/--username is required for translations download')
357 sys.exit(1)
358
359 if args.upload_sources:
360 upload_sources_crowdin(default_branch, args.config)
361 if args.upload_translations:
362 upload_translations_crowdin(default_branch, args.config)
363 if args.download:
Michael Bestas687679f2016-12-07 23:20:12 +0200364 download_crowdin(base_path, default_branch, xml_files,
Michael Bestas80b22ef2018-11-14 23:12:33 +0200365 args.username, args.config)
Tom Powell44256852016-07-06 15:23:25 -0700366
367 if _COMMITS_CREATED:
368 print('\nDone!')
369 sys.exit(0)
Tom Powellf42586f2016-07-11 11:02:54 -0700370 else:
Tom Powell44256852016-07-06 15:23:25 -0700371 print('\nNothing to commit')
372 sys.exit(-1)
Anthony Kingb8607632015-05-01 22:06:37 +0300373
374if __name__ == '__main__':
375 main()