Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: packager.py

Issue 29345751: Issue 4028 - Add support for Edge extensions to buildtools (Closed)
Left Patch Set: Created June 13, 2016, 12:31 p.m.
Right Patch Set: Address Windows Store issues with blockmap and devbuild display name Created Oct. 14, 2016, 12:07 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « docs/metadata.edge.example ('k') | packagerChrome.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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
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:
58 buildNum = getBuildNum(baseDir) 58 buildNum = getBuildNum(baseDir)
59 if len(buildNum) > 0: 59 if len(buildNum) > 0:
60 if re.search(r'(^|\.)\d+$', version): 60 if re.search(r'(^|\.)\d+$', version):
61 # Numerical version number - need to fill up with zeros to have three 61 # Numerical version number - need to fill up with zeros to have three
62 # version components. 62 # version components.
63 while version.count('.') < 2: 63 while version.count('.') < 2:
64 version += '.0' 64 version += '.0'
65 version += '.' + buildNum 65 version += '.' + buildNum
66 return version 66 return version
67 67
68 68
69 def getTemplate(template, autoEscape=False): 69 def getTemplate(template, autoEscape=False):
70 import jinja2 70 import jinja2
71 71
72 templatePath = os.path.join(buildtools.__path__[0], 'templates') 72 template_path = os.path.join(buildtools.__path__[0], 'templates')
Vasily Kuznetsov 2016/06/13 12:57:31 These changes are needed to move all templates int
73 loader = jinja2.FileSystemLoader(templatePath) 73 loader = jinja2.FileSystemLoader(template_path)
74 if autoEscape: 74 if autoEscape:
75 env = jinja2.Environment(loader=loader, autoescape=True) 75 env = jinja2.Environment(loader=loader, autoescape=True)
76 else: 76 else:
77 env = jinja2.Environment(loader=loader) 77 env = jinja2.Environment(loader=loader)
78 env.filters.update({'json': json.dumps}) 78 env.filters.update({'json': json.dumps})
79 return env.get_template(template) 79 return env.get_template(template)
80 80
81 81
82 class Files(dict): 82 class Files(dict):
83 def __init__(self, includedFiles, ignoredFiles, process=None): 83 def __init__(self, includedFiles, ignoredFiles, process=None):
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
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): 137 def zip(self, outFile, sortKey=None, compression=zipfile.ZIP_DEFLATED):
138 zip = zipfile.ZipFile(outFile, 'w', zipfile.ZIP_DEFLATED) 138 with zipfile.ZipFile(outFile, 'w', compression) as zf:
139 names = self.keys() 139 for name in sorted(self, key=sortKey):
140 names.sort(key=sortKey) 140 zf.writestr(name, self[name])
141 for name in names:
142 zip.writestr(name, self[name])
143 zip.close()
144 141
145 def zipToString(self, sortKey=None): 142 def zipToString(self, sortKey=None):
146 buffer = StringIO() 143 buffer = StringIO()
147 self.zip(buffer, sortKey=sortKey) 144 self.zip(buffer, sortKey=sortKey)
148 return buffer.getvalue() 145 return buffer.getvalue()
LEFTRIGHT

Powered by Google App Engine
This is Rietveld