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: NO CHANGE Rebasing against #4720 @ PS 4 Created Oct. 18, 2017, 11:18 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 | « package.json ('k') | packagerEdge.py » ('j') | no next file with comments »
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 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
14 import random
15 15
16 from packager import (readMetadata, getDefaultFileName, getBuildVersion, 16 from packager import (readMetadata, getDefaultFileName, getBuildVersion,
17 getTemplate, Files) 17 getTemplate, Files)
18 18
19 defaultLocale = 'en_US' 19 defaultLocale = 'en_US'
20 20
21 21
22 def getIgnoredFiles(params): 22 def getIgnoredFiles(params):
23 return {'store.description'} 23 return {'store.description'}
24 24
(...skipping 12 matching lines...) Expand all
37 return result 37 return result
38 38
39 39
40 def processFile(path, data, params): 40 def processFile(path, data, params):
41 # We don't change anything yet, this function currently only exists here so 41 # We don't change anything yet, this function currently only exists here so
42 # that it can be overridden if necessary. 42 # that it can be overridden if necessary.
43 return data 43 return data
44 44
45 45
46 def makeIcons(files, filenames): 46 def makeIcons(files, filenames):
47 try:
48 from PIL import Image
49 except ImportError:
50 import Image
51 icons = {} 47 icons = {}
52 for filename in filenames: 48 for filename in filenames:
53 width, height = Image.open(StringIO(files[filename])).size 49 try:
50 magic, width, height = struct.unpack_from('>8s8xii',
51 files[filename])
52 except struct.error:
53 magic = None
54 if magic != '\x89PNG\r\n\x1a\n':
55 raise Exception(filename + ' is no valid PNG.')
54 if(width != height): 56 if(width != height):
55 print >>sys.stderr, 'Warning: %s size is %ix%i, icon should be squar e' % (filename, width, height) 57 print >>sys.stderr, 'Warning: %s size is %ix%i, icon should be squar e' % (filename, width, height)
56 icons[width] = filename 58 icons[width] = filename
57 return icons 59 return icons
58 60
59 61
60 def createScriptPage(params, template_name, script_option): 62 def createScriptPage(params, template_name, script_option):
61 template = getTemplate(template_name, autoEscape=True) 63 template = getTemplate(template_name, autoEscape=True)
62 return template.render( 64 return template.render(
63 basename=params['metadata'].get('general', 'basename'), 65 basename=params['metadata'].get('general', 'basename'),
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 file = open(outputFile, 'wb') 314 file = open(outputFile, 'wb')
313 else: 315 else:
314 file = outputFile 316 file = outputFile
315 if pubkey != None and signature != None: 317 if pubkey != None and signature != None:
316 file.write(struct.pack('<4sIII', 'Cr24', 2, len(pubkey), len(signature)) ) 318 file.write(struct.pack('<4sIII', 'Cr24', 2, len(pubkey), len(signature)) )
317 file.write(pubkey) 319 file.write(pubkey)
318 file.write(signature) 320 file.write(signature)
319 file.write(zipdata) 321 file.write(zipdata)
320 322
321 323
324 def add_devenv_requirements(files, metadata, params):
325 files.read(os.path.join(os.path.dirname(__file__),
326 'chromeDevenvPoller__.js'),
327 relpath='devenvPoller__.js')
328 files['devenvVersion__'] = str(random.random())
329
330 if metadata.has_option('general', 'testScripts'):
331 files['qunit/index.html'] = createScriptPage(
332 params, 'testIndex.html.tmpl', ('general', 'testScripts')
333 )
334
335
322 def createBuild(baseDir, type='chrome', outFile=None, buildNum=None, releaseBuil d=False, keyFile=None, devenv=False): 336 def createBuild(baseDir, type='chrome', outFile=None, buildNum=None, releaseBuil d=False, keyFile=None, devenv=False):
323 metadata = readMetadata(baseDir, type) 337 metadata = readMetadata(baseDir, type)
324 version = getBuildVersion(baseDir, metadata, releaseBuild, buildNum) 338 version = getBuildVersion(baseDir, metadata, releaseBuild, buildNum)
325 339
326 if outFile == None: 340 if outFile == None:
327 if type == 'gecko': 341 if type == 'gecko':
328 file_extension = 'xpi' 342 file_extension = 'xpi'
329 else: 343 else:
330 file_extension = 'crx' if keyFile else 'zip' 344 file_extension = 'crx' if keyFile else 'zip'
331 outFile = getDefaultFileName(metadata, version, file_extension) 345 outFile = getDefaultFileName(metadata, version, file_extension)
(...skipping 24 matching lines...) Expand all
356 ) 370 )
357 371
358 if metadata.has_section('import_locales'): 372 if metadata.has_section('import_locales'):
359 import_locales(params, files) 373 import_locales(params, files)
360 374
361 files['manifest.json'] = createManifest(params, files) 375 files['manifest.json'] = createManifest(params, files)
362 if type == 'chrome': 376 if type == 'chrome':
363 fix_translations_for_chrome(files) 377 fix_translations_for_chrome(files)
364 378
365 if devenv: 379 if devenv:
366 import buildtools 380 add_devenv_requirements(files, metadata, params)
367 import random
368 files.read(os.path.join(buildtools.__path__[0], 'chromeDevenvPoller__.js '), relpath='devenvPoller__.js')
369 files['devenvVersion__'] = str(random.random())
370
371 if metadata.has_option('general', 'testScripts'):
372 files['qunit/index.html'] = createScriptPage(
373 params, 'testIndex.html.tmpl', ('general', 'testScripts')
374 )
375 381
376 zipdata = files.zipToString() 382 zipdata = files.zipToString()
377 signature = None 383 signature = None
378 pubkey = None 384 pubkey = None
379 if keyFile != None: 385 if keyFile != None:
380 signature = signBinary(zipdata, keyFile) 386 signature = signBinary(zipdata, keyFile)
381 pubkey = getPublicKey(keyFile) 387 pubkey = getPublicKey(keyFile)
382 writePackage(outFile, pubkey, signature, zipdata) 388 writePackage(outFile, pubkey, signature, zipdata)
OLDNEW
« no previous file with comments | « package.json ('k') | packagerEdge.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld