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-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, |
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 # GNU General Public License for more details. | 13 # GNU General Public License for more details. |
14 # | 14 # |
15 # You should have received a copy of the GNU General Public License | 15 # You should have received a copy of the GNU General Public License |
16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 |
18 import sys, os, re, json, struct | 18 import sys, os, re, json, struct |
19 from StringIO import StringIO | 19 from StringIO import StringIO |
20 | 20 |
21 import packager | 21 import packager |
22 from packager import readMetadata, getMetadataPath, getDefaultFileName, getBuild Version, getTemplate, Files | 22 from packager import readMetadata, getMetadataPath, getDefaultFileName, getBuild Version, getTemplate, Files |
23 from imageConversion import convertImages, getImageSize | |
24 | 23 |
25 defaultLocale = 'en_US' | 24 defaultLocale = 'en_US' |
26 | 25 |
27 def getIgnoredFiles(params): | 26 def getIgnoredFiles(params): |
28 result = set(('store.description',)) | 27 result = set(('store.description',)) |
29 | 28 |
30 # Hack: ignore all lib subdirectories | 29 # Hack: ignore all lib subdirectories |
31 libDir = os.path.join(params['baseDir'], 'lib') | 30 libDir = os.path.join(params['baseDir'], 'lib') |
32 for file in os.listdir(libDir): | 31 for file in os.listdir(libDir): |
33 if os.path.isdir(os.path.join(libDir, file)): | 32 if os.path.isdir(os.path.join(libDir, file)): |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
66 templateData['pageAction'] = {'icon': icon, 'popup': popup} | 65 templateData['pageAction'] = {'icon': icon, 'popup': popup} |
67 | 66 |
68 if metadata.has_option('general', 'browserAction') and metadata.get('general', 'browserAction') != '': | 67 if metadata.has_option('general', 'browserAction') and metadata.get('general', 'browserAction') != '': |
69 if re.search(r'\s+', metadata.get('general', 'browserAction')): | 68 if re.search(r'\s+', metadata.get('general', 'browserAction')): |
70 icon, popup = re.split(r'\s+', metadata.get('general', 'browserAction'), 1 ) | 69 icon, popup = re.split(r'\s+', metadata.get('general', 'browserAction'), 1 ) |
71 else: | 70 else: |
72 icon, popup = (metadata.get('general', 'browserAction'), None) | 71 icon, popup = (metadata.get('general', 'browserAction'), None) |
73 templateData['browserAction'] = {'icon': icon, 'popup': popup} | 72 templateData['browserAction'] = {'icon': icon, 'popup': popup} |
74 | 73 |
75 if metadata.has_option('general', 'icons'): | 74 if metadata.has_option('general', 'icons'): |
75 from PIL import Image | |
76 icons = {} | 76 icons = {} |
77 for icon in re.split('\s+', metadata.get('general', 'icons')): | 77 for icon in re.split('\s+', metadata.get('general', 'icons')): |
78 iconSize = getImageSize(files[icon]) | 78 width, height = Image.open(StringIO(files[icon])).size |
Wladimir Palant
2014/03/19 12:11:48
Please use destructuring assignment here, that's e
saroyanm
2014/03/19 14:54:18
Done.
| |
79 if(iconSize[0] != iconSize[1]): | 79 if(width != height): |
80 print 'Warning: %s size is %ix%i, icon should be square' % (icon, iconSi ze[0], iconSize[1]) | 80 print 'Warning: %s size is %ix%i, icon should be square' % (icon, width, height) |
Wladimir Palant
2014/03/19 21:23:06
Errors and warnings should go to stderr:
print
| |
81 icons[iconSize[0]] = icon | 81 icons[width] = icon |
82 templateData['icons'] = icons | 82 templateData['icons'] = icons |
83 | 83 |
84 if metadata.has_option('general', 'permissions'): | 84 if metadata.has_option('general', 'permissions'): |
85 templateData['permissions'] = re.split(r'\s+', metadata.get('general', 'perm issions')) | 85 templateData['permissions'] = re.split(r'\s+', metadata.get('general', 'perm issions')) |
86 if params['experimentalAPI']: | 86 if params['experimentalAPI']: |
87 templateData['permissions'].append('experimental') | 87 templateData['permissions'].append('experimental') |
88 | 88 |
89 if metadata.has_option('general', 'backgroundScripts'): | 89 if metadata.has_option('general', 'backgroundScripts'): |
90 templateData['backgroundScripts'] = re.split(r'\s+', metadata.get('general', 'backgroundScripts')) | 90 templateData['backgroundScripts'] = re.split(r'\s+', metadata.get('general', 'backgroundScripts')) |
91 if params['devenv']: | 91 if params['devenv']: |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
341 process=lambda path, data: processFile(path, data, params)) | 341 process=lambda path, data: processFile(path, data, params)) |
342 | 342 |
343 if metadata.has_section('mapping'): | 343 if metadata.has_section('mapping'): |
344 files.readMappedFiles(metadata.items('mapping')) | 344 files.readMappedFiles(metadata.items('mapping')) |
345 files.read(baseDir) | 345 files.read(baseDir) |
346 | 346 |
347 if metadata.has_section('convert_js'): | 347 if metadata.has_section('convert_js'): |
348 convertJS(params, files) | 348 convertJS(params, files) |
349 | 349 |
350 if metadata.has_section('convert_img'): | 350 if metadata.has_section('convert_img'): |
351 from imageConversion import convertImages | |
351 convertImages(params, files) | 352 convertImages(params, files) |
352 | 353 |
353 if metadata.has_section('preprocess'): | 354 if metadata.has_section('preprocess'): |
354 files.preprocess( | 355 files.preprocess( |
355 [f for f, _ in metadata.items('preprocess')], | 356 [f for f, _ in metadata.items('preprocess')], |
356 {'needsExt': True} | 357 {'needsExt': True} |
357 ) | 358 ) |
358 | 359 |
359 if metadata.has_section('import_locales'): | 360 if metadata.has_section('import_locales'): |
360 importGeckoLocales(params, files) | 361 importGeckoLocales(params, files) |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
403 def shutdown_server(server): | 404 def shutdown_server(server): |
404 time.sleep(10) | 405 time.sleep(10) |
405 server.shutdown() | 406 server.shutdown() |
406 thread.start_new_thread(shutdown_server, (server,)) | 407 thread.start_new_thread(shutdown_server, (server,)) |
407 server.serve_forever() | 408 server.serve_forever() |
408 | 409 |
409 if connections[0] == 0: | 410 if connections[0] == 0: |
410 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' |
411 else: | 412 else: |
412 print 'Handled %i connection(s)' % connections[0] | 413 print 'Handled %i connection(s)' % connections[0] |
LEFT | RIGHT |