Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: packagerChrome.py

Issue 5709087064981504: Issue 1321 - Truncate extension name and description at build time instead of only truncating descr… (Closed)
Patch Set: Created Sept. 3, 2014, 6:42 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « localeTools.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # coding: utf-8 1 # coding: utf-8
2 2
3 # This file is part of the Adblock Plus build tools, 3 # This file is part of the Adblock Plus build tools,
4 # Copyright (C) 2006-2014 Eyeo GmbH 4 # Copyright (C) 2006-2014 Eyeo GmbH
5 # 5 #
6 # Adblock Plus is free software: you can redistribute it and/or modify 6 # Adblock Plus is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 3 as 7 # it under the terms of the GNU General Public License version 3 as
8 # published by the Free Software Foundation. 8 # published by the Free Software Foundation.
9 # 9 #
10 # Adblock Plus is distributed in the hope that it will be useful, 10 # Adblock Plus is distributed in the hope that it will be useful,
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 'pt': 'pt_PT', 281 'pt': 'pt_PT',
282 } 282 }
283 for chromeLocale, operaLocale in operaMapping.iteritems(): 283 for chromeLocale, operaLocale in operaMapping.iteritems():
284 chromeFile = '_locales/%s/messages.json' % chromeLocale 284 chromeFile = '_locales/%s/messages.json' % chromeLocale
285 operaFile = '_locales/%s/messages.json' % operaLocale if operaLocale != No ne else None 285 operaFile = '_locales/%s/messages.json' % operaLocale if operaLocale != No ne else None
286 if chromeFile in files: 286 if chromeFile in files:
287 if operaFile != None: 287 if operaFile != None:
288 files[operaFile] = files[chromeFile] 288 files[operaFile] = files[chromeFile]
289 del files[chromeFile] 289 del files[chromeFile]
290 290
291 def fixMissingTranslations(files): 291 def truncate(text, length_limit):
292 # Chrome requires messages used in manifest.json to be given in all languages 292 if len(text) <= length_limit:
293 return text
294 return text[:length_limit - 1].rstrip() + u"\u2026"
Sebastian Noack 2014/09/03 18:53:37 I think we should at least generate a warning when
Wladimir Palant 2014/09/03 19:05:22 I considered doing that. However, the main effect
Sebastian Noack 2014/09/03 19:13:03 Perfect. Even better would be to have proper monit
Wladimir Palant 2014/09/03 21:21:31 Not at all. It should spam you because you are the
Sebastian Noack 2014/09/04 10:40:02 So I feel this is the wrong place to address that
Wladimir Palant 2014/09/04 13:27:03 That's what you did originally. But that means tha
Sebastian Noack 2014/09/04 13:29:55 I agree, but that isn't what I meant to suggest. g
Wladimir Palant 2014/09/04 13:47:43 Take care how exactly? Do you speak Telugu? I don'
Sebastian Noack 2014/09/04 14:00:58 In the worst case one can still decide to truncate
295
296 def fixTranslationsForCWS(files):
297 # Chrome Web Store requires messages used in manifest.json to be present in
298 # all languages. It also enforces length limits for extension names and
299 # descriptions.
293 defaults = {} 300 defaults = {}
294 data = json.loads(files['_locales/%s/messages.json' % defaultLocale]) 301 data = json.loads(files['_locales/%s/messages.json' % defaultLocale])
295 for match in re.finditer(r'__MSG_(\S+)__', files['manifest.json']): 302 for match in re.finditer(r'__MSG_(\S+)__', files['manifest.json']):
296 name = match.group(1) 303 name = match.group(1)
297 defaults[name] = data[name] 304 defaults[name] = data[name]
298 305
306 limits = {}
307 manifest = json.loads(files['manifest.json'])
308 for key, limit in (('name', 45), ('description', 132), ('short_name', 12)):
309 match = re.search(r'__MSG_(\S+)__', manifest.get(key, ""))
310 if match:
311 limits[match.group(1)] = limit
312
299 for filename in files: 313 for filename in files:
300 if not filename.startswith('_locales/') or not filename.endswith('/messages. json'): 314 if not filename.startswith('_locales/') or not filename.endswith('/messages. json'):
301 continue 315 continue
302 316
303 data = json.loads(files[filename]) 317 data = json.loads(files[filename])
304 for name, info in defaults.iteritems(): 318 for name, info in defaults.iteritems():
305 data.setdefault(name, info) 319 data.setdefault(name, info)
306 320 for name, limit in limits.iteritems():
321 if name in data:
322 data[name]['message'] = truncate(data[name]['message'], limit)
307 files[filename] = toJson(data) 323 files[filename] = toJson(data)
308 324
309 def signBinary(zipdata, keyFile): 325 def signBinary(zipdata, keyFile):
310 import M2Crypto 326 import M2Crypto
311 if not os.path.exists(keyFile): 327 if not os.path.exists(keyFile):
312 M2Crypto.RSA.gen_key(1024, 65537, callback=lambda x: None).save_key(keyFile, cipher=None) 328 M2Crypto.RSA.gen_key(1024, 65537, callback=lambda x: None).save_key(keyFile, cipher=None)
313 key = M2Crypto.EVP.load_key(keyFile) 329 key = M2Crypto.EVP.load_key(keyFile)
314 key.sign_init() 330 key.sign_init()
315 key.sign_update(zipdata) 331 key.sign_update(zipdata)
316 return key.final() 332 return key.final()
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 if metadata.has_section('preprocess'): 380 if metadata.has_section('preprocess'):
365 files.preprocess( 381 files.preprocess(
366 [f for f, _ in metadata.items('preprocess')], 382 [f for f, _ in metadata.items('preprocess')],
367 {'needsExt': True} 383 {'needsExt': True}
368 ) 384 )
369 385
370 if metadata.has_section('import_locales'): 386 if metadata.has_section('import_locales'):
371 importGeckoLocales(params, files) 387 importGeckoLocales(params, files)
372 388
373 files['manifest.json'] = createManifest(params, files) 389 files['manifest.json'] = createManifest(params, files)
374 fixMissingTranslations(files) 390 if type == 'chrome':
391 fixTranslationsForCWS(files)
375 392
376 if devenv: 393 if devenv:
377 import buildtools 394 import buildtools
378 import random 395 import random
379 files.read(os.path.join(buildtools.__path__[0], 'chromeDevenvPoller__.js'), relpath='devenvPoller__.js') 396 files.read(os.path.join(buildtools.__path__[0], 'chromeDevenvPoller__.js'), relpath='devenvPoller__.js')
380 files['devenvVersion__'] = str(random.random()) 397 files['devenvVersion__'] = str(random.random())
381 398
382 if (metadata.has_option('general', 'backgroundScripts') and 399 if (metadata.has_option('general', 'backgroundScripts') and
383 'lib/info.js' in re.split(r'\s+', metadata.get('general', 'backgroundScrip ts')) and 400 'lib/info.js' in re.split(r'\s+', metadata.get('general', 'backgroundScrip ts')) and
384 'lib/info.js' not in files): 401 'lib/info.js' not in files):
385 files['lib/info.js'] = createInfoModule(params) 402 files['lib/info.js'] = createInfoModule(params)
386 403
387 zipdata = files.zipToString() 404 zipdata = files.zipToString()
388 signature = None 405 signature = None
389 pubkey = None 406 pubkey = None
390 if keyFile != None: 407 if keyFile != None:
391 signature = signBinary(zipdata, keyFile) 408 signature = signBinary(zipdata, keyFile)
392 pubkey = getPublicKey(keyFile) 409 pubkey = getPublicKey(keyFile)
393 writePackage(outFile, pubkey, signature, zipdata) 410 writePackage(outFile, pubkey, signature, zipdata)
394 411
395 def createDevEnv(baseDir, type): 412 def createDevEnv(baseDir, type):
396 fileBuffer = StringIO() 413 fileBuffer = StringIO()
397 createBuild(baseDir, type=type, outFile=fileBuffer, devenv=True, releaseBuild= True) 414 createBuild(baseDir, type=type, outFile=fileBuffer, devenv=True, releaseBuild= True)
398 415
399 from zipfile import ZipFile 416 from zipfile import ZipFile
400 zip = ZipFile(StringIO(fileBuffer.getvalue()), 'r') 417 zip = ZipFile(StringIO(fileBuffer.getvalue()), 'r')
401 zip.extractall(os.path.join(baseDir, 'devenv')) 418 zip.extractall(os.path.join(baseDir, 'devenv'))
402 zip.close() 419 zip.close()
OLDNEW
« no previous file with comments | « localeTools.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld