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

Side by Side Diff: packagerChrome.py

Issue 5732684932317184: Issue 143 - Use chrome.runtime.reload() to reload Adblock Plus in (Closed)
Patch Set: Created April 16, 2014, 10:03 a.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 | « chromeDevenvPoller__.js ('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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 121
122 # Normalize JSON structure 122 # Normalize JSON structure
123 licenseComment = re.compile(r'/\*.*?\*/', re.S) 123 licenseComment = re.compile(r'/\*.*?\*/', re.S)
124 data = json.loads(re.sub(licenseComment, '', manifest, 1)) 124 data = json.loads(re.sub(licenseComment, '', manifest, 1))
125 if '_dummy' in data: 125 if '_dummy' in data:
126 del data['_dummy'] 126 del data['_dummy']
127 manifest = json.dumps(data, sort_keys=True, indent=2) 127 manifest = json.dumps(data, sort_keys=True, indent=2)
128 128
129 return manifest.encode('utf-8') 129 return manifest.encode('utf-8')
130 130
131 def createPoller(params):
132 template = getTemplate('chromeDevenvPoller__.js.tmpl')
133 return template.render(params).encode('utf-8');
134
135 def createInfoModule(params): 131 def createInfoModule(params):
136 template = getTemplate('chromeInfo.js.tmpl') 132 template = getTemplate('chromeInfo.js.tmpl')
137 return template.render(params).encode('utf-8'); 133 return template.render(params).encode('utf-8');
138 134
139 def convertJS(params, files): 135 def convertJS(params, files):
140 from jshydra.abp_rewrite import doRewrite 136 from jshydra.abp_rewrite import doRewrite
141 137
142 for item in params['metadata'].items('convert_js'): 138 for item in params['metadata'].items('convert_js'):
143 file, sources = item 139 file, sources = item
144 baseDir = os.path.dirname(item.source) 140 baseDir = os.path.dirname(item.source)
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 'baseDir': baseDir, 338 'baseDir': baseDir,
343 'releaseBuild': releaseBuild, 339 'releaseBuild': releaseBuild,
344 'version': version, 340 'version': version,
345 'experimentalAPI': experimentalAPI, 341 'experimentalAPI': experimentalAPI,
346 'devenv': devenv, 342 'devenv': devenv,
347 'metadata': metadata, 343 'metadata': metadata,
348 } 344 }
349 345
350 files = Files(getPackageFiles(params), getIgnoredFiles(params), 346 files = Files(getPackageFiles(params), getIgnoredFiles(params),
351 process=lambda path, data: processFile(path, data, params)) 347 process=lambda path, data: processFile(path, data, params))
352 348
353 if metadata.has_section('mapping'): 349 if metadata.has_section('mapping'):
354 files.readMappedFiles(metadata.items('mapping')) 350 files.readMappedFiles(metadata.items('mapping'))
355 files.read(baseDir) 351 files.read(baseDir)
356 352
357 if metadata.has_section('convert_js'): 353 if metadata.has_section('convert_js'):
358 convertJS(params, files) 354 convertJS(params, files)
359 355
360 if metadata.has_section('convert_img'): 356 if metadata.has_section('convert_img'):
361 from imageConversion import convertImages 357 from imageConversion import convertImages
362 convertImages(params, files) 358 convertImages(params, files)
363 359
364 if metadata.has_section('preprocess'): 360 if metadata.has_section('preprocess'):
365 files.preprocess( 361 files.preprocess(
366 [f for f, _ in metadata.items('preprocess')], 362 [f for f, _ in metadata.items('preprocess')],
367 {'needsExt': True} 363 {'needsExt': True}
368 ) 364 )
369 365
370 if metadata.has_section('import_locales'): 366 if metadata.has_section('import_locales'):
371 importGeckoLocales(params, files) 367 importGeckoLocales(params, files)
372 368
373 files['manifest.json'] = createManifest(params, files) 369 files['manifest.json'] = createManifest(params, files)
374 fixMissingTranslations(files) 370 fixMissingTranslations(files)
375 371
376 if devenv: 372 if devenv:
377 files['devenvPoller__.js'] = createPoller(params) 373 import buildtools
374 import random
375 files.read(os.path.join(buildtools.__path__[0], 'chromeDevenvPoller__.js'), relpath='devenvPoller__.js')
376 files['devenvVersion__'] = str(random.random())
378 377
379 if (metadata.has_option('general', 'backgroundScripts') and 378 if (metadata.has_option('general', 'backgroundScripts') and
380 'lib/info.js' in re.split(r'\s+', metadata.get('general', 'backgroundScrip ts')) and 379 'lib/info.js' in re.split(r'\s+', metadata.get('general', 'backgroundScrip ts')) and
381 'lib/info.js' not in files): 380 'lib/info.js' not in files):
382 files['lib/info.js'] = createInfoModule(params) 381 files['lib/info.js'] = createInfoModule(params)
383 382
384 zipdata = files.zipToString() 383 zipdata = files.zipToString()
385 signature = None 384 signature = None
386 pubkey = None 385 pubkey = None
387 if keyFile != None: 386 if keyFile != None:
388 signature = signBinary(zipdata, keyFile) 387 signature = signBinary(zipdata, keyFile)
389 pubkey = getPublicKey(keyFile) 388 pubkey = getPublicKey(keyFile)
390 writePackage(outFile, pubkey, signature, zipdata) 389 writePackage(outFile, pubkey, signature, zipdata)
391 390
392 def createDevEnv(baseDir, type): 391 def createDevEnv(baseDir, type):
393 fileBuffer = StringIO() 392 fileBuffer = StringIO()
394 createBuild(baseDir, type=type, outFile=fileBuffer, devenv=True, releaseBuild= True) 393 createBuild(baseDir, type=type, outFile=fileBuffer, devenv=True, releaseBuild= True)
395 394
396 from zipfile import ZipFile 395 from zipfile import ZipFile
397 zip = ZipFile(StringIO(fileBuffer.getvalue()), 'r') 396 zip = ZipFile(StringIO(fileBuffer.getvalue()), 'r')
398 zip.extractall(os.path.join(baseDir, 'devenv')) 397 zip.extractall(os.path.join(baseDir, 'devenv'))
399 zip.close() 398 zip.close()
400
401 print 'Development environment created, waiting for connections from active ex tensions...'
402 metadata = readMetadata(baseDir, type)
403 connections = [0]
404
405 import SocketServer, time, thread
406
407 class ConnectionHandler(SocketServer.BaseRequestHandler):
408 def handle(self):
409 connections[0] += 1
410 self.request.sendall('HTTP/1.0 OK\nConnection: close\n\n%s' % metadata.get ('general', 'basename'))
411
412 server = SocketServer.TCPServer(('localhost', 43816), ConnectionHandler)
413
414 def shutdown_server(server):
415 time.sleep(10)
416 server.shutdown()
417 thread.start_new_thread(shutdown_server, (server,))
418 server.serve_forever()
419
420 if connections[0] == 0:
421 print 'Warning: No incoming connections, extension probably not active in th e browser yet'
422 else:
423 print 'Handled %i connection(s)' % connections[0]
OLDNEW
« no previous file with comments | « chromeDevenvPoller__.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld