| OLD | NEW |
| 1 # This Source Code Form is subject to the terms of the Mozilla Public | 1 # This Source Code Form is subject to the terms of the Mozilla Public |
| 2 # License, v. 2.0. If a copy of the MPL was not distributed with this | 2 # License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. | 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 4 | 4 |
| 5 import errno | 5 import errno |
| 6 import io | 6 import io |
| 7 import json | 7 import json |
| 8 import os | 8 import os |
| 9 import re | 9 import re |
| 10 from StringIO import StringIO | 10 from StringIO import StringIO |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 | 217 |
| 218 # FIXME: localeTools doesn't use real Chrome locales, it uses dash as | 218 # FIXME: localeTools doesn't use real Chrome locales, it uses dash as |
| 219 # separator instead. | 219 # separator instead. |
| 220 convert_locale_code = lambda code: code.replace('-', '_') | 220 convert_locale_code = lambda code: code.replace('-', '_') |
| 221 | 221 |
| 222 # We need to map Chrome locales to Gecko locales. Start by mapping Chrome | 222 # We need to map Chrome locales to Gecko locales. Start by mapping Chrome |
| 223 # locales to themselves, merely with the dash as separator. | 223 # locales to themselves, merely with the dash as separator. |
| 224 locale_mapping = {convert_locale_code(l): l for l in localeTools.chromeLocal
es} | 224 locale_mapping = {convert_locale_code(l): l for l in localeTools.chromeLocal
es} |
| 225 | 225 |
| 226 # Convert values to Crowdin locales first (use Chrome => Crowdin mapping). | 226 # Convert values to Crowdin locales first (use Chrome => Crowdin mapping). |
| 227 for chrome_locale, crowdin_locale in localeTools.langMappingChrome.iteritems
(): | 227 for chrome_locale, crowdin_locale in localeTools.CROWDIN_LANG_MAPPING.iterit
ems(): |
| 228 locale_mapping[convert_locale_code(chrome_locale)] = crowdin_locale | 228 locale_mapping[convert_locale_code(chrome_locale)] = crowdin_locale |
| 229 | 229 |
| 230 # Now convert values to Gecko locales (use Gecko => Crowdin mapping). | 230 # Now convert values to Gecko locales (use Gecko => Crowdin mapping). |
| 231 reverse_mapping = {v: k for k, v in locale_mapping.iteritems()} | 231 reverse_mapping = {v: k for k, v in locale_mapping.iteritems()} |
| 232 for gecko_locale, crowdin_locale in localeTools.langMappingGecko.iteritems()
: | 232 for gecko_locale, crowdin_locale in localeTools.CROWDIN_LANG_MAPPING.iterite
ms(): |
| 233 if crowdin_locale in reverse_mapping: | 233 if crowdin_locale in reverse_mapping: |
| 234 locale_mapping[reverse_mapping[crowdin_locale]] = gecko_locale | 234 locale_mapping[reverse_mapping[crowdin_locale]] = gecko_locale |
| 235 | 235 |
| 236 for target, source in locale_mapping.iteritems(): | 236 for target, source in locale_mapping.iteritems(): |
| 237 targetFile = '_locales/%s/messages.json' % target | 237 targetFile = '_locales/%s/messages.json' % target |
| 238 if not targetFile in files: | 238 if not targetFile in files: |
| 239 continue | 239 continue |
| 240 | 240 |
| 241 for item in params['metadata'].items('import_locales'): | 241 for item in params['metadata'].items('import_locales'): |
| 242 fileName, keys = item | 242 fileName, keys = item |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 | 289 |
| 290 files[targetFile] = toJson(data) | 290 files[targetFile] = toJson(data) |
| 291 | 291 |
| 292 | 292 |
| 293 def truncate(text, length_limit): | 293 def truncate(text, length_limit): |
| 294 if len(text) <= length_limit: | 294 if len(text) <= length_limit: |
| 295 return text | 295 return text |
| 296 return text[:length_limit - 1].rstrip() + u'\u2026' | 296 return text[:length_limit - 1].rstrip() + u'\u2026' |
| 297 | 297 |
| 298 | 298 |
| 299 def fixTranslationsForCWS(files): | 299 def fix_translations_for_chrome(files): |
| 300 # Chrome Web Store requires messages used in manifest.json to be present in | |
| 301 # all languages. It also enforces length limits for extension names and | |
| 302 # descriptions. | |
| 303 defaults = {} | 300 defaults = {} |
| 304 data = json.loads(files['_locales/%s/messages.json' % defaultLocale]) | 301 data = json.loads(files['_locales/%s/messages.json' % defaultLocale]) |
| 305 for match in re.finditer(r'__MSG_(\S+)__', files['manifest.json']): | 302 for match in re.finditer(r'__MSG_(\S+)__', files['manifest.json']): |
| 306 name = match.group(1) | 303 name = match.group(1) |
| 307 defaults[name] = data[name] | 304 defaults[name] = data[name] |
| 308 | 305 |
| 309 limits = {} | 306 limits = {} |
| 310 manifest = json.loads(files['manifest.json']) | 307 manifest = json.loads(files['manifest.json']) |
| 311 for key, limit in (('name', 45), ('description', 132), ('short_name', 12)): | 308 for key, limit in (('name', 45), ('description', 132), ('short_name', 12)): |
| 312 match = re.search(r'__MSG_(\S+)__', manifest.get(key, '')) | 309 match = re.search(r'__MSG_(\S+)__', manifest.get(key, '')) |
| 313 if match: | 310 if match: |
| 314 limits[match.group(1)] = limit | 311 limits[match.group(1)] = limit |
| 315 | 312 |
| 316 for filename in files: | 313 for path in list(files): |
| 317 if not filename.startswith('_locales/') or not filename.endswith('/messa
ges.json'): | 314 match = re.search(r'^_locales/(?:es_(AR|CL|(MX))|[^/]+)/(.*)', path) |
| 315 if not match: |
| 318 continue | 316 continue |
| 319 | 317 |
| 320 data = json.loads(files[filename]) | 318 # The Chrome Web Store requires messages used in manifest.json to |
| 321 for name, info in defaults.iteritems(): | 319 # be present in all languages, and enforces length limits on |
| 322 data.setdefault(name, info) | 320 # extension name and description. |
| 323 for name, limit in limits.iteritems(): | 321 is_latam, is_mexican, filename = match.groups() |
| 324 if name in data: | 322 if filename == 'messages.json': |
| 325 data[name]['message'] = truncate(data[name]['message'], limit) | 323 data = json.loads(files[path]) |
| 326 files[filename] = toJson(data) | 324 for name, info in defaults.iteritems(): |
| 325 data.setdefault(name, info) |
| 326 for name, limit in limits.iteritems(): |
| 327 info = data.get(name) |
| 328 if info: |
| 329 info['message'] = truncate(info['message'], limit) |
| 330 files[path] = toJson(data) |
| 331 |
| 332 # Chrome combines Latin American dialects of Spanish into es-419. |
| 333 if is_latam: |
| 334 data = files.pop(path) |
| 335 if is_mexican: |
| 336 files['_locales/es_419/' + filename] = data |
| 327 | 337 |
| 328 | 338 |
| 329 def signBinary(zipdata, keyFile): | 339 def signBinary(zipdata, keyFile): |
| 330 from Crypto.Hash import SHA | 340 from Crypto.Hash import SHA |
| 331 from Crypto.PublicKey import RSA | 341 from Crypto.PublicKey import RSA |
| 332 from Crypto.Signature import PKCS1_v1_5 | 342 from Crypto.Signature import PKCS1_v1_5 |
| 333 | 343 |
| 334 try: | 344 try: |
| 335 with open(keyFile, 'rb') as file: | 345 with open(keyFile, 'rb') as file: |
| 336 key = RSA.importKey(file.read()) | 346 key = RSA.importKey(file.read()) |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 files.preprocess( | 406 files.preprocess( |
| 397 [f for f, _ in metadata.items('preprocess')], | 407 [f for f, _ in metadata.items('preprocess')], |
| 398 {'needsExt': True} | 408 {'needsExt': True} |
| 399 ) | 409 ) |
| 400 | 410 |
| 401 if metadata.has_section('import_locales'): | 411 if metadata.has_section('import_locales'): |
| 402 import_locales(params, files) | 412 import_locales(params, files) |
| 403 | 413 |
| 404 files['manifest.json'] = createManifest(params, files) | 414 files['manifest.json'] = createManifest(params, files) |
| 405 if type == 'chrome': | 415 if type == 'chrome': |
| 406 fixTranslationsForCWS(files) | 416 fix_translations_for_chrome(files) |
| 407 | 417 |
| 408 if devenv: | 418 if devenv: |
| 409 import buildtools | 419 import buildtools |
| 410 import random | 420 import random |
| 411 files.read(os.path.join(buildtools.__path__[0], 'chromeDevenvPoller__.js
'), relpath='devenvPoller__.js') | 421 files.read(os.path.join(buildtools.__path__[0], 'chromeDevenvPoller__.js
'), relpath='devenvPoller__.js') |
| 412 files['devenvVersion__'] = str(random.random()) | 422 files['devenvVersion__'] = str(random.random()) |
| 413 | 423 |
| 414 if metadata.has_option('general', 'testScripts'): | 424 if metadata.has_option('general', 'testScripts'): |
| 415 files['qunit/index.html'] = createScriptPage( | 425 files['qunit/index.html'] = createScriptPage( |
| 416 params, 'testIndex.html.tmpl', ('general', 'testScripts') | 426 params, 'testIndex.html.tmpl', ('general', 'testScripts') |
| 417 ) | 427 ) |
| 418 | 428 |
| 419 zipdata = files.zipToString() | 429 zipdata = files.zipToString() |
| 420 signature = None | 430 signature = None |
| 421 pubkey = None | 431 pubkey = None |
| 422 if keyFile != None: | 432 if keyFile != None: |
| 423 signature = signBinary(zipdata, keyFile) | 433 signature = signBinary(zipdata, keyFile) |
| 424 pubkey = getPublicKey(keyFile) | 434 pubkey = getPublicKey(keyFile) |
| 425 writePackage(outFile, pubkey, signature, zipdata) | 435 writePackage(outFile, pubkey, signature, zipdata) |
| OLD | NEW |