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: Asserting PNGs Created Sept. 19, 2017, 10:02 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « README.md ('k') | tests/README.md » ('j') | tests/README.md » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 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 25 matching lines...) Expand all
36 return result 36 return result
37 37
38 38
39 def processFile(path, data, params): 39 def processFile(path, data, params):
40 # 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
41 # that it can be overridden if necessary. 41 # that it can be overridden if necessary.
42 return data 42 return data
43 43
44 44
45 def makeIcons(files, filenames): 45 def makeIcons(files, filenames):
46 try:
47 from PIL import Image
48 except ImportError:
49 import Image
50 icons = {} 46 icons = {}
51 for filename in filenames: 47 for filename in filenames:
52 width, height = Image.open(StringIO(files[filename])).size 48 png_tuple = (137, 'PNG', '\r\n', '\x1a', '\n')
49 header = struct.unpack('>B3s2scc', files[filename][0:8])
Sebastian Noack 2017/09/20 00:58:00 There is no reason to split the magic number into
tlucas 2017/09/20 08:52:49 Done.
50 assert header == png_tuple, '{} is no valid PNG.'.format(filename)
Vasily Kuznetsov 2017/09/19 17:52:26 Python's `assert` is not a reliable method to test
Sebastian Noack 2017/09/20 00:58:00 I'd like to add that the general idea of programmi
tlucas 2017/09/20 08:52:49 Thanks for the insight - restructured this code al
51
52 width, height = struct.unpack('>ii', files[filename][16:24])
53 if(width != height): 53 if(width != height):
54 print >>sys.stderr, 'Warning: %s size is %ix%i, icon should be squar e' % (filename, width, height) 54 print >>sys.stderr, 'Warning: %s size is %ix%i, icon should be squar e' % (filename, width, height)
55 icons[width] = filename 55 icons[width] = filename
56 return icons 56 return icons
57 57
58 58
59 def createScriptPage(params, template_name, script_option): 59 def createScriptPage(params, template_name, script_option):
60 template = getTemplate(template_name, autoEscape=True) 60 template = getTemplate(template_name, autoEscape=True)
61 return template.render( 61 return template.render(
62 basename=params['metadata'].get('general', 'basename'), 62 basename=params['metadata'].get('general', 'basename'),
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 params, 'testIndex.html.tmpl', ('general', 'testScripts') 416 params, 'testIndex.html.tmpl', ('general', 'testScripts')
417 ) 417 )
418 418
419 zipdata = files.zipToString() 419 zipdata = files.zipToString()
420 signature = None 420 signature = None
421 pubkey = None 421 pubkey = None
422 if keyFile != None: 422 if keyFile != None:
423 signature = signBinary(zipdata, keyFile) 423 signature = signBinary(zipdata, keyFile)
424 pubkey = getPublicKey(keyFile) 424 pubkey = getPublicKey(keyFile)
425 writePackage(outFile, pubkey, signature, zipdata) 425 writePackage(outFile, pubkey, signature, zipdata)
OLDNEW
« no previous file with comments | « README.md ('k') | tests/README.md » ('j') | tests/README.md » ('J')

Powered by Google App Engine
This is Rietveld