| Left: | ||
| Right: |
| 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, |
| 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 | |
| 23 | 24 |
| 24 defaultLocale = 'en_US' | 25 defaultLocale = 'en_US' |
| 25 | 26 |
| 26 def getIgnoredFiles(params): | 27 def getIgnoredFiles(params): |
| 27 result = set(('store.description',)) | 28 result = set(('store.description',)) |
| 28 | 29 |
| 29 # Hack: ignore all lib subdirectories | 30 # Hack: ignore all lib subdirectories |
| 30 libDir = os.path.join(params['baseDir'], 'lib') | 31 libDir = os.path.join(params['baseDir'], 'lib') |
| 31 for file in os.listdir(libDir): | 32 for file in os.listdir(libDir): |
| 32 if os.path.isdir(os.path.join(libDir, file)): | 33 if os.path.isdir(os.path.join(libDir, file)): |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 43 for file in os.listdir(baseDir): | 44 for file in os.listdir(baseDir): |
| 44 if file.endswith('.js') or file.endswith('.html') or file.endswith('.xml'): | 45 if file.endswith('.js') or file.endswith('.html') or file.endswith('.xml'): |
| 45 result.add(file) | 46 result.add(file) |
| 46 return result | 47 return result |
| 47 | 48 |
| 48 def processFile(path, data, params): | 49 def processFile(path, data, params): |
| 49 # We don't change anything yet, this function currently only exists here so | 50 # We don't change anything yet, this function currently only exists here so |
| 50 # that it can be overridden if necessary. | 51 # that it can be overridden if necessary. |
| 51 return data | 52 return data |
| 52 | 53 |
| 53 def createManifest(params): | 54 def createManifest(params, files): |
| 54 template = getTemplate('manifest.json.tmpl') | 55 template = getTemplate('manifest.json.tmpl') |
| 55 templateData = dict(params) | 56 templateData = dict(params) |
| 56 | 57 |
| 57 baseDir = templateData['baseDir'] | 58 baseDir = templateData['baseDir'] |
| 58 metadata = templateData['metadata'] | 59 metadata = templateData['metadata'] |
| 59 | 60 |
| 60 if metadata.has_option('general', 'pageAction') and metadata.get('general', 'p ageAction') != '': | 61 if metadata.has_option('general', 'pageAction') and metadata.get('general', 'p ageAction') != '': |
| 61 if re.search(r'\s+', metadata.get('general', 'pageAction')): | 62 if re.search(r'\s+', metadata.get('general', 'pageAction')): |
| 62 icon, popup = re.split(r'\s+', metadata.get('general', 'pageAction'), 1) | 63 icon, popup = re.split(r'\s+', metadata.get('general', 'pageAction'), 1) |
| 63 else: | 64 else: |
| 64 icon, popup = (metadata.get('general', 'pageAction'), None) | 65 icon, popup = (metadata.get('general', 'pageAction'), None) |
| 65 templateData['pageAction'] = {'icon': icon, 'popup': popup} | 66 templateData['pageAction'] = {'icon': icon, 'popup': popup} |
| 66 | 67 |
| 67 if metadata.has_option('general', 'browserAction') and metadata.get('general', 'browserAction') != '': | 68 if metadata.has_option('general', 'browserAction') and metadata.get('general', 'browserAction') != '': |
| 68 if re.search(r'\s+', metadata.get('general', 'browserAction')): | 69 if re.search(r'\s+', metadata.get('general', 'browserAction')): |
| 69 icon, popup = re.split(r'\s+', metadata.get('general', 'browserAction'), 1 ) | 70 icon, popup = re.split(r'\s+', metadata.get('general', 'browserAction'), 1 ) |
| 70 else: | 71 else: |
| 71 icon, popup = (metadata.get('general', 'browserAction'), None) | 72 icon, popup = (metadata.get('general', 'browserAction'), None) |
| 72 templateData['browserAction'] = {'icon': icon, 'popup': popup} | 73 templateData['browserAction'] = {'icon': icon, 'popup': popup} |
| 73 | 74 |
| 74 if metadata.has_option('general', 'icons'): | 75 if metadata.has_option('general', 'icons'): |
| 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 iconSize = getImageSize(files[icon]) |
|
Wladimir Palant
2014/03/19 12:11:48
Please use destructuring assignment here, that's e
saroyanm
2014/03/19 14:54:18
Done.
| |
| 78 iconsDir = os.path.join(iconsDir, dir) | 79 if(iconSize[0] != iconSize[1]): |
| 79 | 80 print 'Warning: %s size is %ix%i, icon should be square' % (icon, iconSi ze[0], iconSize[1]) |
| 80 prefix, suffix = metadata.get('general', 'icons').split('/')[-1].split('?', 1) | 81 icons[iconSize[0]] = 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 | |
| 358 convertImages(params, files) | 351 convertImages(params, files) |
| 359 | 352 |
| 360 if metadata.has_section('preprocess'): | 353 if metadata.has_section('preprocess'): |
| 361 files.preprocess( | 354 files.preprocess( |
| 362 [f for f, _ in metadata.items('preprocess')], | 355 [f for f, _ in metadata.items('preprocess')], |
| 363 {'needsExt': True} | 356 {'needsExt': True} |
| 364 ) | 357 ) |
| 365 | 358 |
| 366 if metadata.has_section('import_locales'): | 359 if metadata.has_section('import_locales'): |
| 367 importGeckoLocales(params, files) | 360 importGeckoLocales(params, files) |
| 368 | 361 |
| 362 files['manifest.json'] = createManifest(params, files) | |
| 369 fixMissingTranslations(files) | 363 fixMissingTranslations(files) |
| 370 | 364 |
| 371 if devenv: | 365 if devenv: |
| 372 files['devenvPoller__.js'] = createPoller(params) | 366 files['devenvPoller__.js'] = createPoller(params) |
| 373 | 367 |
| 374 if (metadata.has_option('general', 'backgroundScripts') and | 368 if (metadata.has_option('general', 'backgroundScripts') and |
| 375 'lib/info.js' in re.split(r'\s+', metadata.get('general', 'backgroundScrip ts')) and | 369 'lib/info.js' in re.split(r'\s+', metadata.get('general', 'backgroundScrip ts')) and |
| 376 'lib/info.js' not in files): | 370 'lib/info.js' not in files): |
| 377 files['lib/info.js'] = createInfoModule(params) | 371 files['lib/info.js'] = createInfoModule(params) |
| 378 | 372 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 409 def shutdown_server(server): | 403 def shutdown_server(server): |
| 410 time.sleep(10) | 404 time.sleep(10) |
| 411 server.shutdown() | 405 server.shutdown() |
| 412 thread.start_new_thread(shutdown_server, (server,)) | 406 thread.start_new_thread(shutdown_server, (server,)) |
| 413 server.serve_forever() | 407 server.serve_forever() |
| 414 | 408 |
| 415 if connections[0] == 0: | 409 if connections[0] == 0: |
| 416 print 'Warning: No incoming connections, extension probably not active in th e browser yet' | 410 print 'Warning: No incoming connections, extension probably not active in th e browser yet' |
| 417 else: | 411 else: |
| 418 print 'Handled %i connection(s)' % connections[0] | 412 print 'Handled %i connection(s)' % connections[0] |
| OLD | NEW |