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

Side by Side Diff: packagerChrome.py

Issue 29501558: Issue 5383 - Add tests for the Chrome and Firefox packagers (Closed)
Patch Set: Adjusting tests to recent changes Created Oct. 11, 2017, 4:01 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
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 glob 6 import glob
7 import io 7 import io
8 import json 8 import json
9 import os 9 import os
10 import re 10 import re
11 from StringIO import StringIO
12 import struct 11 import struct
13 import subprocess 12 import subprocess
14 import sys 13 import sys
15 14
16 from packager import (readMetadata, getDefaultFileName, getBuildVersion, 15 from packager import (readMetadata, getDefaultFileName, getBuildVersion,
17 getTemplate, Files) 16 getTemplate, Files)
18 17
19 defaultLocale = 'en_US' 18 defaultLocale = 'en_US'
20 19
21 20
(...skipping 15 matching lines...) Expand all
37 return result 36 return result
38 37
39 38
40 def processFile(path, data, params): 39 def processFile(path, data, params):
41 # We don't change anything yet, this function currently only exists here so 40 # We don't change anything yet, this function currently only exists here so
42 # that it can be overridden if necessary. 41 # that it can be overridden if necessary.
43 return data 42 return data
44 43
45 44
46 def makeIcons(files, filenames): 45 def makeIcons(files, filenames):
47 try:
48 from PIL import Image
49 except ImportError:
50 import Image
51 icons = {} 46 icons = {}
52 for filename in filenames: 47 for filename in filenames:
53 width, height = Image.open(StringIO(files[filename])).size 48 try:
49 magic, width, height = struct.unpack_from('>8s8xii',
50 files[filename])
51 except struct.error:
52 magic = None
53 if magic != '\x89PNG\r\n\x1a\n':
54 raise Exception(filename + ' is no valid PNG.')
54 if(width != height): 55 if(width != height):
55 print >>sys.stderr, 'Warning: %s size is %ix%i, icon should be squar e' % (filename, width, height) 56 print >>sys.stderr, 'Warning: %s size is %ix%i, icon should be squar e' % (filename, width, height)
56 icons[width] = filename 57 icons[width] = filename
57 return icons 58 return icons
58 59
59 60
60 def createScriptPage(params, template_name, script_option): 61 def createScriptPage(params, template_name, script_option):
61 template = getTemplate(template_name, autoEscape=True) 62 template = getTemplate(template_name, autoEscape=True)
62 return template.render( 63 return template.render(
63 basename=params['metadata'].get('general', 'basename'), 64 basename=params['metadata'].get('general', 'basename'),
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 191
191 cmd = ['node', os.path.join(os.path.dirname(__file__), 'webpack_runner.js')] 192 cmd = ['node', os.path.join(os.path.dirname(__file__), 'webpack_runner.js')]
192 process = subprocess.Popen(cmd, stdout=subprocess.PIPE, 193 process = subprocess.Popen(cmd, stdout=subprocess.PIPE,
193 stdin=subprocess.PIPE) 194 stdin=subprocess.PIPE)
194 output = process.communicate(input=toJson(configuration))[0] 195 output = process.communicate(input=toJson(configuration))[0]
195 if process.returncode != 0: 196 if process.returncode != 0:
196 raise subprocess.CalledProcessError(process.returncode, cmd=cmd) 197 raise subprocess.CalledProcessError(process.returncode, cmd=cmd)
197 198
198 bundles = json.loads(output) 199 bundles = json.loads(output)
199 for bundle in bundles: 200 for bundle in bundles:
200 files[bundle] = bundles[bundle].encode('utf-8') 201 files[bundle[1:]] = bundles[bundle].encode('utf-8')
201 202
202 203
203 def import_locales(params, files): 204 def import_locales(params, files):
204 for item in params['metadata'].items('import_locales'): 205 for item in params['metadata'].items('import_locales'):
205 filename, keys = item 206 filename, keys = item
206 for sourceFile in glob.glob(os.path.join(os.path.dirname(item.source), 207 for sourceFile in glob.glob(os.path.join(os.path.dirname(item.source),
207 *filename.split('/'))): 208 *filename.split('/'))):
208 locale = sourceFile.split(os.path.sep)[-2] 209 locale = sourceFile.split(os.path.sep)[-2]
209 targetFile = os.path.join('_locales', locale, 'messages.json') 210 targetFile = os.path.join('_locales', locale, 'messages.json')
210 data = json.loads(files.get(targetFile, '{}').decode('utf-8')) 211 data = json.loads(files.get(targetFile, '{}').decode('utf-8'))
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 params, 'testIndex.html.tmpl', ('general', 'testScripts') 369 params, 'testIndex.html.tmpl', ('general', 'testScripts')
369 ) 370 )
370 371
371 zipdata = files.zipToString() 372 zipdata = files.zipToString()
372 signature = None 373 signature = None
373 pubkey = None 374 pubkey = None
374 if keyFile != None: 375 if keyFile != None:
375 signature = signBinary(zipdata, keyFile) 376 signature = signBinary(zipdata, keyFile)
376 pubkey = getPublicKey(keyFile) 377 pubkey = getPublicKey(keyFile)
377 writePackage(outFile, pubkey, signature, zipdata) 378 writePackage(outFile, pubkey, signature, zipdata)
OLDNEW

Powered by Google App Engine
This is Rietveld