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

Side by Side Diff: packagerChrome.py

Issue 11544056: Prepared buildtools for Safari (Closed)
Patch Set: Made "Chrome" be not replaced with "Safari" in the warning on the first run page Created Oct. 25, 2013, 4:55 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
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-2013 Eyeo GmbH 4 # Copyright (C) 2006-2013 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 16 matching lines...) Expand all
27 result = set(('store.description',)) 27 result = set(('store.description',))
28 28
29 # Hack: ignore all lib subdirectories 29 # Hack: ignore all lib subdirectories
30 libDir = os.path.join(params['baseDir'], 'lib') 30 libDir = os.path.join(params['baseDir'], 'lib')
31 for file in os.listdir(libDir): 31 for file in os.listdir(libDir):
32 if os.path.isdir(os.path.join(libDir, file)): 32 if os.path.isdir(os.path.join(libDir, file)):
33 result.add(file) 33 result.add(file)
34 return result 34 return result
35 35
36 def getPackageFiles(params): 36 def getPackageFiles(params):
37 result = set(('_locales', 'icons', 'jquery-ui', 'lib', 'skin', 'ui',)) 37 result = set(('_locales', 'icons', 'jquery-ui', 'lib', 'skin', 'ui', 'ext'))
38 38
39 if params['devenv']: 39 if params['devenv']:
40 result.add('qunit') 40 result.add('qunit')
41 41
42 baseDir = params['baseDir'] 42 baseDir = params['baseDir']
43 for file in os.listdir(baseDir): 43 for file in os.listdir(baseDir):
44 if file.endswith('.js') or file.endswith('.html') or file.endswith('.xml'): 44 if file.endswith('.js') or file.endswith('.html') or file.endswith('.xml'):
45 result.add(file) 45 result.add(file)
46 return result 46 return result
47 47
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 pass 153 pass
154 154
155 # Source files of the conversion shouldn't be part of the build 155 # Source files of the conversion shouldn't be part of the build
156 for sourceFile in sourceFiles: 156 for sourceFile in sourceFiles:
157 if sourceFile in files: 157 if sourceFile in files:
158 del files[sourceFile] 158 del files[sourceFile]
159 159
160 sourceFiles = map(lambda f: os.path.abspath(os.path.join(baseDir, f)), sourc eFiles) 160 sourceFiles = map(lambda f: os.path.abspath(os.path.join(baseDir, f)), sourc eFiles)
161 files[file] = doRewrite(sourceFiles, args) 161 files[file] = doRewrite(sourceFiles, args)
162 162
163 def convertFirstRunPage(params, files):
164 import jinja2
165
166 env = jinja2.Environment(
167 block_start_string='<!-- {%',
168 block_end_string='%} -->',
169 variable_start_string='<!-- {{',
170 variable_end_string='}} -->',
171 comment_start_string='<-- {#',
172 comment_end_string='#} -->',
173
174 trim_blocks=True,
175 lstrip_blocks=True
176 )
177
178 files['firstRun.html'] = env.from_string(files['firstRun.html']).render(type=p arams['type'])
Wladimir Palant 2013/10/30 13:36:01 Hardcoding the file here that needs to be passed t
179
163 def importGeckoLocales(params, files): 180 def importGeckoLocales(params, files):
164 import localeTools 181 import localeTools
165 182
166 localeCodeMapping = { 183 localeCodeMapping = {
167 'ar': 'ar', 184 'ar': 'ar',
168 'bg': 'bg', 185 'bg': 'bg',
169 'ca': 'ca', 186 'ca': 'ca',
170 'cs': 'cs', 187 'cs': 'cs',
171 'da': 'da', 188 'da': 'da',
172 'de': 'de', 189 'de': 'de',
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 'pt': 'pt_PT', 289 'pt': 'pt_PT',
273 } 290 }
274 for chromeLocale, operaLocale in operaMapping.iteritems(): 291 for chromeLocale, operaLocale in operaMapping.iteritems():
275 chromeFile = '_locales/%s/messages.json' % chromeLocale 292 chromeFile = '_locales/%s/messages.json' % chromeLocale
276 operaFile = '_locales/%s/messages.json' % operaLocale if operaLocale != No ne else None 293 operaFile = '_locales/%s/messages.json' % operaLocale if operaLocale != No ne else None
277 if chromeFile in files: 294 if chromeFile in files:
278 if operaFile != None: 295 if operaFile != None:
279 files[operaFile] = files[chromeFile] 296 files[operaFile] = files[chromeFile]
280 del files[chromeFile] 297 del files[chromeFile]
281 298
282 # Hack: Replace "Chrome" by "Opera" in the locales 299 if params['type'] in ('opera', 'safari'):
300 # Hack: Replace "Chrome" by "Opera" or "Safari" in the locales
283 for path, data in files.iteritems(): 301 for path, data in files.iteritems():
284 if path.startswith("_locales/") and path.endswith("/messages.json"): 302 if path.startswith("_locales/") and path.endswith("/messages.json"):
285 files[path] = re.sub(r"\bChrome\b", "Opera", data) 303 # Hack: There is exactly one text (in the first run page) that contains
304 # "Google Chrome" and means Google Chrome, even though it is only shown
305 # on Safari.
306 files[path] = re.sub(r"\b(?<!Google )Chrome\b", params['type'].capitaliz e(), data)
Wladimir Palant 2013/10/30 13:36:01 Ouch, we should really get rid of this hack... How
Sebastian Noack 2013/10/30 16:12:10 I don't like that hack too, and would like to see
Wladimir Palant 2013/10/30 16:21:38 Actually, given that you made the hack likely to e
286 307
287 def signBinary(zipdata, keyFile): 308 def signBinary(zipdata, keyFile):
288 import M2Crypto 309 import M2Crypto
289 if not os.path.exists(keyFile): 310 if not os.path.exists(keyFile):
290 M2Crypto.RSA.gen_key(1024, 65537, callback=lambda x: None).save_key(keyFile, cipher=None) 311 M2Crypto.RSA.gen_key(1024, 65537, callback=lambda x: None).save_key(keyFile, cipher=None)
291 key = M2Crypto.EVP.load_key(keyFile) 312 key = M2Crypto.EVP.load_key(keyFile)
292 key.sign_init() 313 key.sign_init()
293 key.sign_update(zipdata) 314 key.sign_update(zipdata)
294 return key.final() 315 return key.final()
295 316
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 files = Files(getPackageFiles(params), getIgnoredFiles(params), 349 files = Files(getPackageFiles(params), getIgnoredFiles(params),
329 process=lambda path, data: processFile(path, data, params)) 350 process=lambda path, data: processFile(path, data, params))
330 files['manifest.json'] = createManifest(params) 351 files['manifest.json'] = createManifest(params)
331 if metadata.has_section('mapping'): 352 if metadata.has_section('mapping'):
332 files.readMappedFiles(metadata.items('mapping')) 353 files.readMappedFiles(metadata.items('mapping'))
333 files.read(baseDir) 354 files.read(baseDir)
334 355
335 if metadata.has_section('convert_js'): 356 if metadata.has_section('convert_js'):
336 convertJS(params, files) 357 convertJS(params, files)
337 358
359 if metadata.has_section('convert_img'):
360 from imageConversion import convertImages
361 convertImages(params, files)
362
363 if 'firstRun.html' in files:
364 convertFirstRunPage(params, files)
365
338 if metadata.has_section('import_locales'): 366 if metadata.has_section('import_locales'):
339 importGeckoLocales(params, files) 367 importGeckoLocales(params, files)
340 368
341 if devenv: 369 if devenv:
342 files['devenvPoller__.js'] = createPoller(params) 370 files['devenvPoller__.js'] = createPoller(params)
343 371
344 if (metadata.has_option('general', 'backgroundScripts') and 372 if (metadata.has_option('general', 'backgroundScripts') and
345 'lib/info.js' in re.split(r'\s+', metadata.get('general', 'backgroundScrip ts')) and 373 'lib/info.js' in re.split(r'\s+', metadata.get('general', 'backgroundScrip ts')) and
346 'lib/info.js' not in files): 374 'lib/info.js' not in files):
347 files['lib/info.js'] = createInfoModule(params) 375 files['lib/info.js'] = createInfoModule(params)
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 def shutdown_server(server): 407 def shutdown_server(server):
380 time.sleep(10) 408 time.sleep(10)
381 server.shutdown() 409 server.shutdown()
382 thread.start_new_thread(shutdown_server, (server,)) 410 thread.start_new_thread(shutdown_server, (server,))
383 server.serve_forever() 411 server.serve_forever()
384 412
385 if connections[0] == 0: 413 if connections[0] == 0:
386 print 'Warning: No incoming connections, extension probably not active in th e browser yet' 414 print 'Warning: No incoming connections, extension probably not active in th e browser yet'
387 else: 415 else:
388 print 'Handled %i connection(s)' % connections[0] 416 print 'Handled %i connection(s)' % connections[0]
OLDNEW

Powered by Google App Engine
This is Rietveld