OLD | NEW |
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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |
48 def processFile(path, data, params): | 48 def processFile(path, data, params): |
49 # We don't change anything yet, this function currently only exists here so | 49 # We don't change anything yet, this function currently only exists here so |
50 # that it can be overridden if necessary. | 50 # that it can be overridden if necessary. |
51 return data | 51 return data |
52 | 52 |
53 def createManifest(params): | 53 def createManifest(params, files): |
54 template = getTemplate('manifest.json.tmpl') | 54 template = getTemplate('manifest.json.tmpl') |
55 templateData = dict(params) | 55 templateData = dict(params) |
56 | 56 |
57 baseDir = templateData['baseDir'] | 57 baseDir = templateData['baseDir'] |
58 metadata = templateData['metadata'] | 58 metadata = templateData['metadata'] |
59 | 59 |
60 if metadata.has_option('general', 'pageAction') and metadata.get('general', 'p
ageAction') != '': | 60 if metadata.has_option('general', 'pageAction') and metadata.get('general', 'p
ageAction') != '': |
61 if re.search(r'\s+', metadata.get('general', 'pageAction')): | 61 if re.search(r'\s+', metadata.get('general', 'pageAction')): |
62 icon, popup = re.split(r'\s+', metadata.get('general', 'pageAction'), 1) | 62 icon, popup = re.split(r'\s+', metadata.get('general', 'pageAction'), 1) |
63 else: | 63 else: |
64 icon, popup = (metadata.get('general', 'pageAction'), None) | 64 icon, popup = (metadata.get('general', 'pageAction'), None) |
65 templateData['pageAction'] = {'icon': icon, 'popup': popup} | 65 templateData['pageAction'] = {'icon': icon, 'popup': popup} |
66 | 66 |
67 if metadata.has_option('general', 'browserAction') and metadata.get('general',
'browserAction') != '': | 67 if metadata.has_option('general', 'browserAction') and metadata.get('general',
'browserAction') != '': |
68 if re.search(r'\s+', metadata.get('general', 'browserAction')): | 68 if re.search(r'\s+', metadata.get('general', 'browserAction')): |
69 icon, popup = re.split(r'\s+', metadata.get('general', 'browserAction'), 1
) | 69 icon, popup = re.split(r'\s+', metadata.get('general', 'browserAction'), 1
) |
70 else: | 70 else: |
71 icon, popup = (metadata.get('general', 'browserAction'), None) | 71 icon, popup = (metadata.get('general', 'browserAction'), None) |
72 templateData['browserAction'] = {'icon': icon, 'popup': popup} | 72 templateData['browserAction'] = {'icon': icon, 'popup': popup} |
73 | 73 |
74 if metadata.has_option('general', 'icons'): | 74 if metadata.has_option('general', 'icons'): |
| 75 from PIL import Image |
75 icons = {} | 76 icons = {} |
76 iconsDir = baseDir | 77 for icon in re.split('\s+', metadata.get('general', 'icons')): |
77 for dir in metadata.get('general', 'icons').split('/')[0:-1]: | 78 width, height = Image.open(StringIO(files[icon])).size |
78 iconsDir = os.path.join(iconsDir, dir) | 79 if(width != height): |
79 | 80 print 'Warning: %s size is %ix%i, icon should be square' % (icon, width,
height) |
80 prefix, suffix = metadata.get('general', 'icons').split('/')[-1].split('?',
1) | 81 icons[width] = icon |
81 for file in os.listdir(iconsDir): | |
82 path = os.path.join(iconsDir, file) | |
83 if os.path.isfile(path) and file.startswith(prefix) and file.endswith(suff
ix): | |
84 size = file[len(prefix):-len(suffix)] | |
85 if not re.search(r'\D', size): | |
86 icons[size] = os.path.relpath(path, baseDir).replace('\\', '/') | |
87 | |
88 templateData['icons'] = icons | 82 templateData['icons'] = icons |
89 | 83 |
90 if metadata.has_option('general', 'permissions'): | 84 if metadata.has_option('general', 'permissions'): |
91 templateData['permissions'] = re.split(r'\s+', metadata.get('general', 'perm
issions')) | 85 templateData['permissions'] = re.split(r'\s+', metadata.get('general', 'perm
issions')) |
92 if params['experimentalAPI']: | 86 if params['experimentalAPI']: |
93 templateData['permissions'].append('experimental') | 87 templateData['permissions'].append('experimental') |
94 | 88 |
95 if metadata.has_option('general', 'backgroundScripts'): | 89 if metadata.has_option('general', 'backgroundScripts'): |
96 templateData['backgroundScripts'] = re.split(r'\s+', metadata.get('general',
'backgroundScripts')) | 90 templateData['backgroundScripts'] = re.split(r'\s+', metadata.get('general',
'backgroundScripts')) |
97 if params['devenv']: | 91 if params['devenv']: |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 'baseDir': baseDir, | 332 'baseDir': baseDir, |
339 'releaseBuild': releaseBuild, | 333 'releaseBuild': releaseBuild, |
340 'version': version, | 334 'version': version, |
341 'experimentalAPI': experimentalAPI, | 335 'experimentalAPI': experimentalAPI, |
342 'devenv': devenv, | 336 'devenv': devenv, |
343 'metadata': metadata, | 337 'metadata': metadata, |
344 } | 338 } |
345 | 339 |
346 files = Files(getPackageFiles(params), getIgnoredFiles(params), | 340 files = Files(getPackageFiles(params), getIgnoredFiles(params), |
347 process=lambda path, data: processFile(path, data, params)) | 341 process=lambda path, data: processFile(path, data, params)) |
348 files['manifest.json'] = createManifest(params) | 342 |
349 if metadata.has_section('mapping'): | 343 if metadata.has_section('mapping'): |
350 files.readMappedFiles(metadata.items('mapping')) | 344 files.readMappedFiles(metadata.items('mapping')) |
351 files.read(baseDir) | 345 files.read(baseDir) |
352 | 346 |
353 if metadata.has_section('convert_js'): | 347 if metadata.has_section('convert_js'): |
354 convertJS(params, files) | 348 convertJS(params, files) |
355 | 349 |
356 if metadata.has_section('convert_img'): | 350 if metadata.has_section('convert_img'): |
357 from imageConversion import convertImages | 351 from imageConversion import convertImages |
358 convertImages(params, files) | 352 convertImages(params, files) |
359 | 353 |
360 if metadata.has_section('preprocess'): | 354 if metadata.has_section('preprocess'): |
361 files.preprocess( | 355 files.preprocess( |
362 [f for f, _ in metadata.items('preprocess')], | 356 [f for f, _ in metadata.items('preprocess')], |
363 {'needsExt': True} | 357 {'needsExt': True} |
364 ) | 358 ) |
365 | 359 |
366 if metadata.has_section('import_locales'): | 360 if metadata.has_section('import_locales'): |
367 importGeckoLocales(params, files) | 361 importGeckoLocales(params, files) |
368 | 362 |
| 363 files['manifest.json'] = createManifest(params, files) |
369 fixMissingTranslations(files) | 364 fixMissingTranslations(files) |
370 | 365 |
371 if devenv: | 366 if devenv: |
372 files['devenvPoller__.js'] = createPoller(params) | 367 files['devenvPoller__.js'] = createPoller(params) |
373 | 368 |
374 if (metadata.has_option('general', 'backgroundScripts') and | 369 if (metadata.has_option('general', 'backgroundScripts') and |
375 'lib/info.js' in re.split(r'\s+', metadata.get('general', 'backgroundScrip
ts')) and | 370 'lib/info.js' in re.split(r'\s+', metadata.get('general', 'backgroundScrip
ts')) and |
376 'lib/info.js' not in files): | 371 'lib/info.js' not in files): |
377 files['lib/info.js'] = createInfoModule(params) | 372 files['lib/info.js'] = createInfoModule(params) |
378 | 373 |
(...skipping 30 matching lines...) Expand all Loading... |
409 def shutdown_server(server): | 404 def shutdown_server(server): |
410 time.sleep(10) | 405 time.sleep(10) |
411 server.shutdown() | 406 server.shutdown() |
412 thread.start_new_thread(shutdown_server, (server,)) | 407 thread.start_new_thread(shutdown_server, (server,)) |
413 server.serve_forever() | 408 server.serve_forever() |
414 | 409 |
415 if connections[0] == 0: | 410 if connections[0] == 0: |
416 print 'Warning: No incoming connections, extension probably not active in th
e browser yet' | 411 print 'Warning: No incoming connections, extension probably not active in th
e browser yet' |
417 else: | 412 else: |
418 print 'Handled %i connection(s)' % connections[0] | 413 print 'Handled %i connection(s)' % connections[0] |
OLD | NEW |