Left: | ||
Right: |
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 278 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 fixTranslationsForChrome(files): |
tlucas
2017/10/02 09:25:43
nit: when changing a function's name the new name
Sebastian Noack
2017/10/02 23:01:33
Done.
| |
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: |
Vasily Kuznetsov
2017/10/02 21:13:32
This loop with a regexp search and then `if match`
Sebastian Noack
2017/10/02 23:01:33
The reason why I didn't bail out, but went for the
| |
316 isLatAm, isMexican, filename = match.groups() | |
Vasily Kuznetsov
2017/10/02 21:13:32
While PEP8 is annoyingly non-specific with regards
Sebastian Noack
2017/10/02 23:01:33
Yeah, this should be lowercase with underscores. D
| |
319 | 317 |
320 data = json.loads(files[filename]) | 318 # The Chrome Web Store requires messages used in manifest.json to be |
tlucas
2017/10/02 09:25:43
nit: this line is 1 character too long
Sebastian Noack
2017/10/02 23:01:33
Done.
| |
321 for name, info in defaults.iteritems(): | 319 # present in all languages, and enforces length limits on extension |
322 data.setdefault(name, info) | 320 # 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 fixTranslationsForChrome(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 |