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 26 matching lines...) Expand all Loading... |
37 | 37 |
38 | 38 |
39 def getBuildNum(baseDir): | 39 def getBuildNum(baseDir): |
40 try: | 40 try: |
41 from buildtools.ensure_dependencies import Mercurial, Git | 41 from buildtools.ensure_dependencies import Mercurial, Git |
42 if Mercurial().istype(baseDir): | 42 if Mercurial().istype(baseDir): |
43 result = subprocess.check_output(['hg', 'id', '-R', baseDir, '-n']) | 43 result = subprocess.check_output(['hg', 'id', '-R', baseDir, '-n']) |
44 return re.sub(r'\D', '', result) | 44 return re.sub(r'\D', '', result) |
45 elif Git().istype(baseDir): | 45 elif Git().istype(baseDir): |
46 result = subprocess.check_output(['git', 'rev-list', 'HEAD'], cwd=ba
seDir) | 46 result = subprocess.check_output(['git', 'rev-list', 'HEAD'], cwd=ba
seDir) |
47 return len(result.splitlines()) | 47 return str(len(result.splitlines())) |
48 except subprocess.CalledProcessError: | 48 except subprocess.CalledProcessError: |
49 pass | 49 pass |
50 | 50 |
51 return '0' | 51 return '0' |
52 | 52 |
53 | 53 |
54 def getBuildVersion(baseDir, metadata, releaseBuild, buildNum=None): | 54 def getBuildVersion(baseDir, metadata, releaseBuild, buildNum=None): |
55 version = metadata.get('general', 'version') | 55 version = metadata.get('general', 'version') |
56 if not releaseBuild: | 56 if not releaseBuild: |
57 if buildNum == None: | 57 if buildNum == None: |
(...skipping 69 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): |
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): |
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 |