OLD | NEW |
1 # This Source Code Form is subject to the terms of the Mozilla Public | 1 # This Source Code Form is subject to the terms of the Mozilla Public |
2 # License, v. 2.0. If a copy of the MPL was not distributed with this | 2 # License, v. 2.0. If a copy of the MPL was not distributed with this |
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. | 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
4 | 4 |
5 # Note: These are the base functions common to all packagers, the actual | 5 # Note: These are the base functions common to all packagers, the actual |
6 # packagers are implemented in packagerChrome and packagerEdge. | 6 # packagers are implemented in packagerChrome and packagerEdge. |
7 | 7 |
8 import sys | 8 import sys |
9 import os | 9 import os |
10 import re | 10 import re |
11 import subprocess | 11 import subprocess |
| 12 import tempfile |
12 import json | 13 import json |
13 import zipfile | 14 import zipfile |
14 from StringIO import StringIO | 15 from StringIO import StringIO |
15 from chainedconfigparser import ChainedConfigParser | 16 from chainedconfigparser import ChainedConfigParser |
16 | 17 |
17 import buildtools | 18 import buildtools |
18 | 19 |
19 EXTENSIONS = { | 20 EXTENSIONS = { |
20 'edge': 'appx', | 21 'edge': 'appx', |
21 'gecko': 'xpi', | 22 'gecko': 'xpi', |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 for filename in filenames: | 161 for filename in filenames: |
161 env.autoescape = os.path.splitext(filename)[1].lower() in ('.html',
'.xml') | 162 env.autoescape = os.path.splitext(filename)[1].lower() in ('.html',
'.xml') |
162 template = env.from_string(self[filename].decode('utf-8')) | 163 template = env.from_string(self[filename].decode('utf-8')) |
163 self[filename] = template.render(params).encode('utf-8') | 164 self[filename] = template.render(params).encode('utf-8') |
164 | 165 |
165 def zip(self, outFile, sortKey=None, compression=zipfile.ZIP_DEFLATED): | 166 def zip(self, outFile, sortKey=None, compression=zipfile.ZIP_DEFLATED): |
166 with zipfile.ZipFile(outFile, 'w', compression) as zf: | 167 with zipfile.ZipFile(outFile, 'w', compression) as zf: |
167 for name in sorted(self, key=sortKey): | 168 for name in sorted(self, key=sortKey): |
168 zf.writestr(name, self[name]) | 169 zf.writestr(name, self[name]) |
169 | 170 |
| 171 def to_tmp_folder(self, subfolder=None): |
| 172 tmp_dir = tempfile.mkdtemp('adblockplus_package') |
| 173 if subfolder: |
| 174 cwtd = os.path.join(tmp_dir, subfolder) |
| 175 os.makedirs(cwtd) |
| 176 else: |
| 177 cwtd = tmp_dir |
| 178 |
| 179 for name in sorted(self): |
| 180 dest = os.path.join(cwtd, name) |
| 181 try: |
| 182 os.makedirs(os.path.dirname(dest)) |
| 183 except OSError: |
| 184 pass |
| 185 |
| 186 with open(dest, 'w') as fp: |
| 187 fp.write(self[name]) |
| 188 return tmp_dir |
| 189 |
170 def zipToString(self, sortKey=None): | 190 def zipToString(self, sortKey=None): |
171 buffer = StringIO() | 191 buffer = StringIO() |
172 self.zip(buffer, sortKey=sortKey) | 192 self.zip(buffer, sortKey=sortKey) |
173 return buffer.getvalue() | 193 return buffer.getvalue() |
OLD | NEW |