 Issue 29363565:
  Issue 4552 - Drop jshydra dependency (buildtools)  (Closed)
    
  
    Issue 29363565:
  Issue 4552 - Drop jshydra dependency (buildtools)  (Closed) 
  | Left: | ||
| Right: | 
| 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 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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 138 return manifest.encode('utf-8') | 138 return manifest.encode('utf-8') | 
| 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 output_files = collections.OrderedDict() | 147 output_files = collections.OrderedDict() | 
| 148 args = collections.defaultdict(dict) | 148 args = {} | 
| 149 | 149 | 
| 150 for item in params['metadata'].items('convert_js'): | 150 for item in params['metadata'].items('convert_js'): | 
| 
Wladimir Palant
2016/11/30 14:54:44
Nit: `for name, value in ...`? This should make th
 
kzar
2016/11/30 15:26:17
Well we need item still for `item.source`. How abo
 | |
| 151 filename, arg = re.search(r'^(.*?)(?:\[(.*)\])?$', item[0]).groups() | 151 name, value = item | 
| 152 filename, arg = re.search(r'^(.*?)(?:\[(.*)\])?$', name).groups() | |
| 152 if arg is None: | 153 if arg is None: | 
| 153 output_files[filename] = (item[1].split(), item.source) | 154 output_files[filename] = (value.split(), item.source) | 
| 154 else: | 155 else: | 
| 155 args[filename][arg] = item[1] | 156 args.setdefault(filename, {})[arg] = value | 
| 
Wladimir Palant
2016/11/30 11:39:32
Nit: Frankly, I'd prefer `args.setdefault(filename
 
kzar
2016/11/30 14:29:44
Done.
 | |
| 156 | 157 | 
| 157 template = getTemplate('modules.js.tmpl', autoEscape=True) | 158 template = getTemplate('modules.js.tmpl') | 
| 
Wladimir Palant
2016/11/30 11:39:32
Please remove autoEscape=True, this isn't an HTML
 
kzar
2016/11/30 14:29:44
Done.
 | |
| 158 | 159 | 
| 159 for filename, (input_files, origin) in output_files.iteritems(): | 160 for filename, (input_files, origin) in output_files.iteritems(): | 
| 160 if '/' in filename and not files.isIncluded(filename): | 161 if '/' in filename and not files.isIncluded(filename): | 
| 161 continue | 162 continue | 
| 162 | 163 | 
| 163 args["filename"]["autoload"] = set(args.get("autoload", "").split(",")) | 164 current_args = args.get(filename, {}) | 
| 
Wladimir Palant
2016/11/30 11:39:32
This line has three bugs, I assume that it hasn't
 
kzar
2016/11/30 14:29:44
Ouch, done.
 | |
| 165 current_args['autoload'] = [module for module in | |
| 166 current_args.get('autoload', '').split(',') | |
| 167 if module != ''] | |
| 164 | 168 | 
| 165 base_dir = os.path.dirname(origin) | 169 base_dir = os.path.dirname(origin) | 
| 166 modules = [] | 170 modules = [] | 
| 
kzar
2016/11/18 17:25:48
List of tuples instead of a dict since the module
 | |
| 167 | 171 | 
| 168 for input_filename in input_files: | 172 for input_filename in input_files: | 
| 169 module_name = os.path.splitext(os.path.basename(input_filename))[0] | 173 module_name = os.path.splitext(os.path.basename(input_filename))[0] | 
| 170 prefix = os.path.basename(os.path.dirname(input_filename)) | 174 prefix = os.path.basename(os.path.dirname(input_filename)) | 
| 171 if prefix != "lib": | 175 if prefix != 'lib': | 
| 172 module_name = "{}_{}".format(prefix, module_name) | 176 module_name = '{}_{}'.format(prefix, module_name) | 
| 173 with open(os.path.join(base_dir, input_filename), 'r') as f: | 177 with open(os.path.join(base_dir, input_filename), 'r') as file: | 
| 
Wladimir Palant
2016/11/30 11:39:32
Nit: file rather than f?
 
kzar
2016/11/30 14:29:44
Done.
 | |
| 174 modules.append((module_name, f.read().decode('utf-8'))) | 178 modules.append((module_name, file.read().decode('utf-8'))) | 
| 175 files.pop(input_filename, None) | 179 files.pop(input_filename, None) | 
| 176 | 180 | 
| 177 files[filename] = template.render( | 181 files[filename] = template.render( | 
| 178 args=args[filename], | 182 args=current_args, | 
| 179 modules=modules | 183 modules=modules | 
| 180 ).encode('utf-8') | 184 ).encode('utf-8') | 
| 181 | 185 | 
| 182 | 186 | 
| 183 def toJson(data): | 187 def toJson(data): | 
| 184 return json.dumps( | 188 return json.dumps( | 
| 185 data, ensure_ascii=False, sort_keys=True, | 189 data, ensure_ascii=False, sort_keys=True, | 
| 186 indent=2, separators=(',', ': ') | 190 indent=2, separators=(',', ': ') | 
| 187 ).encode('utf-8') + '\n' | 191 ).encode('utf-8') + '\n' | 
| 188 | 192 | 
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 394 files['qunit/index.html'] = createScriptPage(params, 'testIndex.html.tmp l', | 398 files['qunit/index.html'] = createScriptPage(params, 'testIndex.html.tmp l', | 
| 395 ('general', 'testScripts')) | 399 ('general', 'testScripts')) | 
| 396 | 400 | 
| 397 zipdata = files.zipToString() | 401 zipdata = files.zipToString() | 
| 398 signature = None | 402 signature = None | 
| 399 pubkey = None | 403 pubkey = None | 
| 400 if keyFile != None: | 404 if keyFile != None: | 
| 401 signature = signBinary(zipdata, keyFile) | 405 signature = signBinary(zipdata, keyFile) | 
| 402 pubkey = getPublicKey(keyFile) | 406 pubkey = getPublicKey(keyFile) | 
| 403 writePackage(outFile, pubkey, signature, zipdata) | 407 writePackage(outFile, pubkey, signature, zipdata) | 
| LEFT | RIGHT |