Left: | ||
Right: |
OLD | NEW |
---|---|
1 # coding: utf-8 | 1 # coding: utf-8 |
2 | 2 |
3 # This Source Code Form is subject to the terms of the Mozilla Public | 3 # This Source Code Form is subject to the terms of the Mozilla Public |
4 # License, v. 2.0. If a copy of the MPL was not distributed with this | 4 # License, v. 2.0. If a copy of the MPL was not distributed with this |
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/. | 5 # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
6 | 6 |
7 import os, sys, re, subprocess, shutil, buildtools | 7 import os, sys, re, subprocess, shutil, buildtools |
8 from getopt import getopt, GetoptError | 8 from getopt import getopt, GetoptError |
9 from StringIO import StringIO | 9 from StringIO import StringIO |
10 from zipfile import ZipFile | 10 from zipfile import ZipFile |
11 | 11 |
12 knownTypes = ('gecko', 'chrome', 'opera', 'safari') | 12 knownTypes = ('gecko', 'chrome', 'opera', 'safari', 'generic') |
13 | 13 |
14 class Command(object): | 14 class Command(object): |
15 name = property(lambda self: self._name) | 15 name = property(lambda self: self._name) |
16 shortDescription = property(lambda self: self._shortDescription, | 16 shortDescription = property(lambda self: self._shortDescription, |
17 lambda self, value: self.__dict__.update({'_shortDescription': value})) | 17 lambda self, value: self.__dict__.update({'_shortDescription': value})) |
18 description = property(lambda self: self._description, | 18 description = property(lambda self: self._description, |
19 lambda self, value: self.__dict__.update({'_description': value})) | 19 lambda self, value: self.__dict__.update({'_description': value})) |
20 params = property(lambda self: self._params, | 20 params = property(lambda self: self._params, |
21 lambda self, value: self.__dict__.update({'_params': value})) | 21 lambda self, value: self.__dict__.update({'_params': value})) |
22 supportedTypes = property(lambda self: self._supportedTypes, | 22 supportedTypes = property(lambda self: self._supportedTypes, |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
229 from buildtools.packager import getDevEnvPath | 229 from buildtools.packager import getDevEnvPath |
230 devenv_dir = getDevEnvPath(baseDir, type) | 230 devenv_dir = getDevEnvPath(baseDir, type) |
231 | 231 |
232 shutil.rmtree(devenv_dir, ignore_errors=True) | 232 shutil.rmtree(devenv_dir, ignore_errors=True) |
233 | 233 |
234 file.seek(0) | 234 file.seek(0) |
235 with ZipFile(file, 'r') as zip_file: | 235 with ZipFile(file, 'r') as zip_file: |
236 zip_file.extractall(devenv_dir) | 236 zip_file.extractall(devenv_dir) |
237 | 237 |
238 | 238 |
239 def readLocaleConfig(baseDir, type, metadata, includeIncomplete=False): | |
240 if type == 'gecko': | |
241 import buildtools.packagerGecko as packager | |
242 basePath = packager.getLocalesDir(baseDir) | |
243 return { | |
244 'base_path': basePath, | |
245 'name_format': 'BCP-47', | |
246 'file_format': 'gecko-dtd', | |
247 'target_platforms': {'gecko'}, | |
248 'default_locale': packager.defaultLocale, | |
249 'locales': {locale: os.path.join(basePath, locale) | |
250 for locale in packager.getLocales(baseDir, includeIncomplete)} | |
251 } | |
Wladimir Palant
2016/02/12 19:05:43
Gecko is still being treated as a special case her
kzar
2016/02/12 19:40:26
Done.
| |
252 | |
253 if type == 'chrome' or type == 'opera': | |
254 import buildtools.packagerChrome as packager | |
255 localeDir = '_locales' | |
256 localeConfig = { | |
257 'name_format': 'ISO-15897', | |
258 'file_format': 'chrome-json', | |
259 'target_platforms': {'chrome'}, | |
260 'default_locale': packager.defaultLocale, | |
261 } | |
262 else: | |
263 localeDir = metadata.get('locales', 'base_path') | |
264 localeConfig = { | |
265 'name_format': metadata.get('locales', 'name_format'), | |
266 'file_format': metadata.get('locales', 'file_format'), | |
267 'target_platforms': set(metadata.get('locales', | |
268 'target_platforms').split()), | |
269 'default_locale': metadata.get('locales', 'default_locale') | |
270 } | |
271 | |
272 localeConfig['base_path'] = fullBasePath = os.path.join(baseDir, localeDir) | |
273 | |
274 locales = [(locale, os.path.join(fullBasePath, locale)) | |
275 for locale in os.listdir(fullBasePath)] | |
276 if localeConfig['name_format'] == 'ISO-15897': | |
277 locales = [(locale.replace('_', '-'), localePath) | |
278 for locale, localePath in locales] | |
279 localeConfig['locales'] = dict(locales) | |
280 | |
281 return localeConfig | |
282 | |
239 def setupTranslations(baseDir, scriptName, opts, args, type): | 283 def setupTranslations(baseDir, scriptName, opts, args, type): |
240 if len(args) < 1: | 284 if len(args) < 1: |
241 print 'Project key is required to update translation master files.' | 285 print 'Project key is required to update translation master files.' |
242 usage(scriptName, type, 'setuptrans') | 286 usage(scriptName, type, 'setuptrans') |
243 return | 287 return |
244 | 288 |
245 key = args[0] | 289 key = args[0] |
246 | 290 |
247 from buildtools.packager import readMetadata | 291 from buildtools.packager import readMetadata |
248 metadata = readMetadata(baseDir, type) | 292 metadata = readMetadata(baseDir, type) |
293 | |
249 basename = metadata.get('general', 'basename') | 294 basename = metadata.get('general', 'basename') |
250 | 295 localeConfig = readLocaleConfig(baseDir, type, metadata, True) |
251 if type == 'chrome' or type == 'opera': | |
252 import buildtools.packagerChrome as packager | |
253 locales = os.listdir(os.path.join(baseDir, '_locales')) | |
254 locales = map(lambda locale: locale.replace('_', '-'), locales) | |
255 else: | |
256 import buildtools.packagerGecko as packager | |
257 locales = packager.getLocales(baseDir, True) | |
258 | 296 |
259 import buildtools.localeTools as localeTools | 297 import buildtools.localeTools as localeTools |
260 localeTools.setupTranslations(type, locales, basename, key) | 298 localeTools.setupTranslations(localeConfig, basename, key) |
261 | 299 |
262 | 300 |
263 def updateTranslationMaster(baseDir, scriptName, opts, args, type): | 301 def updateTranslationMaster(baseDir, scriptName, opts, args, type): |
264 if len(args) < 1: | 302 if len(args) < 1: |
265 print 'Project key is required to update translation master files.' | 303 print 'Project key is required to update translation master files.' |
266 usage(scriptName, type, 'translate') | 304 usage(scriptName, type, 'translate') |
267 return | 305 return |
268 | 306 |
269 key = args[0] | 307 key = args[0] |
270 | 308 |
271 from buildtools.packager import readMetadata | 309 from buildtools.packager import readMetadata |
272 metadata = readMetadata(baseDir, type) | 310 metadata = readMetadata(baseDir, type) |
311 | |
273 basename = metadata.get('general', 'basename') | 312 basename = metadata.get('general', 'basename') |
313 localeConfig = readLocaleConfig(baseDir, type, metadata) | |
274 | 314 |
275 if type == 'chrome' or type == 'opera': | 315 defaultLocaleDir = os.path.join(localeConfig['base_path'], |
276 import buildtools.packagerChrome as packager | 316 localeConfig['default_locale']) |
277 defaultLocaleDir = os.path.join(baseDir, '_locales', packager.defaultLocale) | |
278 else: | |
279 import buildtools.packagerGecko as packager | |
280 defaultLocaleDir = os.path.join(packager.getLocalesDir(baseDir), packager.de faultLocale) | |
281 | 317 |
282 import buildtools.localeTools as localeTools | 318 import buildtools.localeTools as localeTools |
283 localeTools.updateTranslationMaster(type, metadata, defaultLocaleDir, basename , key) | 319 localeTools.updateTranslationMaster(localeConfig, metadata, defaultLocaleDir, |
320 basename, key) | |
284 | 321 |
285 | 322 |
286 def uploadTranslations(baseDir, scriptName, opts, args, type): | 323 def uploadTranslations(baseDir, scriptName, opts, args, type): |
287 if len(args) < 1: | 324 if len(args) < 1: |
288 print 'Project key is required to upload existing translations.' | 325 print 'Project key is required to upload existing translations.' |
289 usage(scriptName, type, 'uploadtrans') | 326 usage(scriptName, type, 'uploadtrans') |
290 return | 327 return |
291 | 328 |
292 key = args[0] | 329 key = args[0] |
293 | 330 |
294 from buildtools.packager import readMetadata | 331 from buildtools.packager import readMetadata |
295 metadata = readMetadata(baseDir, type) | 332 metadata = readMetadata(baseDir, type) |
333 | |
296 basename = metadata.get('general', 'basename') | 334 basename = metadata.get('general', 'basename') |
297 | 335 localeConfig = readLocaleConfig(baseDir, type, metadata, True) |
298 if type == 'chrome' or type == 'opera': | |
299 import buildtools.packagerChrome as packager | |
300 localesDir = os.path.join(baseDir, '_locales') | |
301 locales = os.listdir(localesDir) | |
302 locales = map(lambda locale: (locale.replace('_', '-'), os.path.join(locales Dir, locale)), locales) | |
303 else: | |
304 import buildtools.packagerGecko as packager | |
305 localesDir = packager.getLocalesDir(baseDir) | |
306 locales = packager.getLocales(baseDir, True) | |
307 locales = map(lambda locale: (locale, os.path.join(localesDir, locale)), loc ales) | |
308 | 336 |
309 import buildtools.localeTools as localeTools | 337 import buildtools.localeTools as localeTools |
310 for locale, localeDir in locales: | 338 for locale, localeDir in localeConfig['locales'].iteritems(): |
311 if locale != packager.defaultLocale: | 339 if locale != localeConfig['default_locale']: |
312 localeTools.uploadTranslations(type, metadata, localeDir, locale, basename , key) | 340 localeTools.uploadTranslations(localeConfig, metadata, localeDir, locale, |
341 basename, key) | |
313 | 342 |
314 | 343 |
315 def getTranslations(baseDir, scriptName, opts, args, type): | 344 def getTranslations(baseDir, scriptName, opts, args, type): |
316 if len(args) < 1: | 345 if len(args) < 1: |
317 print 'Project key is required to update translation master files.' | 346 print 'Project key is required to update translation master files.' |
318 usage(scriptName, type, 'translate') | 347 usage(scriptName, type, 'translate') |
319 return | 348 return |
320 | 349 |
350 key = args[0] | |
351 | |
321 from buildtools.packager import readMetadata | 352 from buildtools.packager import readMetadata |
322 metadata = readMetadata(baseDir, type) | 353 metadata = readMetadata(baseDir, type) |
354 | |
323 basename = metadata.get('general', 'basename') | 355 basename = metadata.get('general', 'basename') |
324 | 356 localeConfig = readLocaleConfig(baseDir, type, metadata) |
325 key = args[0] | |
326 if type == 'chrome' or type == 'opera': | |
327 import buildtools.packagerChrome as packager | |
328 localesDir = os.path.join(baseDir, '_locales') | |
329 else: | |
330 import buildtools.packagerGecko as packager | |
331 localesDir = packager.getLocalesDir(baseDir) | |
332 | 357 |
333 import buildtools.localeTools as localeTools | 358 import buildtools.localeTools as localeTools |
334 localeTools.getTranslations(type, localesDir, packager.defaultLocale.replace(' _', '-'), basename, key) | 359 localeTools.getTranslations(localeConfig, basename, key) |
335 | 360 |
336 | 361 |
337 def showDescriptions(baseDir, scriptName, opts, args, type): | 362 def showDescriptions(baseDir, scriptName, opts, args, type): |
338 locales = None | 363 locales = None |
339 for option, value in opts: | 364 for option, value in opts: |
340 if option in ('-l', '--locales'): | 365 if option in ('-l', '--locales'): |
341 locales = value.split(',') | 366 locales = value.split(',') |
342 | 367 |
343 import buildtools.packagerGecko as packager | 368 import buildtools.packagerGecko as packager |
344 if locales == None: | 369 if locales == None: |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
452 | 477 |
453 with addCommand(createDevEnv, 'devenv') as command: | 478 with addCommand(createDevEnv, 'devenv') as command: |
454 command.shortDescription = 'Set up a development environment' | 479 command.shortDescription = 'Set up a development environment' |
455 command.description = 'Will set up or update the devenv folder as an unpacked extension folder for development.' | 480 command.description = 'Will set up or update the devenv folder as an unpacked extension folder for development.' |
456 command.supportedTypes = ('chrome', 'opera', 'safari') | 481 command.supportedTypes = ('chrome', 'opera', 'safari') |
457 | 482 |
458 with addCommand(setupTranslations, 'setuptrans') as command: | 483 with addCommand(setupTranslations, 'setuptrans') as command: |
459 command.shortDescription = 'Sets up translation languages' | 484 command.shortDescription = 'Sets up translation languages' |
460 command.description = 'Sets up translation languages for the project on crowdi n.net.' | 485 command.description = 'Sets up translation languages for the project on crowdi n.net.' |
461 command.params = '[options] project-key' | 486 command.params = '[options] project-key' |
462 command.supportedTypes = ('gecko', 'chrome', 'opera') | 487 command.supportedTypes = ('gecko', 'chrome', 'opera', 'generic') |
463 | 488 |
464 with addCommand(updateTranslationMaster, 'translate') as command: | 489 with addCommand(updateTranslationMaster, 'translate') as command: |
465 command.shortDescription = 'Updates translation master files' | 490 command.shortDescription = 'Updates translation master files' |
466 command.description = 'Updates the translation master files in the project on crowdin.net.' | 491 command.description = 'Updates the translation master files in the project on crowdin.net.' |
467 command.params = '[options] project-key' | 492 command.params = '[options] project-key' |
468 command.supportedTypes = ('gecko', 'chrome', 'opera') | 493 command.supportedTypes = ('gecko', 'chrome', 'opera', 'generic') |
469 | 494 |
470 with addCommand(uploadTranslations, 'uploadtrans') as command: | 495 with addCommand(uploadTranslations, 'uploadtrans') as command: |
471 command.shortDescription = 'Uploads existing translations' | 496 command.shortDescription = 'Uploads existing translations' |
472 command.description = 'Uploads already existing translations to the project on crowdin.net.' | 497 command.description = 'Uploads already existing translations to the project on crowdin.net.' |
473 command.params = '[options] project-key' | 498 command.params = '[options] project-key' |
474 command.supportedTypes = ('gecko', 'chrome', 'opera') | 499 command.supportedTypes = ('gecko', 'chrome', 'opera', 'generic') |
475 | 500 |
476 with addCommand(getTranslations, 'gettranslations') as command: | 501 with addCommand(getTranslations, 'gettranslations') as command: |
477 command.shortDescription = 'Downloads translation updates' | 502 command.shortDescription = 'Downloads translation updates' |
478 command.description = 'Downloads updated translations from crowdin.net.' | 503 command.description = 'Downloads updated translations from crowdin.net.' |
479 command.params = '[options] project-key' | 504 command.params = '[options] project-key' |
480 command.supportedTypes = ('gecko', 'chrome', 'opera') | 505 command.supportedTypes = ('gecko', 'chrome', 'opera', 'generic') |
481 | 506 |
482 with addCommand(showDescriptions, 'showdesc') as command: | 507 with addCommand(showDescriptions, 'showdesc') as command: |
483 command.shortDescription = 'Print description strings for all locales' | 508 command.shortDescription = 'Print description strings for all locales' |
484 command.description = 'Display description strings for all locales as specifie d in the corresponding meta.properties files.' | 509 command.description = 'Display description strings for all locales as specifie d in the corresponding meta.properties files.' |
485 command.addOption('Only include the given locales', short='l', long='locales', value='l1,l2,l3') | 510 command.addOption('Only include the given locales', short='l', long='locales', value='l1,l2,l3') |
486 command.params = '[options]' | 511 command.params = '[options]' |
487 command.supportedTypes = ('gecko') | 512 command.supportedTypes = ('gecko') |
488 | 513 |
489 with addCommand(generateDocs, 'docs') as command: | 514 with addCommand(generateDocs, 'docs') as command: |
490 command.shortDescription = 'Generate documentation (requires node.js)' | 515 command.shortDescription = 'Generate documentation (requires node.js)' |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
573 if option in ('-h', '--help'): | 598 if option in ('-h', '--help'): |
574 usage(scriptName, type, command) | 599 usage(scriptName, type, command) |
575 sys.exit() | 600 sys.exit() |
576 commands[command](baseDir, scriptName, opts, args, type) | 601 commands[command](baseDir, scriptName, opts, args, type) |
577 else: | 602 else: |
578 print 'Command %s is not supported for this application type' % command | 603 print 'Command %s is not supported for this application type' % command |
579 usage(scriptName, type) | 604 usage(scriptName, type) |
580 else: | 605 else: |
581 print 'Command %s is unrecognized' % command | 606 print 'Command %s is unrecognized' % command |
582 usage(scriptName, type) | 607 usage(scriptName, type) |
OLD | NEW |