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 } | |
252 | |
253 if type == 'chrome' or type == 'opera': | |
Wladimir Palant
2016/02/12 17:13:04
What about Safari?
kzar
2016/02/12 18:25:25
Safari isn't a supported type for any of the trans
| |
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 localeConfig['locales'] = {locale.replace('_', '-'): | |
274 os.path.join(fullBasePath, locale) | |
Wladimir Palant
2016/02/12 17:13:04
Replacing '_' by '-' is only necessary for ISO-158
kzar
2016/02/12 18:25:25
Done.
| |
275 for locale in os.listdir(fullBasePath)} | |
276 return localeConfig | |
277 | |
239 def setupTranslations(baseDir, scriptName, opts, args, type): | 278 def setupTranslations(baseDir, scriptName, opts, args, type): |
240 if len(args) < 1: | 279 if len(args) < 1: |
241 print 'Project key is required to update translation master files.' | 280 print 'Project key is required to update translation master files.' |
242 usage(scriptName, type, 'setuptrans') | 281 usage(scriptName, type, 'setuptrans') |
243 return | 282 return |
244 | 283 |
245 key = args[0] | 284 key = args[0] |
246 | 285 |
247 from buildtools.packager import readMetadata | 286 from buildtools.packager import readMetadata |
248 metadata = readMetadata(baseDir, type) | 287 metadata = readMetadata(baseDir, type) |
288 | |
249 basename = metadata.get('general', 'basename') | 289 basename = metadata.get('general', 'basename') |
250 | 290 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 | 291 |
259 import buildtools.localeTools as localeTools | 292 import buildtools.localeTools as localeTools |
260 localeTools.setupTranslations(type, locales, basename, key) | 293 localeTools.setupTranslations(basename, localeConfig, key) |
261 | 294 |
262 | 295 |
263 def updateTranslationMaster(baseDir, scriptName, opts, args, type): | 296 def updateTranslationMaster(baseDir, scriptName, opts, args, type): |
264 if len(args) < 1: | 297 if len(args) < 1: |
265 print 'Project key is required to update translation master files.' | 298 print 'Project key is required to update translation master files.' |
266 usage(scriptName, type, 'translate') | 299 usage(scriptName, type, 'translate') |
267 return | 300 return |
268 | 301 |
269 key = args[0] | 302 key = args[0] |
270 | 303 |
271 from buildtools.packager import readMetadata | 304 from buildtools.packager import readMetadata |
272 metadata = readMetadata(baseDir, type) | 305 metadata = readMetadata(baseDir, type) |
306 | |
273 basename = metadata.get('general', 'basename') | 307 basename = metadata.get('general', 'basename') |
308 localeConfig = readLocaleConfig(baseDir, type, metadata) | |
274 | 309 |
275 if type == 'chrome' or type == 'opera': | 310 defaultLocaleDir = os.path.join(localeConfig['base_path'], |
276 import buildtools.packagerChrome as packager | 311 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 | 312 |
282 import buildtools.localeTools as localeTools | 313 import buildtools.localeTools as localeTools |
283 localeTools.updateTranslationMaster(type, metadata, defaultLocaleDir, basename , key) | 314 localeTools.updateTranslationMaster(metadata, defaultLocaleDir, basename, |
315 localeConfig, key) | |
Wladimir Palant
2016/02/12 17:13:04
With localeConfig being very central for each loca
kzar
2016/02/12 18:25:25
Done.
| |
284 | 316 |
285 | 317 |
286 def uploadTranslations(baseDir, scriptName, opts, args, type): | 318 def uploadTranslations(baseDir, scriptName, opts, args, type): |
287 if len(args) < 1: | 319 if len(args) < 1: |
288 print 'Project key is required to upload existing translations.' | 320 print 'Project key is required to upload existing translations.' |
289 usage(scriptName, type, 'uploadtrans') | 321 usage(scriptName, type, 'uploadtrans') |
290 return | 322 return |
291 | 323 |
292 key = args[0] | 324 key = args[0] |
293 | 325 |
294 from buildtools.packager import readMetadata | 326 from buildtools.packager import readMetadata |
295 metadata = readMetadata(baseDir, type) | 327 metadata = readMetadata(baseDir, type) |
328 | |
296 basename = metadata.get('general', 'basename') | 329 basename = metadata.get('general', 'basename') |
297 | 330 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 | 331 |
309 import buildtools.localeTools as localeTools | 332 import buildtools.localeTools as localeTools |
310 for locale, localeDir in locales: | 333 for locale, localeDir in localeConfig['locales'].iteritems(): |
311 if locale != packager.defaultLocale: | 334 if locale != localeConfig['default_locale']: |
312 localeTools.uploadTranslations(type, metadata, localeDir, locale, basename , key) | 335 localeTools.uploadTranslations(metadata, localeDir, locale, basename, |
336 localeConfig, key) | |
313 | 337 |
314 | 338 |
315 def getTranslations(baseDir, scriptName, opts, args, type): | 339 def getTranslations(baseDir, scriptName, opts, args, type): |
316 if len(args) < 1: | 340 if len(args) < 1: |
317 print 'Project key is required to update translation master files.' | 341 print 'Project key is required to update translation master files.' |
318 usage(scriptName, type, 'translate') | 342 usage(scriptName, type, 'translate') |
319 return | 343 return |
320 | 344 |
345 key = args[0] | |
346 | |
321 from buildtools.packager import readMetadata | 347 from buildtools.packager import readMetadata |
322 metadata = readMetadata(baseDir, type) | 348 metadata = readMetadata(baseDir, type) |
349 | |
323 basename = metadata.get('general', 'basename') | 350 basename = metadata.get('general', 'basename') |
324 | 351 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 | 352 |
333 import buildtools.localeTools as localeTools | 353 import buildtools.localeTools as localeTools |
334 localeTools.getTranslations(type, localesDir, packager.defaultLocale.replace(' _', '-'), basename, key) | 354 localeTools.getTranslations(localeConfig, basename, key) |
335 | 355 |
336 | 356 |
337 def showDescriptions(baseDir, scriptName, opts, args, type): | 357 def showDescriptions(baseDir, scriptName, opts, args, type): |
338 locales = None | 358 locales = None |
339 for option, value in opts: | 359 for option, value in opts: |
340 if option in ('-l', '--locales'): | 360 if option in ('-l', '--locales'): |
341 locales = value.split(',') | 361 locales = value.split(',') |
342 | 362 |
343 import buildtools.packagerGecko as packager | 363 import buildtools.packagerGecko as packager |
344 if locales == None: | 364 if locales == None: |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
452 | 472 |
453 with addCommand(createDevEnv, 'devenv') as command: | 473 with addCommand(createDevEnv, 'devenv') as command: |
454 command.shortDescription = 'Set up a development environment' | 474 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.' | 475 command.description = 'Will set up or update the devenv folder as an unpacked extension folder for development.' |
456 command.supportedTypes = ('chrome', 'opera', 'safari') | 476 command.supportedTypes = ('chrome', 'opera', 'safari') |
457 | 477 |
458 with addCommand(setupTranslations, 'setuptrans') as command: | 478 with addCommand(setupTranslations, 'setuptrans') as command: |
459 command.shortDescription = 'Sets up translation languages' | 479 command.shortDescription = 'Sets up translation languages' |
460 command.description = 'Sets up translation languages for the project on crowdi n.net.' | 480 command.description = 'Sets up translation languages for the project on crowdi n.net.' |
461 command.params = '[options] project-key' | 481 command.params = '[options] project-key' |
462 command.supportedTypes = ('gecko', 'chrome', 'opera') | 482 command.supportedTypes = ('gecko', 'chrome', 'opera', 'generic') |
463 | 483 |
464 with addCommand(updateTranslationMaster, 'translate') as command: | 484 with addCommand(updateTranslationMaster, 'translate') as command: |
465 command.shortDescription = 'Updates translation master files' | 485 command.shortDescription = 'Updates translation master files' |
466 command.description = 'Updates the translation master files in the project on crowdin.net.' | 486 command.description = 'Updates the translation master files in the project on crowdin.net.' |
467 command.params = '[options] project-key' | 487 command.params = '[options] project-key' |
468 command.supportedTypes = ('gecko', 'chrome', 'opera') | 488 command.supportedTypes = ('gecko', 'chrome', 'opera', 'generic') |
469 | 489 |
470 with addCommand(uploadTranslations, 'uploadtrans') as command: | 490 with addCommand(uploadTranslations, 'uploadtrans') as command: |
471 command.shortDescription = 'Uploads existing translations' | 491 command.shortDescription = 'Uploads existing translations' |
472 command.description = 'Uploads already existing translations to the project on crowdin.net.' | 492 command.description = 'Uploads already existing translations to the project on crowdin.net.' |
473 command.params = '[options] project-key' | 493 command.params = '[options] project-key' |
474 command.supportedTypes = ('gecko', 'chrome', 'opera') | 494 command.supportedTypes = ('gecko', 'chrome', 'opera', 'generic') |
475 | 495 |
476 with addCommand(getTranslations, 'gettranslations') as command: | 496 with addCommand(getTranslations, 'gettranslations') as command: |
477 command.shortDescription = 'Downloads translation updates' | 497 command.shortDescription = 'Downloads translation updates' |
478 command.description = 'Downloads updated translations from crowdin.net.' | 498 command.description = 'Downloads updated translations from crowdin.net.' |
479 command.params = '[options] project-key' | 499 command.params = '[options] project-key' |
480 command.supportedTypes = ('gecko', 'chrome', 'opera') | 500 command.supportedTypes = ('gecko', 'chrome', 'opera', 'generic') |
481 | 501 |
482 with addCommand(showDescriptions, 'showdesc') as command: | 502 with addCommand(showDescriptions, 'showdesc') as command: |
483 command.shortDescription = 'Print description strings for all locales' | 503 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.' | 504 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') | 505 command.addOption('Only include the given locales', short='l', long='locales', value='l1,l2,l3') |
486 command.params = '[options]' | 506 command.params = '[options]' |
487 command.supportedTypes = ('gecko') | 507 command.supportedTypes = ('gecko') |
488 | 508 |
489 with addCommand(generateDocs, 'docs') as command: | 509 with addCommand(generateDocs, 'docs') as command: |
490 command.shortDescription = 'Generate documentation (requires node.js)' | 510 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'): | 593 if option in ('-h', '--help'): |
574 usage(scriptName, type, command) | 594 usage(scriptName, type, command) |
575 sys.exit() | 595 sys.exit() |
576 commands[command](baseDir, scriptName, opts, args, type) | 596 commands[command](baseDir, scriptName, opts, args, type) |
577 else: | 597 else: |
578 print 'Command %s is not supported for this application type' % command | 598 print 'Command %s is not supported for this application type' % command |
579 usage(scriptName, type) | 599 usage(scriptName, type) |
580 else: | 600 else: |
581 print 'Command %s is unrecognized' % command | 601 print 'Command %s is unrecognized' % command |
582 usage(scriptName, type) | 602 usage(scriptName, type) |
OLD | NEW |