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

Side by Side Diff: packagerChrome.py

Issue 9158140: Packager refactoring, moved common packager code into separate module (Closed)
Patch Set: Created Jan. 10, 2013, 7:57 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
« no previous file with comments | « packager.py ('k') | packagerGecko.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 # 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-2012 Eyeo GmbH 4 # Copyright (C) 2006-2012 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,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details. 13 # GNU General Public License for more details.
14 # 14 #
15 # You should have received a copy of the GNU General Public License 15 # You should have received a copy of the GNU General Public License
16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
17 17
18 import sys, os, subprocess, re, json, codecs, struct, jinja2, buildtools 18 import sys, os, re, json, struct
19 from ConfigParser import SafeConfigParser
20 from StringIO import StringIO 19 from StringIO import StringIO
21 from zipfile import ZipFile, ZIP_DEFLATED 20 from zipfile import ZipFile, ZIP_DEFLATED
22 21
22 from packager import getDefaultFileName, readMetadata, getBuildVersion, getTempl ate
23
23 defaultLocale = 'en_US' 24 defaultLocale = 'en_US'
24 25
25 def getDefaultFileName(baseDir, metadata, ext):
26 return os.path.join(baseDir, '%s-%s.%s' % (metadata.get('general', 'basename') , metadata.get('general', 'version'), ext))
27
28 def getMetadataPath(baseDir):
29 return os.path.join(baseDir, 'metadata')
30
31 def getBuildNum(baseDir):
32 try:
33 (result, dummy) = subprocess.Popen(['hg', 'id', '-n'], stdout=subprocess.PIP E).communicate()
34 return re.sub(r'\D', '', result)
35 except Exception:
36 return '0'
37
38 def getIgnoredFiles(params): 26 def getIgnoredFiles(params):
39 return ['store.description'] 27 return ['store.description']
40 28
41 def readMetadata(baseDir):
42 metadata = SafeConfigParser()
43 metadata.optionxform = str
44 file = codecs.open(getMetadataPath(baseDir), 'rb', encoding='utf-8')
45 metadata.readfp(file)
46 file.close()
47 return metadata
48
49 def getPackageFiles(params): 29 def getPackageFiles(params):
50 baseDir = params['baseDir'] 30 baseDir = params['baseDir']
51 for file in ('_locales', 'icons', 'jquery-ui', 'lib', 'skin', 'ui'): 31 for file in ('_locales', 'icons', 'jquery-ui', 'lib', 'skin', 'ui'):
52 yield os.path.join(baseDir, file) 32 yield os.path.join(baseDir, file)
53 if params['devenv']: 33 if params['devenv']:
54 yield os.path.join(baseDir, 'qunit') 34 yield os.path.join(baseDir, 'qunit')
55 for file in os.listdir(baseDir): 35 for file in os.listdir(baseDir):
56 if file.endswith('.js') or file.endswith('.html') or file.endswith('.xml'): 36 if file.endswith('.js') or file.endswith('.html') or file.endswith('.xml'):
57 yield os.path.join(baseDir, file) 37 yield os.path.join(baseDir, file)
58 38
59 def createManifest(params): 39 def createManifest(params):
60 env = jinja2.Environment(loader=jinja2.FileSystemLoader(buildtools.__path__[0] )) 40 template = getTemplate('manifest.json.tmpl')
61 env.filters.update({'json': json.dumps})
62 template = env.get_template('manifest.json.tmpl')
63 templateData = dict(params) 41 templateData = dict(params)
64 42
65 baseDir = templateData['baseDir'] 43 baseDir = templateData['baseDir']
66 metadata = templateData['metadata'] 44 metadata = templateData['metadata']
67 45
68 if metadata.has_option('general', 'pageAction'): 46 if metadata.has_option('general', 'pageAction'):
69 icon, popup = re.split(r'\s+', metadata.get('general', 'pageAction'), 1) 47 icon, popup = re.split(r'\s+', metadata.get('general', 'pageAction'), 1)
70 templateData['pageAction'] = {'icon': icon, 'popup': popup} 48 templateData['pageAction'] = {'icon': icon, 'popup': popup}
71 49
72 if metadata.has_option('general', 'icons'): 50 if metadata.has_option('general', 'icons'):
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 # Normalize JSON structure 92 # Normalize JSON structure
115 licenseComment = re.compile(r'/\*.*?\*/', re.S) 93 licenseComment = re.compile(r'/\*.*?\*/', re.S)
116 data = json.loads(re.sub(licenseComment, '', manifest, 1)) 94 data = json.loads(re.sub(licenseComment, '', manifest, 1))
117 if '_dummy' in data: 95 if '_dummy' in data:
118 del data['_dummy'] 96 del data['_dummy']
119 manifest = json.dumps(data, sort_keys=True, indent=2) 97 manifest = json.dumps(data, sort_keys=True, indent=2)
120 98
121 return manifest.encode('utf-8') 99 return manifest.encode('utf-8')
122 100
123 def createPoller(params): 101 def createPoller(params):
124 env = jinja2.Environment(loader=jinja2.FileSystemLoader(buildtools.__path__[0] )) 102 template = getTemplate('chromeDevenvPoller__.js.tmpl')
125 env.filters.update({'json': json.dumps})
126 template = env.get_template('chromeDevenvPoller__.js.tmpl')
127 return template.render(params).encode('utf-8'); 103 return template.render(params).encode('utf-8');
128 104
129 def readFile(params, files, path): 105 def readFile(params, files, path):
130 ignoredFiles = getIgnoredFiles(params) 106 ignoredFiles = getIgnoredFiles(params)
131 if os.path.isdir(path): 107 if os.path.isdir(path):
132 for file in os.listdir(path): 108 for file in os.listdir(path):
133 if file in ignoredFiles: 109 if file in ignoredFiles:
134 continue 110 continue
135 readFile(params, files, os.path.join(path, file)) 111 readFile(params, files, os.path.join(path, file))
136 else: 112 else:
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 else: 168 else:
193 file = outputFile 169 file = outputFile
194 if pubkey != None and signature != None: 170 if pubkey != None and signature != None:
195 file.write(struct.pack('<4sIII', 'Cr24', 2, len(pubkey), len(signature))) 171 file.write(struct.pack('<4sIII', 'Cr24', 2, len(pubkey), len(signature)))
196 file.write(pubkey) 172 file.write(pubkey)
197 file.write(signature) 173 file.write(signature)
198 file.write(zipdata) 174 file.write(zipdata)
199 175
200 def createBuild(baseDir, outFile=None, buildNum=None, releaseBuild=False, keyFil e=None, experimentalAPI=False, devenv=False): 176 def createBuild(baseDir, outFile=None, buildNum=None, releaseBuild=False, keyFil e=None, experimentalAPI=False, devenv=False):
201 metadata = readMetadata(baseDir) 177 metadata = readMetadata(baseDir)
178 version = getBuildVersion(baseDir, metadata, releaseBuild, buildNum)
179
202 if outFile == None: 180 if outFile == None:
203 outFile = getDefaultFileName(baseDir, metadata, 'crx' if keyFile else 'zip') 181 outFile = getDefaultFileName(baseDir, metadata, version, 'crx' if keyFile el se 'zip')
204
205 version = metadata.get('general', 'version')
206 if not releaseBuild:
207 if buildNum == None:
208 buildNum = getBuildNum(baseDir)
209 if len(buildNum) > 0:
210 while version.count('.') < 2:
211 version += '.0'
212 version += '.' + buildNum
213 182
214 params = { 183 params = {
215 'baseDir': baseDir, 184 'baseDir': baseDir,
216 'releaseBuild': releaseBuild, 185 'releaseBuild': releaseBuild,
217 'version': version, 186 'version': version,
218 'experimentalAPI': experimentalAPI, 187 'experimentalAPI': experimentalAPI,
219 'devenv': devenv, 188 'devenv': devenv,
220 'metadata': metadata, 189 'metadata': metadata,
221 } 190 }
222 191
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 def shutdown_server(server): 232 def shutdown_server(server):
264 time.sleep(10) 233 time.sleep(10)
265 server.shutdown() 234 server.shutdown()
266 thread.start_new_thread(shutdown_server, (server,)) 235 thread.start_new_thread(shutdown_server, (server,))
267 server.serve_forever() 236 server.serve_forever()
268 237
269 if connections[0] == 0: 238 if connections[0] == 0:
270 print 'Warning: No incoming connections, extension probably not active in th e browser yet' 239 print 'Warning: No incoming connections, extension probably not active in th e browser yet'
271 else: 240 else:
272 print 'Handled %i connection(s)' % connections[0] 241 print 'Handled %i connection(s)' % connections[0]
OLDNEW
« no previous file with comments | « packager.py ('k') | packagerGecko.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld