| 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-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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 ).encode('utf-8') | 113 ).encode('utf-8') |
| 114 | 114 |
| 115 def createInfoModule(params): | 115 def createInfoModule(params): |
| 116 template = getTemplate('safariInfo.js.tmpl') | 116 template = getTemplate('safariInfo.js.tmpl') |
| 117 return template.render(params).encode('utf-8') | 117 return template.render(params).encode('utf-8') |
| 118 | 118 |
| 119 def fixAbsoluteUrls(files): | 119 def fixAbsoluteUrls(files): |
| 120 for filename, content in files.iteritems(): | 120 for filename, content in files.iteritems(): |
| 121 if os.path.splitext(filename)[1].lower() == '.html': | 121 if os.path.splitext(filename)[1].lower() == '.html': |
| 122 files[filename] = re.sub( | 122 files[filename] = re.sub( |
| 123 r'(<[^<>]*?\b(?:href|src)\s*=\s*["\']?)(?=\/)', | 123 r'(<[^<>]*?\b(?:href|src)\s*=\s*["\']?)\/+', |
| 124 r'\1' + ('/'.join(['..'] * filename.count('/')) or '.'), | 124 r'\1' + '/'.join(['..'] * filename.count('/') + ['']), |
| 125 content, re.S | re.I | 125 content, re.S | re.I |
| 126 ) | 126 ) |
| 127 | 127 |
| 128 def createSignedXarArchive(outFile, files, keyFile): | 128 def createSignedXarArchive(outFile, files, keyFile): |
| 129 import subprocess | 129 import subprocess |
| 130 import tempfile | 130 import tempfile |
| 131 import shutil | 131 import shutil |
| 132 import M2Crypto | 132 import M2Crypto |
| 133 | 133 |
| 134 # write files to temporary directory and create a xar archive | 134 # write files to temporary directory and create a xar archive |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 fixAbsoluteUrls(files) | 260 fixAbsoluteUrls(files) |
| 261 | 261 |
| 262 dirname = metadata.get('general', 'basename') + '.safariextension' | 262 dirname = metadata.get('general', 'basename') + '.safariextension' |
| 263 for filename in files.keys(): | 263 for filename in files.keys(): |
| 264 files[os.path.join(dirname, filename)] = files.pop(filename) | 264 files[os.path.join(dirname, filename)] = files.pop(filename) |
| 265 | 265 |
| 266 if keyFile: | 266 if keyFile: |
| 267 createSignedXarArchive(outFile, files, keyFile) | 267 createSignedXarArchive(outFile, files, keyFile) |
| 268 else: | 268 else: |
| 269 files.zip(outFile) | 269 files.zip(outFile) |
| LEFT | RIGHT |