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