Index: packager.py |
=================================================================== |
--- a/packager.py |
+++ b/packager.py |
@@ -3,17 +3,16 @@ |
# file, You can obtain one at http://mozilla.org/MPL/2.0/. |
# Note: These are the base functions common to all packagers, the actual |
# packagers are implemented in packagerGecko and packagerChrome. |
import sys |
import os |
import re |
-import codecs |
import subprocess |
import json |
import zipfile |
from StringIO import StringIO |
from chainedconfigparser import ChainedConfigParser |
import buildtools |
@@ -65,21 +64,22 @@ |
version += '.0' |
version += '.' + buildNum |
return version |
def getTemplate(template, autoEscape=False): |
import jinja2 |
- templatePath = buildtools.__path__[0] |
+ template_path = os.path.join(buildtools.__path__[0], 'templates') |
+ loader = jinja2.FileSystemLoader(template_path) |
if autoEscape: |
- env = jinja2.Environment(loader=jinja2.FileSystemLoader(templatePath), autoescape=True) |
+ env = jinja2.Environment(loader=loader, autoescape=True) |
else: |
- env = jinja2.Environment(loader=jinja2.FileSystemLoader(templatePath)) |
+ env = jinja2.Environment(loader=loader) |
env.filters.update({'json': json.dumps}) |
return env.get_template(template) |
class Files(dict): |
def __init__(self, includedFiles, ignoredFiles, process=None): |
self.includedFiles = includedFiles |
self.ignoredFiles = ignoredFiles |
@@ -129,20 +129,19 @@ |
import jinja2 |
env = jinja2.Environment() |
for filename in filenames: |
env.autoescape = os.path.splitext(filename)[1].lower() in ('.html', '.xml') |
template = env.from_string(self[filename].decode('utf-8')) |
self[filename] = template.render(params).encode('utf-8') |
- def zip(self, outFile, sortKey=None): |
- zip = zipfile.ZipFile(outFile, 'w', zipfile.ZIP_DEFLATED) |
- names = self.keys() |
- names.sort(key=sortKey) |
- for name in names: |
- zip.writestr(name, self[name]) |
- zip.close() |
+ def zip(self, outFile, sortKey=None, compress=True): |
+ compression = zipfile.ZIP_DEFLATED if compress else zipfile.ZIP_STORED |
+ zf = zipfile.ZipFile(outFile, 'w', compression) |
+ for name in sorted(self, key=sortKey): |
+ zf.writestr(name, self[name]) |
+ zf.close() |
def zipToString(self, sortKey=None): |
buffer = StringIO() |
self.zip(buffer, sortKey=sortKey) |
return buffer.getvalue() |