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) |
318 continue | 315 if match: |
| 316 isLatAm, isMexican, filename = match.groups() |
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 if filename == 'messages.json': |
324 if name in data: | 322 data = json.loads(files[path]) |
325 data[name]['message'] = truncate(data[name]['message'], limit) | 323 for name, info in defaults.iteritems(): |
326 files[filename] = toJson(data) | 324 data.setdefault(name, info) |
| 325 for name, limit in limits.iteritems(): |
| 326 info = data.get(name) |
| 327 if info: |
| 328 info['message'] = truncate(info['message'], limit) |
| 329 files[path] = toJson(data) |
| 330 |
| 331 # Chrome combines Latin American dialects of Spanish into es-419. |
| 332 if isLatAm: |
| 333 data = files.pop(path) |
| 334 if isMexican: |
| 335 files['_locales/es_419/' + filename] = data |
327 | 336 |
328 | 337 |
329 def signBinary(zipdata, keyFile): | 338 def signBinary(zipdata, keyFile): |
330 from Crypto.Hash import SHA | 339 from Crypto.Hash import SHA |
331 from Crypto.PublicKey import RSA | 340 from Crypto.PublicKey import RSA |
332 from Crypto.Signature import PKCS1_v1_5 | 341 from Crypto.Signature import PKCS1_v1_5 |
333 | 342 |
334 try: | 343 try: |
335 with open(keyFile, 'rb') as file: | 344 with open(keyFile, 'rb') as file: |
336 key = RSA.importKey(file.read()) | 345 key = RSA.importKey(file.read()) |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 files.preprocess( | 405 files.preprocess( |
397 [f for f, _ in metadata.items('preprocess')], | 406 [f for f, _ in metadata.items('preprocess')], |
398 {'needsExt': True} | 407 {'needsExt': True} |
399 ) | 408 ) |
400 | 409 |
401 if metadata.has_section('import_locales'): | 410 if metadata.has_section('import_locales'): |
402 import_locales(params, files) | 411 import_locales(params, files) |
403 | 412 |
404 files['manifest.json'] = createManifest(params, files) | 413 files['manifest.json'] = createManifest(params, files) |
405 if type == 'chrome': | 414 if type == 'chrome': |
406 fixTranslationsForCWS(files) | 415 fix_translations_for_chrome(files) |
407 | 416 |
408 if devenv: | 417 if devenv: |
409 import buildtools | 418 import buildtools |
410 import random | 419 import random |
411 files.read(os.path.join(buildtools.__path__[0], 'chromeDevenvPoller__.js
'), relpath='devenvPoller__.js') | 420 files.read(os.path.join(buildtools.__path__[0], 'chromeDevenvPoller__.js
'), relpath='devenvPoller__.js') |
412 files['devenvVersion__'] = str(random.random()) | 421 files['devenvVersion__'] = str(random.random()) |
413 | 422 |
414 if metadata.has_option('general', 'testScripts'): | 423 if metadata.has_option('general', 'testScripts'): |
415 files['qunit/index.html'] = createScriptPage( | 424 files['qunit/index.html'] = createScriptPage( |
416 params, 'testIndex.html.tmpl', ('general', 'testScripts') | 425 params, 'testIndex.html.tmpl', ('general', 'testScripts') |
417 ) | 426 ) |
418 | 427 |
419 zipdata = files.zipToString() | 428 zipdata = files.zipToString() |
420 signature = None | 429 signature = None |
421 pubkey = None | 430 pubkey = None |
422 if keyFile != None: | 431 if keyFile != None: |
423 signature = signBinary(zipdata, keyFile) | 432 signature = signBinary(zipdata, keyFile) |
424 pubkey = getPublicKey(keyFile) | 433 pubkey = getPublicKey(keyFile) |
425 writePackage(outFile, pubkey, signature, zipdata) | 434 writePackage(outFile, pubkey, signature, zipdata) |
OLD | NEW |