| 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 |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 | 235 |
| 236 | 236 |
| 237 def setupTranslations(baseDir, scriptName, opts, args, type): | 237 def setupTranslations(baseDir, scriptName, opts, args, type): |
| 238 if len(args) < 1: | 238 if len(args) < 1: |
| 239 print 'Project key is required to update translation master files.' | 239 print 'Project key is required to update translation master files.' |
| 240 usage(scriptName, type, 'setuptrans') | 240 usage(scriptName, type, 'setuptrans') |
| 241 return | 241 return |
| 242 | 242 |
| 243 key = args[0] | 243 key = args[0] |
| 244 | 244 |
| 245 from buildtools.packager import readMetadata |
| 246 metadata = readMetadata(baseDir, type) |
| 247 basename = metadata.get('general', 'basename') |
| 248 |
| 245 if type == 'chrome' or type == 'opera': | 249 if type == 'chrome' or type == 'opera': |
| 246 import buildtools.packagerChrome as packager | 250 import buildtools.packagerChrome as packager |
| 247 locales = os.listdir(os.path.join(baseDir, '_locales')) | 251 locales = os.listdir(os.path.join(baseDir, '_locales')) |
| 248 locales = map(lambda locale: locale.replace('_', '-'), locales) | 252 locales = map(lambda locale: locale.replace('_', '-'), locales) |
| 249 basename = packager.readMetadata(baseDir, type).get('general', 'basename') | |
| 250 else: | 253 else: |
| 251 import buildtools.packagerGecko as packager | 254 import buildtools.packagerGecko as packager |
| 252 locales = packager.getLocales(baseDir, True) | 255 locales = packager.getLocales(baseDir, True) |
| 253 basename = packager.readMetadata(baseDir, type).get('general', 'basename') | |
| 254 | 256 |
| 255 import buildtools.localeTools as localeTools | 257 import buildtools.localeTools as localeTools |
| 256 localeTools.setupTranslations(type, locales, basename, key) | 258 localeTools.setupTranslations(type, locales, basename, key) |
| 257 | 259 |
| 258 | 260 |
| 259 def updateTranslationMaster(baseDir, scriptName, opts, args, type): | 261 def updateTranslationMaster(baseDir, scriptName, opts, args, type): |
| 260 if len(args) < 1: | 262 if len(args) < 1: |
| 261 print 'Project key is required to update translation master files.' | 263 print 'Project key is required to update translation master files.' |
| 262 usage(scriptName, type, 'translate') | 264 usage(scriptName, type, 'translate') |
| 263 return | 265 return |
| 264 | 266 |
| 265 key = args[0] | 267 key = args[0] |
| 266 | 268 |
| 269 from buildtools.packager import readMetadata |
| 270 metadata = readMetadata(baseDir, type) |
| 271 basename = metadata.get('general', 'basename') |
| 272 |
| 267 if type == 'chrome' or type == 'opera': | 273 if type == 'chrome' or type == 'opera': |
| 268 import buildtools.packagerChrome as packager | 274 import buildtools.packagerChrome as packager |
| 269 defaultLocaleDir = os.path.join(baseDir, '_locales', packager.defaultLocale) | 275 defaultLocaleDir = os.path.join(baseDir, '_locales', packager.defaultLocale) |
| 270 metadata = packager.readMetadata(baseDir, type) | |
| 271 basename = metadata.get('general', 'basename') | |
| 272 else: | 276 else: |
| 273 import buildtools.packagerGecko as packager | 277 import buildtools.packagerGecko as packager |
| 274 defaultLocaleDir = os.path.join(packager.getLocalesDir(baseDir), packager.de
faultLocale) | 278 defaultLocaleDir = os.path.join(packager.getLocalesDir(baseDir), packager.de
faultLocale) |
| 275 metadata = packager.readMetadata(baseDir, type) | |
| 276 basename = metadata.get('general', 'basename') | |
| 277 | 279 |
| 278 import buildtools.localeTools as localeTools | 280 import buildtools.localeTools as localeTools |
| 279 localeTools.updateTranslationMaster(type, metadata, defaultLocaleDir, basename
, key) | 281 localeTools.updateTranslationMaster(type, metadata, defaultLocaleDir, basename
, key) |
| 280 | 282 |
| 281 | 283 |
| 282 def uploadTranslations(baseDir, scriptName, opts, args, type): | 284 def uploadTranslations(baseDir, scriptName, opts, args, type): |
| 283 if len(args) < 1: | 285 if len(args) < 1: |
| 284 print 'Project key is required to upload existing translations.' | 286 print 'Project key is required to upload existing translations.' |
| 285 usage(scriptName, type, 'uploadtrans') | 287 usage(scriptName, type, 'uploadtrans') |
| 286 return | 288 return |
| 287 | 289 |
| 288 key = args[0] | 290 key = args[0] |
| 289 | 291 |
| 292 from buildtools.packager import readMetadata |
| 293 metadata = readMetadata(baseDir, type) |
| 294 basename = metadata.get('general', 'basename') |
| 295 |
| 290 if type == 'chrome' or type == 'opera': | 296 if type == 'chrome' or type == 'opera': |
| 291 import buildtools.packagerChrome as packager | 297 import buildtools.packagerChrome as packager |
| 292 localesDir = os.path.join(baseDir, '_locales') | 298 localesDir = os.path.join(baseDir, '_locales') |
| 293 locales = os.listdir(localesDir) | 299 locales = os.listdir(localesDir) |
| 294 locales = map(lambda locale: (locale.replace('_', '-'), os.path.join(locales
Dir, locale)), locales) | 300 locales = map(lambda locale: (locale.replace('_', '-'), os.path.join(locales
Dir, locale)), locales) |
| 295 metadata = packager.readMetadata(baseDir, type) | |
| 296 basename = metadata.get('general', 'basename') | |
| 297 else: | 301 else: |
| 298 import buildtools.packagerGecko as packager | 302 import buildtools.packagerGecko as packager |
| 299 localesDir = packager.getLocalesDir(baseDir) | 303 localesDir = packager.getLocalesDir(baseDir) |
| 300 locales = packager.getLocales(baseDir, True) | 304 locales = packager.getLocales(baseDir, True) |
| 301 locales = map(lambda locale: (locale, os.path.join(localesDir, locale)), loc
ales) | 305 locales = map(lambda locale: (locale, os.path.join(localesDir, locale)), loc
ales) |
| 302 metadata = packager.readMetadata(baseDir, type) | |
| 303 basename = metadata.get('general', 'basename') | |
| 304 | 306 |
| 305 import buildtools.localeTools as localeTools | 307 import buildtools.localeTools as localeTools |
| 306 for locale, localeDir in locales: | 308 for locale, localeDir in locales: |
| 307 if locale != packager.defaultLocale: | 309 if locale != packager.defaultLocale: |
| 308 localeTools.uploadTranslations(type, metadata, localeDir, locale, basename
, key) | 310 localeTools.uploadTranslations(type, metadata, localeDir, locale, basename
, key) |
| 309 | 311 |
| 310 | 312 |
| 311 def getTranslations(baseDir, scriptName, opts, args, type): | 313 def getTranslations(baseDir, scriptName, opts, args, type): |
| 312 if len(args) < 1: | 314 if len(args) < 1: |
| 313 print 'Project key is required to update translation master files.' | 315 print 'Project key is required to update translation master files.' |
| 314 usage(scriptName, type, 'translate') | 316 usage(scriptName, type, 'translate') |
| 315 return | 317 return |
| 316 | 318 |
| 319 from buildtools.packager import readMetadata |
| 320 metadata = readMetadata(baseDir, type) |
| 321 basename = metadata.get('general', 'basename') |
| 322 |
| 317 key = args[0] | 323 key = args[0] |
| 318 if type == 'chrome' or type == 'opera': | 324 if type == 'chrome' or type == 'opera': |
| 319 import buildtools.packagerChrome as packager | 325 import buildtools.packagerChrome as packager |
| 320 localesDir = os.path.join(baseDir, '_locales') | 326 localesDir = os.path.join(baseDir, '_locales') |
| 321 else: | 327 else: |
| 322 import buildtools.packagerGecko as packager | 328 import buildtools.packagerGecko as packager |
| 323 localesDir = packager.getLocalesDir(baseDir) | 329 localesDir = packager.getLocalesDir(baseDir) |
| 324 | 330 |
| 325 import buildtools.localeTools as localeTools | 331 import buildtools.localeTools as localeTools |
| 326 basename = packager.readMetadata(baseDir, type).get('general', 'basename') | |
| 327 localeTools.getTranslations(type, localesDir, packager.defaultLocale.replace('
_', '-'), basename, key) | 332 localeTools.getTranslations(type, localesDir, packager.defaultLocale.replace('
_', '-'), basename, key) |
| 328 | 333 |
| 329 | 334 |
| 330 def showDescriptions(baseDir, scriptName, opts, args, type): | 335 def showDescriptions(baseDir, scriptName, opts, args, type): |
| 331 locales = None | 336 locales = None |
| 332 for option, value in opts: | 337 for option, value in opts: |
| 333 if option in ('-l', '--locales'): | 338 if option in ('-l', '--locales'): |
| 334 locales = value.split(',') | 339 locales = value.split(',') |
| 335 | 340 |
| 336 import buildtools.packagerGecko as packager | 341 import buildtools.packagerGecko as packager |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 if option in ('-h', '--help'): | 577 if option in ('-h', '--help'): |
| 573 usage(scriptName, type, command) | 578 usage(scriptName, type, command) |
| 574 sys.exit() | 579 sys.exit() |
| 575 commands[command](baseDir, scriptName, opts, args, type) | 580 commands[command](baseDir, scriptName, opts, args, type) |
| 576 else: | 581 else: |
| 577 print 'Command %s is not supported for this application type' % command | 582 print 'Command %s is not supported for this application type' % command |
| 578 usage(scriptName, type) | 583 usage(scriptName, type) |
| 579 else: | 584 else: |
| 580 print 'Command %s is unrecognized' % command | 585 print 'Command %s is unrecognized' % command |
| 581 usage(scriptName, type) | 586 usage(scriptName, type) |
| OLD | NEW |