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 data = json.loads(files['_locales/%s/messages.json' % defaultLocale]) |
| 291 for match in re.finditer(r'__MSG_(\S+)__', files['manifest.json']): |
| 292 name = match.group(1) |
| 293 defaults[name] = data[name] |
| 294 |
| 295 for filename in files: |
| 296 if not filename.startswith('_locales/') or not filename.endswith('/messages.
json'): |
| 297 continue |
| 298 |
| 299 data = json.loads(files[filename]) |
| 300 for name, info in defaults.iteritems(): |
| 301 data.setdefault(name, info) |
| 302 |
| 303 files[filename] = toJson(data) |
| 304 |
282 def signBinary(zipdata, keyFile): | 305 def signBinary(zipdata, keyFile): |
283 import M2Crypto | 306 import M2Crypto |
284 if not os.path.exists(keyFile): | 307 if not os.path.exists(keyFile): |
285 M2Crypto.RSA.gen_key(1024, 65537, callback=lambda x: None).save_key(keyFile,
cipher=None) | 308 M2Crypto.RSA.gen_key(1024, 65537, callback=lambda x: None).save_key(keyFile,
cipher=None) |
286 key = M2Crypto.EVP.load_key(keyFile) | 309 key = M2Crypto.EVP.load_key(keyFile) |
287 key.sign_init() | 310 key.sign_init() |
288 key.sign_update(zipdata) | 311 key.sign_update(zipdata) |
289 return key.final() | 312 return key.final() |
290 | 313 |
291 def getPublicKey(keyFile): | 314 def getPublicKey(keyFile): |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 | 359 |
337 if metadata.has_section('preprocess'): | 360 if metadata.has_section('preprocess'): |
338 files.preprocess( | 361 files.preprocess( |
339 [f for f, _ in metadata.items('preprocess')], | 362 [f for f, _ in metadata.items('preprocess')], |
340 {'needsExt': True} | 363 {'needsExt': True} |
341 ) | 364 ) |
342 | 365 |
343 if metadata.has_section('import_locales'): | 366 if metadata.has_section('import_locales'): |
344 importGeckoLocales(params, files) | 367 importGeckoLocales(params, files) |
345 | 368 |
| 369 fixMissingTranslations(files) |
| 370 |
346 if devenv: | 371 if devenv: |
347 files['devenvPoller__.js'] = createPoller(params) | 372 files['devenvPoller__.js'] = createPoller(params) |
348 | 373 |
349 if (metadata.has_option('general', 'backgroundScripts') and | 374 if (metadata.has_option('general', 'backgroundScripts') and |
350 'lib/info.js' in re.split(r'\s+', metadata.get('general', 'backgroundScrip
ts')) and | 375 'lib/info.js' in re.split(r'\s+', metadata.get('general', 'backgroundScrip
ts')) and |
351 'lib/info.js' not in files): | 376 'lib/info.js' not in files): |
352 files['lib/info.js'] = createInfoModule(params) | 377 files['lib/info.js'] = createInfoModule(params) |
353 | 378 |
354 zipdata = files.zipToString() | 379 zipdata = files.zipToString() |
355 signature = None | 380 signature = None |
(...skipping 28 matching lines...) Expand all Loading... |
384 def shutdown_server(server): | 409 def shutdown_server(server): |
385 time.sleep(10) | 410 time.sleep(10) |
386 server.shutdown() | 411 server.shutdown() |
387 thread.start_new_thread(shutdown_server, (server,)) | 412 thread.start_new_thread(shutdown_server, (server,)) |
388 server.serve_forever() | 413 server.serve_forever() |
389 | 414 |
390 if connections[0] == 0: | 415 if connections[0] == 0: |
391 print 'Warning: No incoming connections, extension probably not active in th
e browser yet' | 416 print 'Warning: No incoming connections, extension probably not active in th
e browser yet' |
392 else: | 417 else: |
393 print 'Handled %i connection(s)' % connections[0] | 418 print 'Handled %i connection(s)' % connections[0] |
OLD | NEW |