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-2012 Eyeo GmbH | 4 # Copyright (C) 2006-2012 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 26 matching lines...) Expand all Loading... |
37 | 37 |
38 if params['devenv']: | 38 if params['devenv']: |
39 result.add('qunit') | 39 result.add('qunit') |
40 | 40 |
41 baseDir = params['baseDir'] | 41 baseDir = params['baseDir'] |
42 for file in os.listdir(baseDir): | 42 for file in os.listdir(baseDir): |
43 if file.endswith('.js') or file.endswith('.html') or file.endswith('.xml'): | 43 if file.endswith('.js') or file.endswith('.html') or file.endswith('.xml'): |
44 result.add(file) | 44 result.add(file) |
45 return result | 45 return result |
46 | 46 |
| 47 def processFile(path, data, params): |
| 48 # We don't change anything yet, this function currently only exists here so |
| 49 # that it can be overridden if necessary. |
| 50 return data |
| 51 |
47 def createManifest(params): | 52 def createManifest(params): |
48 template = getTemplate('manifest.json.tmpl') | 53 template = getTemplate('manifest.json.tmpl') |
49 templateData = dict(params) | 54 templateData = dict(params) |
50 | 55 |
51 baseDir = templateData['baseDir'] | 56 baseDir = templateData['baseDir'] |
52 metadata = templateData['metadata'] | 57 metadata = templateData['metadata'] |
53 | 58 |
54 if metadata.has_option('general', 'pageAction'): | 59 if metadata.has_option('general', 'pageAction') and metadata.get('general', 'p
ageAction') != '': |
55 icon, popup = re.split(r'\s+', metadata.get('general', 'pageAction'), 1) | 60 icon, popup = re.split(r'\s+', metadata.get('general', 'pageAction'), 1) |
56 templateData['pageAction'] = {'icon': icon, 'popup': popup} | 61 templateData['pageAction'] = {'icon': icon, 'popup': popup} |
57 | 62 |
58 if metadata.has_option('general', 'icons'): | 63 if metadata.has_option('general', 'icons'): |
59 icons = {} | 64 icons = {} |
60 iconsDir = baseDir | 65 iconsDir = baseDir |
61 for dir in metadata.get('general', 'icons').split('/')[0:-1]: | 66 for dir in metadata.get('general', 'icons').split('/')[0:-1]: |
62 iconsDir = os.path.join(iconsDir, dir) | 67 iconsDir = os.path.join(iconsDir, dir) |
63 | 68 |
64 prefix, suffix = metadata.get('general', 'icons').split('/')[-1].split('?',
1) | 69 prefix, suffix = metadata.get('general', 'icons').split('/')[-1].split('?',
1) |
65 for file in os.listdir(iconsDir): | 70 for file in os.listdir(iconsDir): |
66 path = os.path.join(iconsDir, file) | 71 path = os.path.join(iconsDir, file) |
67 if os.path.isfile(path) and file.startswith(prefix) and file.endswith(suff
ix): | 72 if os.path.isfile(path) and file.startswith(prefix) and file.endswith(suff
ix): |
68 size = file[len(prefix):-len(suffix)] | 73 size = file[len(prefix):-len(suffix)] |
69 if not re.search(r'\D', size): | 74 if not re.search(r'\D', size): |
70 icons[size] = os.path.relpath(path, baseDir).replace('\\', '/') | 75 icons[size] = os.path.relpath(path, baseDir).replace('\\', '/') |
71 | 76 |
72 templateData['icons'] = icons | 77 templateData['icons'] = icons |
73 | 78 |
74 if metadata.has_option('general', 'permissions'): | 79 if metadata.has_option('general', 'permissions'): |
75 templateData['permissions'] = re.split(r'\s+', metadata.get('general', 'perm
issions')) | 80 templateData['permissions'] = re.split(r'\s+', metadata.get('general', 'perm
issions')) |
76 if params['experimentalAPI']: | 81 if params['experimentalAPI']: |
77 templateData['permissions'].append('experimental') | 82 templateData['permissions'].append('experimental') |
78 | 83 |
79 if metadata.has_option('general', 'backgroundScripts'): | 84 if metadata.has_option('general', 'backgroundScripts'): |
80 templateData['backgroundScripts'] = re.split(r'\s+', metadata.get('general',
'backgroundScripts')) | 85 templateData['backgroundScripts'] = re.split(r'\s+', metadata.get('general',
'backgroundScripts')) |
81 if params['devenv']: | 86 if params['devenv']: |
82 templateData['backgroundScripts'].append('devenvPoller__.js') | 87 templateData['backgroundScripts'].append('devenvPoller__.js') |
83 | 88 |
84 if metadata.has_option('general', 'webAccessible'): | 89 if metadata.has_option('general', 'webAccessible') and metadata.get('general',
'webAccessible') != '': |
85 templateData['webAccessible'] = re.split(r'\s+', metadata.get('general', 'we
bAccessible')) | 90 templateData['webAccessible'] = re.split(r'\s+', metadata.get('general', 'we
bAccessible')) |
86 | 91 |
87 if metadata.has_section('contentScripts'): | 92 if metadata.has_section('contentScripts'): |
88 contentScripts = [] | 93 contentScripts = [] |
89 for run_at, scripts in metadata.items('contentScripts'): | 94 for run_at, scripts in metadata.items('contentScripts'): |
| 95 if scripts == '': |
| 96 continue |
90 contentScripts.append({ | 97 contentScripts.append({ |
91 'matches': ['http://*/*', 'https://*/*'], | 98 'matches': ['http://*/*', 'https://*/*'], |
92 'js': re.split(r'\s+', scripts), | 99 'js': re.split(r'\s+', scripts), |
93 'run_at': run_at, | 100 'run_at': run_at, |
94 'all_frames': True, | 101 'all_frames': True, |
95 }) | 102 }) |
96 templateData['contentScripts'] = contentScripts | 103 templateData['contentScripts'] = contentScripts |
97 | 104 |
98 manifest = template.render(templateData) | 105 manifest = template.render(templateData) |
99 | 106 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 incompleteMarker = os.path.join(os.path.dirname(sourceFile), '.incomplete'
) | 198 incompleteMarker = os.path.join(os.path.dirname(sourceFile), '.incomplete'
) |
192 if not os.path.exists(sourceFile) or os.path.exists(incompleteMarker): | 199 if not os.path.exists(sourceFile) or os.path.exists(incompleteMarker): |
193 continue | 200 continue |
194 | 201 |
195 data = {} | 202 data = {} |
196 if targetFile in files: | 203 if targetFile in files: |
197 data = json.loads(files[targetFile].decode('utf-8')) | 204 data = json.loads(files[targetFile].decode('utf-8')) |
198 | 205 |
199 try: | 206 try: |
200 sourceData = localeTools.readFile(sourceFile) | 207 sourceData = localeTools.readFile(sourceFile) |
| 208 |
| 209 # Resolve wildcard imports |
| 210 if keys == '*' or keys == '=*': |
| 211 importList = sourceData.keys() |
| 212 importList = filter(lambda k: not k.startswith('_'), importList) |
| 213 if keys == '=*': |
| 214 importList = map(lambda k: '=' + k, importList) |
| 215 keys = ' '.join(importList) |
| 216 |
201 for stringID in re.split(r'\s+', keys): | 217 for stringID in re.split(r'\s+', keys): |
202 noMangling = False | 218 noMangling = False |
203 if stringID.startswith('='): | 219 if stringID.startswith('='): |
204 stringID = stringID[1:] | 220 stringID = stringID[1:] |
205 noMangling = True | 221 noMangling = True |
206 | 222 |
207 if stringID in sourceData: | 223 if stringID in sourceData: |
208 if noMangling: | 224 if noMangling: |
209 key = stringID | 225 key = re.sub(r'\W', '_', stringID) |
210 else: | 226 else: |
211 key = re.sub(r'\..*', '', parts[-1]) + '_' + re.sub(r'\W', '_', st
ringID) | 227 key = re.sub(r'\..*', '', parts[-1]) + '_' + re.sub(r'\W', '_', st
ringID) |
212 if key in data: | 228 if key in data: |
213 print 'Warning: locale string %s defined multiple times' % key | 229 print 'Warning: locale string %s defined multiple times' % key |
214 data[key] = {'message': sourceData[stringID]} | 230 data[key] = {'message': sourceData[stringID]} |
215 except Exception, e: | 231 except Exception, e: |
216 print 'Warning: error importing locale data from %s: %s' % (sourceFile,
e) | 232 print 'Warning: error importing locale data from %s: %s' % (sourceFile,
e) |
217 | 233 |
218 files[targetFile] = json.dumps(data, ensure_ascii=False, sort_keys=True, | 234 files[targetFile] = json.dumps(data, ensure_ascii=False, sort_keys=True, |
219 indent=2, separators=(',', ': ')).encode('utf-8') +
'\n' | 235 indent=2, separators=(',', ': ')).encode('utf-8') +
'\n' |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 | 267 |
252 params = { | 268 params = { |
253 'baseDir': baseDir, | 269 'baseDir': baseDir, |
254 'releaseBuild': releaseBuild, | 270 'releaseBuild': releaseBuild, |
255 'version': version, | 271 'version': version, |
256 'experimentalAPI': experimentalAPI, | 272 'experimentalAPI': experimentalAPI, |
257 'devenv': devenv, | 273 'devenv': devenv, |
258 'metadata': metadata, | 274 'metadata': metadata, |
259 } | 275 } |
260 | 276 |
261 files = Files(getPackageFiles(params), getIgnoredFiles(params)) | 277 files = Files(getPackageFiles(params), getIgnoredFiles(params), |
| 278 process=lambda path, data: processFile(path, data, params)) |
262 files['manifest.json'] = createManifest(params) | 279 files['manifest.json'] = createManifest(params) |
263 if metadata.has_section('mapping'): | 280 if metadata.has_section('mapping'): |
264 files.readMappedFiles(metadata.items('mapping')) | 281 files.readMappedFiles(metadata.items('mapping')) |
265 files.read(baseDir) | 282 files.read(baseDir) |
266 | 283 |
267 if metadata.has_section('convert_js'): | 284 if metadata.has_section('convert_js'): |
268 convertJS(params, files) | 285 convertJS(params, files) |
269 | 286 |
270 if metadata.has_section('import_locales'): | 287 if metadata.has_section('import_locales'): |
271 importGeckoLocales(params, files) | 288 importGeckoLocales(params, files) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 def shutdown_server(server): | 323 def shutdown_server(server): |
307 time.sleep(10) | 324 time.sleep(10) |
308 server.shutdown() | 325 server.shutdown() |
309 thread.start_new_thread(shutdown_server, (server,)) | 326 thread.start_new_thread(shutdown_server, (server,)) |
310 server.serve_forever() | 327 server.serve_forever() |
311 | 328 |
312 if connections[0] == 0: | 329 if connections[0] == 0: |
313 print 'Warning: No incoming connections, extension probably not active in th
e browser yet' | 330 print 'Warning: No incoming connections, extension probably not active in th
e browser yet' |
314 else: | 331 else: |
315 print 'Handled %i connection(s)' % connections[0] | 332 print 'Handled %i connection(s)' % connections[0] |
LEFT | RIGHT |