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-2013 Eyeo GmbH | 4 # Copyright (C) 2006-2013 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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
153 pass | 153 pass |
154 | 154 |
155 # Source files of the conversion shouldn't be part of the build | 155 # Source files of the conversion shouldn't be part of the build |
156 for sourceFile in sourceFiles: | 156 for sourceFile in sourceFiles: |
157 if sourceFile in files: | 157 if sourceFile in files: |
158 del files[sourceFile] | 158 del files[sourceFile] |
159 | 159 |
160 sourceFiles = map(lambda f: os.path.abspath(os.path.join(baseDir, f)), sourc eFiles) | 160 sourceFiles = map(lambda f: os.path.abspath(os.path.join(baseDir, f)), sourc eFiles) |
161 files[file] = doRewrite(sourceFiles, args) | 161 files[file] = doRewrite(sourceFiles, args) |
162 | 162 |
163 def toJson(data): | |
164 return json.dumps( | |
165 data, ensure_ascii=False, sort_keys=True, | |
166 indent=2, separators=(',', ': ') | |
167 ).encode('utf-8') + '\n' | |
168 | |
163 def importGeckoLocales(params, files): | 169 def importGeckoLocales(params, files): |
164 import localeTools | 170 import localeTools |
165 | 171 |
166 localeCodeMapping = { | 172 localeCodeMapping = { |
167 'ar': 'ar', | 173 'ar': 'ar', |
168 'bg': 'bg', | 174 'bg': 'bg', |
169 'ca': 'ca', | 175 'ca': 'ca', |
170 'cs': 'cs', | 176 'cs': 'cs', |
171 'da': 'da', | 177 'da': 'da', |
172 'de': 'de', | 178 'de': 'de', |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
254 if match: | 260 if match: |
255 value = match.group(1) | 261 value = match.group(1) |
256 else: | 262 else: |
257 index = value.find("&") | 263 index = value.find("&") |
258 if index >= 0: | 264 if index >= 0: |
259 value = value[0:index] + value[index + 1:] | 265 value = value[0:index] + value[index + 1:] |
260 data[key] = {'message': value} | 266 data[key] = {'message': value} |
261 except Exception, e: | 267 except Exception, e: |
262 print 'Warning: error importing locale data from %s: %s' % (sourceFile, e) | 268 print 'Warning: error importing locale data from %s: %s' % (sourceFile, e) |
263 | 269 |
264 files[targetFile] = json.dumps(data, ensure_ascii=False, sort_keys=True, | 270 files[targetFile] = toJson(data) |
265 indent=2, separators=(',', ': ')).encode('utf-8') + '\n' | |
266 | 271 |
267 if params['type'] == 'opera': | 272 if params['type'] == 'opera': |
268 # Opera has a slightly different locale mapping | 273 # Opera has a slightly different locale mapping |
269 operaMapping = { | 274 operaMapping = { |
270 'es': 'es_ES', | 275 'es': 'es_ES', |
271 'es_419': None, | 276 'es_419': None, |
272 'pt': 'pt_PT', | 277 'pt': 'pt_PT', |
273 } | 278 } |
274 for chromeLocale, operaLocale in operaMapping.iteritems(): | 279 for chromeLocale, operaLocale in operaMapping.iteritems(): |
275 chromeFile = '_locales/%s/messages.json' % chromeLocale | 280 chromeFile = '_locales/%s/messages.json' % chromeLocale |
276 operaFile = '_locales/%s/messages.json' % operaLocale if operaLocale != No ne else None | 281 operaFile = '_locales/%s/messages.json' % operaLocale if operaLocale != No ne else None |
277 if chromeFile in files: | 282 if chromeFile in files: |
278 if operaFile != None: | 283 if operaFile != None: |
279 files[operaFile] = files[chromeFile] | 284 files[operaFile] = files[chromeFile] |
280 del files[chromeFile] | 285 del files[chromeFile] |
281 | 286 |
287 def fixMissingTranslations(files): | |
288 # Chrome requires messages used in manifest.json to be given in all languages | |
289 defaults = [] | |
290 for name, info in json.loads(files['_locales/%s/messages.json' % defaultLocale ]).iteritems(): | |
291 if '__MSG_%s__' % name in files['manifest.json']: | |
292 defaults.append((name, info)) | |
Wladimir Palant
2014/03/13 15:21:45
This seems backwards, shouldn't we search for __MS
Sebastian Noack
2014/03/13 15:44:33
Done.
| |
293 | |
294 for filename in files: | |
295 if not filename.startswith('_locales/') or not filename.endswith('/messages. json'): | |
296 continue | |
297 | |
298 data = json.loads(files[filename]) | |
299 for name, info in defaults: | |
300 data.setdefault(name, info) | |
301 | |
302 files[filename] = toJson(data) | |
303 | |
282 def signBinary(zipdata, keyFile): | 304 def signBinary(zipdata, keyFile): |
283 import M2Crypto | 305 import M2Crypto |
284 if not os.path.exists(keyFile): | 306 if not os.path.exists(keyFile): |
285 M2Crypto.RSA.gen_key(1024, 65537, callback=lambda x: None).save_key(keyFile, cipher=None) | 307 M2Crypto.RSA.gen_key(1024, 65537, callback=lambda x: None).save_key(keyFile, cipher=None) |
286 key = M2Crypto.EVP.load_key(keyFile) | 308 key = M2Crypto.EVP.load_key(keyFile) |
287 key.sign_init() | 309 key.sign_init() |
288 key.sign_update(zipdata) | 310 key.sign_update(zipdata) |
289 return key.final() | 311 return key.final() |
290 | 312 |
291 def getPublicKey(keyFile): | 313 def getPublicKey(keyFile): |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
336 | 358 |
337 if metadata.has_section('preprocess'): | 359 if metadata.has_section('preprocess'): |
338 files.preprocess( | 360 files.preprocess( |
339 [f for f, _ in metadata.items('preprocess')], | 361 [f for f, _ in metadata.items('preprocess')], |
340 {'needsExt': True} | 362 {'needsExt': True} |
341 ) | 363 ) |
342 | 364 |
343 if metadata.has_section('import_locales'): | 365 if metadata.has_section('import_locales'): |
344 importGeckoLocales(params, files) | 366 importGeckoLocales(params, files) |
345 | 367 |
368 fixMissingTranslations(files) | |
369 | |
346 if devenv: | 370 if devenv: |
347 files['devenvPoller__.js'] = createPoller(params) | 371 files['devenvPoller__.js'] = createPoller(params) |
348 | 372 |
349 if (metadata.has_option('general', 'backgroundScripts') and | 373 if (metadata.has_option('general', 'backgroundScripts') and |
350 'lib/info.js' in re.split(r'\s+', metadata.get('general', 'backgroundScrip ts')) and | 374 'lib/info.js' in re.split(r'\s+', metadata.get('general', 'backgroundScrip ts')) and |
351 'lib/info.js' not in files): | 375 'lib/info.js' not in files): |
352 files['lib/info.js'] = createInfoModule(params) | 376 files['lib/info.js'] = createInfoModule(params) |
353 | 377 |
354 zipdata = files.zipToString() | 378 zipdata = files.zipToString() |
355 signature = None | 379 signature = None |
(...skipping 28 matching lines...) Expand all Loading... | |
384 def shutdown_server(server): | 408 def shutdown_server(server): |
385 time.sleep(10) | 409 time.sleep(10) |
386 server.shutdown() | 410 server.shutdown() |
387 thread.start_new_thread(shutdown_server, (server,)) | 411 thread.start_new_thread(shutdown_server, (server,)) |
388 server.serve_forever() | 412 server.serve_forever() |
389 | 413 |
390 if connections[0] == 0: | 414 if connections[0] == 0: |
391 print 'Warning: No incoming connections, extension probably not active in th e browser yet' | 415 print 'Warning: No incoming connections, extension probably not active in th e browser yet' |
392 else: | 416 else: |
393 print 'Handled %i connection(s)' % connections[0] | 417 print 'Handled %i connection(s)' % connections[0] |
OLD | NEW |