| LEFT | RIGHT |
| 1 # This Source Code Form is subject to the terms of the Mozilla Public | 1 # This Source Code Form is subject to the terms of the Mozilla Public |
| 2 # License, v. 2.0. If a copy of the MPL was not distributed with this | 2 # License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. | 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 4 | 4 |
| 5 import argparse | 5 import argparse |
| 6 import logging | 6 import logging |
| 7 import os | 7 import os |
| 8 import re | 8 import re |
| 9 import shutil | 9 import shutil |
| 10 import subprocess | 10 import subprocess |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 with ZipFile(file, 'r') as zip_file: | 189 with ZipFile(file, 'r') as zip_file: |
| 190 zip_file.extractall(devenv_dir) | 190 zip_file.extractall(devenv_dir) |
| 191 | 191 |
| 192 | 192 |
| 193 project_key_argument = make_argument( | 193 project_key_argument = make_argument( |
| 194 'project_key', help='The crowdin project key.', | 194 'project_key', help='The crowdin project key.', |
| 195 ) | 195 ) |
| 196 | 196 |
| 197 | 197 |
| 198 @argparse_command( | 198 @argparse_command( |
| 199 arguments=(project_key_argument, ), | 199 arguments=(project_key_argument,), |
| 200 ) | 200 ) |
| 201 def setuptrans(base_dir, project_key, platform, **kwargs): | 201 def setuptrans(base_dir, project_key, platform, **kwargs): |
| 202 """ | 202 """ |
| 203 Set up translation languages. | 203 Set up translation languages. |
| 204 | 204 |
| 205 Set up translation languages for the project on crowdin.com. | 205 Set up translation languages for the project on crowdin.com. |
| 206 """ | 206 """ |
| 207 from buildtools.packager import readMetadata | 207 from buildtools.packager import readMetadata |
| 208 metadata = readMetadata(base_dir, platform) | 208 metadata = readMetadata(base_dir, platform) |
| 209 | 209 |
| 210 basename = metadata.get('general', 'basename') | 210 basename = metadata.get('general', 'basename') |
| 211 locale_config = read_locale_config(base_dir, platform, metadata) | 211 locale_config = read_locale_config(base_dir, platform, metadata) |
| 212 | 212 |
| 213 import buildtools.localeTools as localeTools | 213 import buildtools.localeTools as localeTools |
| 214 localeTools.setupTranslations(locale_config, basename, project_key) | 214 localeTools.setupTranslations(locale_config, basename, project_key) |
| 215 | 215 |
| 216 | 216 |
| 217 @argparse_command( | 217 @argparse_command( |
| 218 arguments=(project_key_argument, ), | 218 arguments=(project_key_argument,), |
| 219 ) | 219 ) |
| 220 def translate(base_dir, project_key, platform, **kwargs): | 220 def translate(base_dir, project_key, platform, **kwargs): |
| 221 """ | 221 """ |
| 222 Update translation master files. | 222 Update translation master files. |
| 223 | 223 |
| 224 Update the translation master files in the project on crowdin.com. | 224 Update the translation master files in the project on crowdin.com. |
| 225 """ | 225 """ |
| 226 from buildtools.packager import readMetadata | 226 from buildtools.packager import readMetadata |
| 227 metadata = readMetadata(base_dir, platform) | 227 metadata = readMetadata(base_dir, platform) |
| 228 | 228 |
| 229 basename = metadata.get('general', 'basename') | 229 basename = metadata.get('general', 'basename') |
| 230 locale_config = read_locale_config(base_dir, platform, metadata) | 230 locale_config = read_locale_config(base_dir, platform, metadata) |
| 231 | 231 |
| 232 default_locale_dir = os.path.join(locale_config['base_path'], | 232 default_locale_dir = os.path.join(locale_config['base_path'], |
| 233 locale_config['default_locale']) | 233 locale_config['default_locale']) |
| 234 | 234 |
| 235 import buildtools.localeTools as localeTools | 235 import buildtools.localeTools as localeTools |
| 236 localeTools.updateTranslationMaster(locale_config, metadata, | 236 localeTools.updateTranslationMaster(locale_config, metadata, |
| 237 default_locale_dir, basename, | 237 default_locale_dir, basename, |
| 238 project_key) | 238 project_key) |
| 239 | 239 |
| 240 | 240 |
| 241 @argparse_command( | 241 @argparse_command( |
| 242 arguments=(project_key_argument, ), | 242 arguments=(project_key_argument,), |
| 243 ) | 243 ) |
| 244 def uploadtrans(base_dir, project_key, platform, **kwargs): | 244 def uploadtrans(base_dir, project_key, platform, **kwargs): |
| 245 """ | 245 """ |
| 246 Upload existing translations. | 246 Upload existing translations. |
| 247 | 247 |
| 248 Upload already existing translations to the project on crowdin.com. | 248 Upload already existing translations to the project on crowdin.com. |
| 249 """ | 249 """ |
| 250 from buildtools.packager import readMetadata | 250 from buildtools.packager import readMetadata |
| 251 metadata = readMetadata(base_dir, platform) | 251 metadata = readMetadata(base_dir, platform) |
| 252 | 252 |
| 253 basename = metadata.get('general', 'basename') | 253 basename = metadata.get('general', 'basename') |
| 254 locale_config = read_locale_config(base_dir, platform, metadata) | 254 locale_config = read_locale_config(base_dir, platform, metadata) |
| 255 | 255 |
| 256 import buildtools.localeTools as localeTools | 256 import buildtools.localeTools as localeTools |
| 257 for locale, locale_dir in locale_config['locales'].iteritems(): | 257 for locale, locale_dir in locale_config['locales'].iteritems(): |
| 258 if locale != locale_config['default_locale'].replace('_', '-'): | 258 if locale != locale_config['default_locale'].replace('_', '-'): |
| 259 localeTools.uploadTranslations(locale_config, metadata, locale_dir, | 259 localeTools.uploadTranslations(locale_config, metadata, locale_dir, |
| 260 locale, basename, project_key) | 260 locale, basename, project_key) |
| 261 | 261 |
| 262 | 262 |
| 263 @argparse_command( | 263 @argparse_command( |
| 264 arguments=(project_key_argument, ), | 264 arguments=(project_key_argument,), |
| 265 ) | 265 ) |
| 266 def gettranslations(base_dir, project_key, platform, **kwargs): | 266 def gettranslations(base_dir, project_key, platform, **kwargs): |
| 267 """ | 267 """ |
| 268 Download translation updates. | 268 Download translation updates. |
| 269 | 269 |
| 270 Download updated translations from crowdin.com. | 270 Download updated translations from crowdin.com. |
| 271 """ | 271 """ |
| 272 from buildtools.packager import readMetadata | 272 from buildtools.packager import readMetadata |
| 273 metadata = readMetadata(base_dir, platform) | 273 metadata = readMetadata(base_dir, platform) |
| 274 | 274 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 if build_available_subcommands(base_dir): | 379 if build_available_subcommands(base_dir): |
| 380 MAIN_PARSER.set_defaults(base_dir=base_dir) | 380 MAIN_PARSER.set_defaults(base_dir=base_dir) |
| 381 | 381 |
| 382 # If no args are provided, this module is run directly from the command | 382 # If no args are provided, this module is run directly from the command |
| 383 # line. argparse will take care of consuming sys.argv. | 383 # line. argparse will take care of consuming sys.argv. |
| 384 arguments = MAIN_PARSER.parse_args(args if len(args) > 0 else None) | 384 arguments = MAIN_PARSER.parse_args(args if len(args) > 0 else None) |
| 385 | 385 |
| 386 function = arguments.function | 386 function = arguments.function |
| 387 del arguments.function | 387 del arguments.function |
| 388 function(**vars(arguments)) | 388 function(**vars(arguments)) |
| LEFT | RIGHT |