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

Side by Side Diff: packagerChrome.py

Issue 5700138072801280: Allow to specify the default icon for browserActions and pageActions in multiple sizes (Closed)
Patch Set: Created April 4, 2014, 9:03 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # coding: utf-8 1 # coding: utf-8
2 2
3 # This file is part of the Adblock Plus build tools, 3 # This file is part of the Adblock Plus build tools,
4 # Copyright (C) 2006-2014 Eyeo GmbH 4 # Copyright (C) 2006-2014 Eyeo GmbH
5 # 5 #
6 # Adblock Plus is free software: you can redistribute it and/or modify 6 # Adblock Plus is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 3 as 7 # it under the terms of the GNU General Public License version 3 as
8 # published by the Free Software Foundation. 8 # published by the Free Software Foundation.
9 # 9 #
10 # Adblock Plus is distributed in the hope that it will be useful, 10 # Adblock Plus is distributed in the hope that it will be useful,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 for file in os.listdir(baseDir): 43 for file in os.listdir(baseDir):
44 if file.endswith('.js') or file.endswith('.html') or file.endswith('.xml'): 44 if file.endswith('.js') or file.endswith('.html') or file.endswith('.xml'):
45 result.add(file) 45 result.add(file)
46 return result 46 return result
47 47
48 def processFile(path, data, params): 48 def processFile(path, data, params):
49 # We don't change anything yet, this function currently only exists here so 49 # We don't change anything yet, this function currently only exists here so
50 # that it can be overridden if necessary. 50 # that it can be overridden if necessary.
51 return data 51 return data
52 52
53 def makeIcons(files, filenames):
54 from PIL import Image
55 icons = {}
56 for filename in filenames:
57 width, height = Image.open(StringIO(files[filename])).size
58 if(width != height):
59 print >>sys.stderr, 'Warning: %s size is %ix%i, icon should be square' % (filename, width, height)
60 icons[width] = filename
61 return icons
62
53 def createManifest(params, files): 63 def createManifest(params, files):
54 template = getTemplate('manifest.json.tmpl') 64 template = getTemplate('manifest.json.tmpl')
55 templateData = dict(params) 65 templateData = dict(params)
56 66
57 baseDir = templateData['baseDir'] 67 baseDir = templateData['baseDir']
58 metadata = templateData['metadata'] 68 metadata = templateData['metadata']
59 69
60 if metadata.has_option('general', 'pageAction') and metadata.get('general', 'p ageAction') != '': 70 for opt in ('browserAction', 'pageAction'):
61 if re.search(r'\s+', metadata.get('general', 'pageAction')): 71 if not metadata.has_option('general', opt):
62 icon, popup = re.split(r'\s+', metadata.get('general', 'pageAction'), 1) 72 continue
73
74 icons = metadata.get('general', opt).split()
75 if not icons:
76 continue
77
78 if len(icons) == 1:
79 # ... = icon.png
80 icon, popup = icons[0], None
81 elif len(icons) == 2:
82 # ... = icon.png popup.html
83 icon, popup = icons
63 else: 84 else:
64 icon, popup = (metadata.get('general', 'pageAction'), None) 85 # ... = icon-19.png icon-38.png popup.html
65 templateData['pageAction'] = {'icon': icon, 'popup': popup} 86 popup = icons.pop()
87 icon = makeIcons(files, icons)
66 88
67 if metadata.has_option('general', 'browserAction') and metadata.get('general', 'browserAction') != '': 89 templateData[opt] = {'icon': icon, 'popup': popup}
68 if re.search(r'\s+', metadata.get('general', 'browserAction')):
69 icon, popup = re.split(r'\s+', metadata.get('general', 'browserAction'), 1 )
70 else:
71 icon, popup = (metadata.get('general', 'browserAction'), None)
72 templateData['browserAction'] = {'icon': icon, 'popup': popup}
73 90
74 if metadata.has_option('general', 'icons'): 91 if metadata.has_option('general', 'icons'):
75 from PIL import Image 92 templateData['icons'] = makeIcons(files, metadata.get('general', 'icons').sp lit())
76 icons = {}
77 for icon in re.split('\s+', metadata.get('general', 'icons')):
78 width, height = Image.open(StringIO(files[icon])).size
79 if(width != height):
80 print >>sys.stderr, 'Warning: %s size is %ix%i, icon should be square' % (icon, width, height)
81 icons[width] = icon
82 templateData['icons'] = icons
83 93
84 if metadata.has_option('general', 'permissions'): 94 if metadata.has_option('general', 'permissions'):
85 templateData['permissions'] = re.split(r'\s+', metadata.get('general', 'perm issions')) 95 templateData['permissions'] = re.split(r'\s+', metadata.get('general', 'perm issions'))
86 if params['experimentalAPI']: 96 if params['experimentalAPI']:
87 templateData['permissions'].append('experimental') 97 templateData['permissions'].append('experimental')
88 98
89 if metadata.has_option('general', 'backgroundScripts'): 99 if metadata.has_option('general', 'backgroundScripts'):
90 templateData['backgroundScripts'] = re.split(r'\s+', metadata.get('general', 'backgroundScripts')) 100 templateData['backgroundScripts'] = re.split(r'\s+', metadata.get('general', 'backgroundScripts'))
91 if params['devenv']: 101 if params['devenv']:
92 templateData['backgroundScripts'].append('devenvPoller__.js') 102 templateData['backgroundScripts'].append('devenvPoller__.js')
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 def shutdown_server(server): 414 def shutdown_server(server):
405 time.sleep(10) 415 time.sleep(10)
406 server.shutdown() 416 server.shutdown()
407 thread.start_new_thread(shutdown_server, (server,)) 417 thread.start_new_thread(shutdown_server, (server,))
408 server.serve_forever() 418 server.serve_forever()
409 419
410 if connections[0] == 0: 420 if connections[0] == 0:
411 print 'Warning: No incoming connections, extension probably not active in th e browser yet' 421 print 'Warning: No incoming connections, extension probably not active in th e browser yet'
412 else: 422 else:
413 print 'Handled %i connection(s)' % connections[0] 423 print 'Handled %i connection(s)' % connections[0]
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld