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

Delta Between Two Patch Sets: packagerChrome.py

Issue 29399569: Issue 5060 - Move require into modules template, make info a module (Closed)
Left Patch Set: Don't redeclare require Created March 31, 2017, 6:48 a.m.
Right Patch Set: Improve check for require Created April 1, 2017, 1:27 a.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 | « no previous file | packagerEdge.py » ('j') | templates/modules.js.tmpl » ('J')
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 import errno 5 import errno
6 import io 6 import io
7 import json 7 import json
8 import os 8 import os
9 import re 9 import re
10 from StringIO import StringIO 10 from StringIO import StringIO
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 del data['_dummy'] 135 del data['_dummy']
136 manifest = json.dumps(data, sort_keys=True, indent=2) 136 manifest = json.dumps(data, sort_keys=True, indent=2)
137 137
138 return manifest.encode('utf-8') 138 return manifest.encode('utf-8')
139 139
140 140
141 def convertJS(params, files): 141 def convertJS(params, files):
142 output_files = collections.OrderedDict() 142 output_files = collections.OrderedDict()
143 args = {} 143 args = {}
144 144
145 info_module = None
Sebastian Noack 2017/03/31 10:42:01 How about merging chromeInfo.js.tmpl, geckoInfo.js
kzar 2017/03/31 14:03:01 Well I tried that and figured that repeating the m
Sebastian Noack 2017/03/31 14:50:45 We definitely should clean up that mess and target
146 info_template = {
147 'chrome': 'chromeInfo.js.tmpl',
148 'gecko-webext': 'geckoInfo.js.tmpl'
149 }.get(params['type'])
150 if info_template:
151 info_module = getTemplate(info_template).render(
152 basename=params['metadata'].get('general', 'basename'),
153 version=params['metadata'].get('general', 'version')
154 ).decode('utf-8')
155
156 for item in params['metadata'].items('convert_js'): 145 for item in params['metadata'].items('convert_js'):
157 name, value = item 146 name, value = item
158 filename, arg = re.search(r'^(.*?)(?:\[(.*)\])?$', name).groups() 147 filename, arg = re.search(r'^(.*?)(?:\[(.*)\])?$', name).groups()
159 if arg is None: 148 if arg is None:
160 output_files[filename] = (value.split(), item.source) 149 output_files[filename] = (value.split(), item.source)
161 else: 150 else:
162 args.setdefault(filename, {})[arg] = value 151 args.setdefault(filename, {})[arg] = value
163 152
164 template = getTemplate('modules.js.tmpl') 153 template = getTemplate('modules.js.tmpl')
165 154
166 for filename, (input_files, origin) in output_files.iteritems(): 155 for filename, (input_files, origin) in output_files.iteritems():
167 if '/' in filename and not files.isIncluded(filename): 156 if '/' in filename and not files.isIncluded(filename):
168 continue 157 continue
169 158
170 current_args = args.get(filename, {}) 159 current_args = args.get(filename, {})
171 current_args['autoload'] = [module for module in 160 current_args['autoload'] = [module for module in
172 current_args.get('autoload', '').split(',') 161 current_args.get('autoload', '').split(',')
173 if module != ''] 162 if module != '']
174 163
175 base_dir = os.path.dirname(origin) 164 base_dir = os.path.dirname(origin)
176 modules = [] 165 modules = []
177
178 if 'module' in current_args and info_module:
179 modules.append(('info', info_module))
180 166
181 for input_filename in input_files: 167 for input_filename in input_files:
182 module_name = os.path.splitext(os.path.basename(input_filename))[0] 168 module_name = os.path.splitext(os.path.basename(input_filename))[0]
183 prefix = os.path.basename(os.path.dirname(input_filename)) 169 prefix = os.path.basename(os.path.dirname(input_filename))
184 if prefix != 'lib': 170 if prefix != 'lib':
185 module_name = '{}_{}'.format(prefix, module_name) 171 module_name = '{}_{}'.format(prefix, module_name)
186 with open(os.path.join(base_dir, input_filename), 'r') as file: 172 with open(os.path.join(base_dir, input_filename), 'r') as file:
187 modules.append((module_name, file.read().decode('utf-8'))) 173 modules.append((module_name, file.read().decode('utf-8')))
188 files.pop(input_filename, None) 174 files.pop(input_filename, None)
189 175
190 files[filename] = template.render( 176 files[filename] = template.render(
191 args=current_args, 177 args=current_args,
178 basename=params['metadata'].get('general', 'basename'),
192 modules=modules, 179 modules=modules,
193 basename=params['metadata'].get('general', 'basename'), 180 type=params['type'],
194 version=params['metadata'].get('general', 'version') 181 version=params['metadata'].get('general', 'version')
195 ).encode('utf-8') 182 ).encode('utf-8')
196 183
197 184
198 def toJson(data): 185 def toJson(data):
199 return json.dumps( 186 return json.dumps(
200 data, ensure_ascii=False, sort_keys=True, 187 data, ensure_ascii=False, sort_keys=True,
201 indent=2, separators=(',', ': ') 188 indent=2, separators=(',', ': ')
202 ).encode('utf-8') + '\n' 189 ).encode('utf-8') + '\n'
203 190
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 files['qunit/index.html'] = createScriptPage(params, 'testIndex.html.tmp l', 395 files['qunit/index.html'] = createScriptPage(params, 'testIndex.html.tmp l',
409 ('general', 'testScripts')) 396 ('general', 'testScripts'))
410 397
411 zipdata = files.zipToString() 398 zipdata = files.zipToString()
412 signature = None 399 signature = None
413 pubkey = None 400 pubkey = None
414 if keyFile != None: 401 if keyFile != None:
415 signature = signBinary(zipdata, keyFile) 402 signature = signBinary(zipdata, keyFile)
416 pubkey = getPublicKey(keyFile) 403 pubkey = getPublicKey(keyFile)
417 writePackage(outFile, pubkey, signature, zipdata) 404 writePackage(outFile, pubkey, signature, zipdata)
LEFTRIGHT
« no previous file | packagerEdge.py » ('j') | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld