| LEFT | RIGHT |
| 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 |
| (...skipping 218 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): | 239 def readLocaleConfig(baseDir, type, metadata): |
| 240 if type == 'gecko': | 240 if type == 'gecko': |
| 241 import buildtools.packagerGecko as packager | 241 import buildtools.packagerGecko as packager |
| 242 basePath = packager.getLocalesDir(baseDir) | 242 localeDir = packager.getLocalesDir(baseDir) |
| 243 return { | 243 localeConfig = { |
| 244 'base_path': basePath, | |
| 245 'name_format': 'BCP-47', | 244 'name_format': 'BCP-47', |
| 246 'file_format': 'gecko-dtd', | 245 'file_format': 'gecko-dtd', |
| 247 'target_platforms': {'gecko'}, | 246 'target_platforms': {'gecko'}, |
| 248 'default_locale': packager.defaultLocale, | 247 'default_locale': packager.defaultLocale |
| 249 'locales': {locale: os.path.join(basePath, locale) | |
| 250 for locale in packager.getLocales(baseDir, includeIncomplete)} | |
| 251 } | 248 } |
| 252 | 249 elif type == 'chrome' or type == 'opera': |
| 253 if type == 'chrome' or type == 'opera': | |
| 254 import buildtools.packagerChrome as packager | 250 import buildtools.packagerChrome as packager |
| 255 localeDir = '_locales' | 251 localeDir = os.path.join(baseDir, '_locales') |
| 256 localeConfig = { | 252 localeConfig = { |
| 257 'name_format': 'ISO-15897', | 253 'name_format': 'ISO-15897', |
| 258 'file_format': 'chrome-json', | 254 'file_format': 'chrome-json', |
| 259 'target_platforms': {'chrome'}, | 255 'target_platforms': {'chrome'}, |
| 260 'default_locale': packager.defaultLocale, | 256 'default_locale': packager.defaultLocale, |
| 261 } | 257 } |
| 262 else: | 258 else: |
| 263 localeDir = metadata.get('locales', 'base_path') | 259 localeDir = os.path.join(baseDir, |
| 260 *metadata.get('locales', 'base_path').split('/')) |
| 264 localeConfig = { | 261 localeConfig = { |
| 265 'name_format': metadata.get('locales', 'name_format'), | 262 'name_format': metadata.get('locales', 'name_format'), |
| 266 'file_format': metadata.get('locales', 'file_format'), | 263 'file_format': metadata.get('locales', 'file_format'), |
| 267 'target_platforms': set(metadata.get('locales', | 264 'target_platforms': set(metadata.get('locales', |
| 268 'target_platforms').split()), | 265 'target_platforms').split()), |
| 269 'default_locale': metadata.get('locales', 'default_locale') | 266 'default_locale': metadata.get('locales', 'default_locale') |
| 270 } | 267 } |
| 271 | 268 |
| 272 localeConfig['base_path'] = fullBasePath = os.path.join(baseDir, localeDir) | 269 localeConfig['base_path'] = localeDir |
| 273 localeConfig['locales'] = {locale.replace('_', '-'): | 270 |
| 274 os.path.join(fullBasePath, locale) | 271 locales = [(locale, os.path.join(localeDir, locale)) |
| 275 for locale in os.listdir(fullBasePath)} | 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 |
| 276 return localeConfig | 278 return localeConfig |
| 277 | 279 |
| 278 def setupTranslations(baseDir, scriptName, opts, args, type): | 280 def setupTranslations(baseDir, scriptName, opts, args, type): |
| 279 if len(args) < 1: | 281 if len(args) < 1: |
| 280 print 'Project key is required to update translation master files.' | 282 print 'Project key is required to update translation master files.' |
| 281 usage(scriptName, type, 'setuptrans') | 283 usage(scriptName, type, 'setuptrans') |
| 282 return | 284 return |
| 283 | 285 |
| 284 key = args[0] | 286 key = args[0] |
| 285 | 287 |
| 286 from buildtools.packager import readMetadata | 288 from buildtools.packager import readMetadata |
| 287 metadata = readMetadata(baseDir, type) | 289 metadata = readMetadata(baseDir, type) |
| 288 | 290 |
| 289 basename = metadata.get('general', 'basename') | 291 basename = metadata.get('general', 'basename') |
| 290 localeConfig = readLocaleConfig(baseDir, type, metadata, True) | 292 localeConfig = readLocaleConfig(baseDir, type, metadata) |
| 291 | 293 |
| 292 import buildtools.localeTools as localeTools | 294 import buildtools.localeTools as localeTools |
| 293 localeTools.setupTranslations(basename, localeConfig, key) | 295 localeTools.setupTranslations(localeConfig, basename, key) |
| 294 | 296 |
| 295 | 297 |
| 296 def updateTranslationMaster(baseDir, scriptName, opts, args, type): | 298 def updateTranslationMaster(baseDir, scriptName, opts, args, type): |
| 297 if len(args) < 1: | 299 if len(args) < 1: |
| 298 print 'Project key is required to update translation master files.' | 300 print 'Project key is required to update translation master files.' |
| 299 usage(scriptName, type, 'translate') | 301 usage(scriptName, type, 'translate') |
| 300 return | 302 return |
| 301 | 303 |
| 302 key = args[0] | 304 key = args[0] |
| 303 | 305 |
| 304 from buildtools.packager import readMetadata | 306 from buildtools.packager import readMetadata |
| 305 metadata = readMetadata(baseDir, type) | 307 metadata = readMetadata(baseDir, type) |
| 306 | 308 |
| 307 basename = metadata.get('general', 'basename') | 309 basename = metadata.get('general', 'basename') |
| 308 localeConfig = readLocaleConfig(baseDir, type, metadata) | 310 localeConfig = readLocaleConfig(baseDir, type, metadata) |
| 309 | 311 |
| 310 defaultLocaleDir = os.path.join(localeConfig['base_path'], | 312 defaultLocaleDir = os.path.join(localeConfig['base_path'], |
| 311 localeConfig['default_locale']) | 313 localeConfig['default_locale']) |
| 312 | 314 |
| 313 import buildtools.localeTools as localeTools | 315 import buildtools.localeTools as localeTools |
| 314 localeTools.updateTranslationMaster(metadata, defaultLocaleDir, basename, | 316 localeTools.updateTranslationMaster(localeConfig, metadata, defaultLocaleDir, |
| 315 localeConfig, key) | 317 basename, key) |
| 316 | 318 |
| 317 | 319 |
| 318 def uploadTranslations(baseDir, scriptName, opts, args, type): | 320 def uploadTranslations(baseDir, scriptName, opts, args, type): |
| 319 if len(args) < 1: | 321 if len(args) < 1: |
| 320 print 'Project key is required to upload existing translations.' | 322 print 'Project key is required to upload existing translations.' |
| 321 usage(scriptName, type, 'uploadtrans') | 323 usage(scriptName, type, 'uploadtrans') |
| 322 return | 324 return |
| 323 | 325 |
| 324 key = args[0] | 326 key = args[0] |
| 325 | 327 |
| 326 from buildtools.packager import readMetadata | 328 from buildtools.packager import readMetadata |
| 327 metadata = readMetadata(baseDir, type) | 329 metadata = readMetadata(baseDir, type) |
| 328 | 330 |
| 329 basename = metadata.get('general', 'basename') | 331 basename = metadata.get('general', 'basename') |
| 330 localeConfig = readLocaleConfig(baseDir, type, metadata, True) | 332 localeConfig = readLocaleConfig(baseDir, type, metadata) |
| 331 | 333 |
| 332 import buildtools.localeTools as localeTools | 334 import buildtools.localeTools as localeTools |
| 333 for locale, localeDir in localeConfig['locales'].iteritems(): | 335 for locale, localeDir in localeConfig['locales'].iteritems(): |
| 334 if locale != localeConfig['default_locale']: | 336 if locale != localeConfig['default_locale']: |
| 335 localeTools.uploadTranslations(metadata, localeDir, locale, basename, | 337 localeTools.uploadTranslations(localeConfig, metadata, localeDir, locale, |
| 336 localeConfig, key) | 338 basename, key) |
| 337 | 339 |
| 338 | 340 |
| 339 def getTranslations(baseDir, scriptName, opts, args, type): | 341 def getTranslations(baseDir, scriptName, opts, args, type): |
| 340 if len(args) < 1: | 342 if len(args) < 1: |
| 341 print 'Project key is required to update translation master files.' | 343 print 'Project key is required to update translation master files.' |
| 342 usage(scriptName, type, 'translate') | 344 usage(scriptName, type, 'translate') |
| 343 return | 345 return |
| 344 | 346 |
| 345 key = args[0] | 347 key = args[0] |
| 346 | 348 |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 if option in ('-h', '--help'): | 595 if option in ('-h', '--help'): |
| 594 usage(scriptName, type, command) | 596 usage(scriptName, type, command) |
| 595 sys.exit() | 597 sys.exit() |
| 596 commands[command](baseDir, scriptName, opts, args, type) | 598 commands[command](baseDir, scriptName, opts, args, type) |
| 597 else: | 599 else: |
| 598 print 'Command %s is not supported for this application type' % command | 600 print 'Command %s is not supported for this application type' % command |
| 599 usage(scriptName, type) | 601 usage(scriptName, type) |
| 600 else: | 602 else: |
| 601 print 'Command %s is unrecognized' % command | 603 print 'Command %s is unrecognized' % command |
| 602 usage(scriptName, type) | 604 usage(scriptName, type) |
| LEFT | RIGHT |