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

Unified 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.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « README.md ('k') | tests/README.md » ('j') | tests/README.md » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: packagerChrome.py
diff --git a/packagerChrome.py b/packagerChrome.py
index d75203d17b9e63262e69f44e5112cfc729005d8d..82fe95801ef0cd8bbaf8cf4ff59b8c0f1d3cb420 100644
--- a/packagerChrome.py
+++ b/packagerChrome.py
@@ -43,13 +43,13 @@ def processFile(path, data, params):
def makeIcons(files, filenames):
- try:
- from PIL import Image
- except ImportError:
- import Image
icons = {}
for filename in filenames:
- width, height = Image.open(StringIO(files[filename])).size
+ png_tuple = (137, 'PNG', '\r\n', '\x1a', '\n')
+ 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.
+ 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
+
+ width, height = struct.unpack('>ii', files[filename][16:24])
if(width != height):
print >>sys.stderr, 'Warning: %s size is %ix%i, icon should be square' % (filename, width, height)
icons[width] = filename
« no previous file with comments | « README.md ('k') | tests/README.md » ('j') | tests/README.md » ('J')

Powered by Google App Engine
This is Rietveld