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

Delta Between Two Patch Sets: packagerChrome.py

Issue 29350281: Issue 4047 - Improved configuration of converted JS files (Closed)
Left Patch Set: Avoid error if input arguments seens before input files Created Aug. 30, 2016, 12:37 p.m.
Right Patch Set: Use defaultdict(list) instead lambda Created Aug. 30, 2016, 2:22 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 | « no previous file | no next file » | 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 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
11 import struct 11 import struct
12 import sys 12 import sys
13 from collections import OrderedDict 13 import collections
14 14
15 import packager 15 import packager
16 from packager import readMetadata, getMetadataPath, getDefaultFileName, getBuild Version, getTemplate, Files 16 from packager import readMetadata, getMetadataPath, getDefaultFileName, getBuild Version, getTemplate, Files
17 17
18 defaultLocale = 'en_US' 18 defaultLocale = 'en_US'
19 19
20 20
21 def getIgnoredFiles(params): 21 def getIgnoredFiles(params):
22 return {'store.description'} 22 return {'store.description'}
23 23
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 139
140 140
141 def createInfoModule(params): 141 def createInfoModule(params):
142 template = getTemplate('chromeInfo.js.tmpl') 142 template = getTemplate('chromeInfo.js.tmpl')
143 return template.render(params).encode('utf-8') 143 return template.render(params).encode('utf-8')
144 144
145 145
146 def convertJS(params, files): 146 def convertJS(params, files):
147 from jshydra.abp_rewrite import rewrite_js 147 from jshydra.abp_rewrite import rewrite_js
148 148
149 output_files = OrderedDict() 149 output_files = collections.OrderedDict()
150 args = {} 150 args = collections.defaultdict(list)
151
151 for item in params['metadata'].items('convert_js'): 152 for item in params['metadata'].items('convert_js'):
152 filename, arg = re.search(r'^(.*?)(?:\[(.*)\])?$', item[0]).groups() 153 filename, arg = re.search(r'^(.*?)(?:\[(.*)\])?$', item[0]).groups()
153 if arg is None: 154 if arg is None:
154 output_files[filename] = (item[1].split(), item.source) 155 output_files[filename] = (item[1].split(), item.source)
155 else: 156 else:
156 args.setdefault(filename, []).append('{}={}'.format(arg, item[1])) 157 args[filename].append('{}={}'.format(arg, item[1]))
157 158
158 for filename, (input_files, origin) in output_files.iteritems(): 159 for filename, (input_files, origin) in output_files.iteritems():
159 if '/' in filename and not files.isIncluded(filename): 160 if '/' in filename and not files.isIncluded(filename):
160 continue 161 continue
161 162
162 base_dir = os.path.dirname(origin) 163 base_dir = os.path.dirname(origin)
163 jshydra_args = ['--arg', ' '.join(args.get(filename, []))] 164 jshydra_args = ['--arg', ' '.join(args[filename])]
164 165
165 for input_filename in input_files: 166 for input_filename in input_files:
166 jshydra_args.append(os.path.join(base_dir, input_filename)) 167 jshydra_args.append(os.path.join(base_dir, input_filename))
167 files.pop(input_filename, None) 168 files.pop(input_filename, None)
168 169
169 files[filename] = rewrite_js(jshydra_args) 170 files[filename] = rewrite_js(jshydra_args)
170 171
171 172
172 def toJson(data): 173 def toJson(data):
173 return json.dumps( 174 return json.dumps(
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 files['qunit/index.html'] = createScriptPage(params, 'testIndex.html.tmp l', 384 files['qunit/index.html'] = createScriptPage(params, 'testIndex.html.tmp l',
384 ('general', 'testScripts')) 385 ('general', 'testScripts'))
385 386
386 zipdata = files.zipToString() 387 zipdata = files.zipToString()
387 signature = None 388 signature = None
388 pubkey = None 389 pubkey = None
389 if keyFile != None: 390 if keyFile != None:
390 signature = signBinary(zipdata, keyFile) 391 signature = signBinary(zipdata, keyFile)
391 pubkey = getPublicKey(keyFile) 392 pubkey = getPublicKey(keyFile)
392 writePackage(outFile, pubkey, signature, zipdata) 393 writePackage(outFile, pubkey, signature, zipdata)
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld