Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 packagerGecko and packagerChrome. | 6 # packagers are implemented in packagerGecko and packagerChrome. |
7 | 7 |
8 import sys | 8 import sys |
9 import os | 9 import os |
10 import re | 10 import re |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
127 | 127 |
128 def preprocess(self, filenames, params={}): | 128 def preprocess(self, filenames, params={}): |
129 import jinja2 | 129 import jinja2 |
130 env = jinja2.Environment() | 130 env = jinja2.Environment() |
131 | 131 |
132 for filename in filenames: | 132 for filename in filenames: |
133 env.autoescape = os.path.splitext(filename)[1].lower() in ('.html', '.xml') | 133 env.autoescape = os.path.splitext(filename)[1].lower() in ('.html', '.xml') |
134 template = env.from_string(self[filename].decode('utf-8')) | 134 template = env.from_string(self[filename].decode('utf-8')) |
135 self[filename] = template.render(params).encode('utf-8') | 135 self[filename] = template.render(params).encode('utf-8') |
136 | 136 |
137 def zip(self, outFile, sortKey=None, compress=True): | 137 def zip(self, outFile, sortKey=None, compression=zipfile.ZIP_DEFLATED): |
Sebastian Noack
2016/10/04 19:58:05
Perhaps it is a little simpler if you just pass th
Vasily Kuznetsov
2016/10/11 15:58:28
Done.
| |
138 compression = zipfile.ZIP_DEFLATED if compress else zipfile.ZIP_STORED | 138 with zipfile.ZipFile(outFile, 'w', compression) as zf: |
139 zf = zipfile.ZipFile(outFile, 'w', compression) | 139 for name in sorted(self, key=sortKey): |
Sebastian Noack
2016/10/04 19:58:05
While changing this code anyway, use with-statemen
Vasily Kuznetsov
2016/10/11 15:58:27
Done.
| |
140 for name in sorted(self, key=sortKey): | 140 zf.writestr(name, self[name]) |
141 zf.writestr(name, self[name]) | |
142 zf.close() | |
143 | 141 |
144 def zipToString(self, sortKey=None): | 142 def zipToString(self, sortKey=None): |
145 buffer = StringIO() | 143 buffer = StringIO() |
146 self.zip(buffer, sortKey=sortKey) | 144 self.zip(buffer, sortKey=sortKey) |
147 return buffer.getvalue() | 145 return buffer.getvalue() |
LEFT | RIGHT |