Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
152 except ValueError: | 152 except ValueError: |
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 | |
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 | 162 |
180 def importGeckoLocales(params, files): | 163 def importGeckoLocales(params, files): |
181 import localeTools | 164 import localeTools |
182 | 165 |
183 localeCodeMapping = { | 166 localeCodeMapping = { |
184 'ar': 'ar', | 167 'ar': 'ar', |
185 'bg': 'bg', | 168 'bg': 'bg', |
186 'ca': 'ca', | 169 'ca': 'ca', |
187 'cs': 'cs', | 170 'cs': 'cs', |
188 'da': 'da', | 171 'da': 'da', |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
289 'pt': 'pt_PT', | 272 'pt': 'pt_PT', |
290 } | 273 } |
291 for chromeLocale, operaLocale in operaMapping.iteritems(): | 274 for chromeLocale, operaLocale in operaMapping.iteritems(): |
292 chromeFile = '_locales/%s/messages.json' % chromeLocale | 275 chromeFile = '_locales/%s/messages.json' % chromeLocale |
293 operaFile = '_locales/%s/messages.json' % operaLocale if operaLocale != No ne else None | 276 operaFile = '_locales/%s/messages.json' % operaLocale if operaLocale != No ne else None |
294 if chromeFile in files: | 277 if chromeFile in files: |
295 if operaFile != None: | 278 if operaFile != None: |
296 files[operaFile] = files[chromeFile] | 279 files[operaFile] = files[chromeFile] |
297 del files[chromeFile] | 280 del files[chromeFile] |
298 | 281 |
299 if params['type'] in ('opera', 'safari'): | |
300 # Hack: Replace "Chrome" by "Opera" or "Safari" in the locales | |
301 for path, data in files.iteritems(): | |
302 if path.startswith("_locales/") and path.endswith("/messages.json"): | |
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
| |
307 | |
308 def signBinary(zipdata, keyFile): | 282 def signBinary(zipdata, keyFile): |
309 import M2Crypto | 283 import M2Crypto |
310 if not os.path.exists(keyFile): | 284 if not os.path.exists(keyFile): |
311 M2Crypto.RSA.gen_key(1024, 65537, callback=lambda x: None).save_key(keyFile, cipher=None) | 285 M2Crypto.RSA.gen_key(1024, 65537, callback=lambda x: None).save_key(keyFile, cipher=None) |
312 key = M2Crypto.EVP.load_key(keyFile) | 286 key = M2Crypto.EVP.load_key(keyFile) |
313 key.sign_init() | 287 key.sign_init() |
314 key.sign_update(zipdata) | 288 key.sign_update(zipdata) |
315 return key.final() | 289 return key.final() |
316 | 290 |
317 def getPublicKey(keyFile): | 291 def getPublicKey(keyFile): |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
353 files.readMappedFiles(metadata.items('mapping')) | 327 files.readMappedFiles(metadata.items('mapping')) |
354 files.read(baseDir) | 328 files.read(baseDir) |
355 | 329 |
356 if metadata.has_section('convert_js'): | 330 if metadata.has_section('convert_js'): |
357 convertJS(params, files) | 331 convertJS(params, files) |
358 | 332 |
359 if metadata.has_section('convert_img'): | 333 if metadata.has_section('convert_img'): |
360 from imageConversion import convertImages | 334 from imageConversion import convertImages |
361 convertImages(params, files) | 335 convertImages(params, files) |
362 | 336 |
363 if 'firstRun.html' in files: | 337 if metadata.has_section('preprocess'): |
364 convertFirstRunPage(params, files) | 338 files.preprocess( |
339 [f for f, _ in metadata.items('preprocess')], | |
340 {'needsExt': True} | |
341 ) | |
365 | 342 |
366 if metadata.has_section('import_locales'): | 343 if metadata.has_section('import_locales'): |
367 importGeckoLocales(params, files) | 344 importGeckoLocales(params, files) |
368 | 345 |
369 if devenv: | 346 if devenv: |
370 files['devenvPoller__.js'] = createPoller(params) | 347 files['devenvPoller__.js'] = createPoller(params) |
371 | 348 |
372 if (metadata.has_option('general', 'backgroundScripts') and | 349 if (metadata.has_option('general', 'backgroundScripts') and |
373 'lib/info.js' in re.split(r'\s+', metadata.get('general', 'backgroundScrip ts')) and | 350 'lib/info.js' in re.split(r'\s+', metadata.get('general', 'backgroundScrip ts')) and |
374 'lib/info.js' not in files): | 351 'lib/info.js' not in files): |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
407 def shutdown_server(server): | 384 def shutdown_server(server): |
408 time.sleep(10) | 385 time.sleep(10) |
409 server.shutdown() | 386 server.shutdown() |
410 thread.start_new_thread(shutdown_server, (server,)) | 387 thread.start_new_thread(shutdown_server, (server,)) |
411 server.serve_forever() | 388 server.serve_forever() |
412 | 389 |
413 if connections[0] == 0: | 390 if connections[0] == 0: |
414 print 'Warning: No incoming connections, extension probably not active in th e browser yet' | 391 print 'Warning: No incoming connections, extension probably not active in th e browser yet' |
415 else: | 392 else: |
416 print 'Handled %i connection(s)' % connections[0] | 393 print 'Handled %i connection(s)' % connections[0] |
LEFT | RIGHT |