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

Side by Side Diff: packagerChrome.py

Issue 9257092: More build tools improvements (Closed)
Patch Set: Created Jan. 25, 2013, 10:22 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 | « 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,
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 manifest = json.dumps(data, sort_keys=True, indent=2) 105 manifest = json.dumps(data, sort_keys=True, indent=2)
106 106
107 return manifest.encode('utf-8') 107 return manifest.encode('utf-8')
108 108
109 def createPoller(params): 109 def createPoller(params):
110 template = getTemplate('chromeDevenvPoller__.js.tmpl') 110 template = getTemplate('chromeDevenvPoller__.js.tmpl')
111 return template.render(params).encode('utf-8'); 111 return template.render(params).encode('utf-8');
112 112
113 def convertJS(params, files): 113 def convertJS(params, files):
114 from jshydra.abp_rewrite import doRewrite 114 from jshydra.abp_rewrite import doRewrite
115 baseDir = params['baseDir']
116 115
117 for file, sources in params['metadata'].items('convert_js'): 116 for item in params['metadata'].items('convert_js'):
117 file, sources = item
118 baseDir = os.path.dirname(item.source)
119
118 # Make sure the file is inside an included directory 120 # Make sure the file is inside an included directory
119 if '/' in file and not files.isIncluded(file): 121 if '/' in file and not files.isIncluded(file):
120 continue 122 continue
121 123
122 sourceFiles = re.split(r'\s+', sources) 124 sourceFiles = re.split(r'\s+', sources)
123 args = [] 125 args = []
124 try: 126 try:
125 argsStart = sourceFiles.index('--arg') 127 argsStart = sourceFiles.index('--arg')
126 args = sourceFiles[argsStart + 1:] 128 args = sourceFiles[argsStart + 1:]
127 sourceFiles = sourceFiles[0:argsStart] 129 sourceFiles = sourceFiles[0:argsStart]
128 except ValueError: 130 except ValueError:
129 pass 131 pass
130 132
131 sourceFiles = map(lambda f: os.path.abspath(os.path.join(baseDir, f)), sourc eFiles) 133 sourceFiles = map(lambda f: os.path.abspath(os.path.join(baseDir, f)), sourc eFiles)
132 files[file] = doRewrite(sourceFiles, args) 134 files[file] = doRewrite(sourceFiles, args)
133 135
136 def importGeckoLocales(params, files):
137 import localeTools
138
139 localeCodeMapping = {
140 'ar': 'ar',
141 'bg': 'bg',
142 'ca': 'ca',
143 'cs': 'cs',
144 'da': 'da',
145 'de': 'de',
146 'el': 'el',
147 'en-US': 'en_US',
148 'en-GB': 'en_GB',
149 'es-ES': 'es',
150 'es-AR': 'es_419',
151 'et': 'et',
152 'fi': 'fi',
153 # '': 'fil', ???
154 'fr': 'fr',
155 'he': 'he',
156 'hi-IN': 'hi',
157 'hr': 'hr',
158 'hu': 'hu',
159 'id': 'id',
160 'it': 'it',
161 'ja': 'ja',
162 'ko': 'ko',
163 'lt': 'lt',
164 'lv': 'lv',
165 'nl': 'nl',
166 # 'nb-NO': 'no', ???
167 'pl': 'pl',
168 'pt-BR': 'pt_BR',
169 'pt-PT': 'pt_PT',
170 'ro': 'ro',
171 'ru': 'ru',
172 'sk': 'sk',
173 'sl': 'sl',
174 'sr': 'sr',
175 'sv-SE': 'sv',
176 'th': 'th',
177 'tr': 'tr',
178 'uk': 'uk',
179 'vi': 'vi',
180 'zh-CN': 'zh_CN',
181 'zh-TW': 'zh_TW',
182 }
183
184 for source, target in localeCodeMapping.iteritems():
185 targetFile = '_locales/%s/messages.json' % target
186
187 for item in params['metadata'].items('import_locales'):
188 fileName, keys = item
189 parts = map(lambda n: source if n == '*' else n, fileName.split('/'))
190 sourceFile = os.path.join(os.path.dirname(item.source), *parts)
191 incompleteMarker = os.path.join(os.path.dirname(sourceFile), '.incomplete' )
192 if not os.path.exists(sourceFile) or os.path.exists(incompleteMarker):
193 continue
194
195 data = {}
196 if targetFile in files:
197 data = json.loads(files[targetFile].decode('utf-8'))
198
199 try:
200 sourceData = localeTools.readFile(sourceFile)
201 for stringID in re.split(r'\s+', keys):
202 noMangling = False
203 if stringID.startswith('='):
204 stringID = stringID[1:]
205 noMangling = True
206
207 if stringID in sourceData:
208 if noMangling:
209 key = stringID
210 else:
211 key = re.sub(r'\..*', '', parts[-1]) + '_' + re.sub(r'\W', '_', st ringID)
212 if key in data:
213 print 'Warning: locale string %s defined multiple times' % key
214 data[key] = {'message': sourceData[stringID]}
215 except Exception, e:
216 print 'Warning: error importing locale data from %s: %s' % (sourceFile, e)
217
218 files[targetFile] = json.dumps(data, ensure_ascii=False, sort_keys=True,
219 indent=2, separators=(',', ': ')).encode('utf-8') + '\n'
220
134 def signBinary(zipdata, keyFile): 221 def signBinary(zipdata, keyFile):
135 import M2Crypto 222 import M2Crypto
136 if not os.path.exists(keyFile): 223 if not os.path.exists(keyFile):
137 M2Crypto.RSA.gen_key(1024, 65537, callback=lambda x: None).save_key(keyFile, cipher=None) 224 M2Crypto.RSA.gen_key(1024, 65537, callback=lambda x: None).save_key(keyFile, cipher=None)
138 key = M2Crypto.EVP.load_key(keyFile) 225 key = M2Crypto.EVP.load_key(keyFile)
139 key.sign_init() 226 key.sign_init()
140 key.sign_update(zipdata) 227 key.sign_update(zipdata)
141 return key.final() 228 return key.final()
142 229
143 def getPublicKey(keyFile): 230 def getPublicKey(keyFile):
(...skipping 23 matching lines...) Expand all
167 'releaseBuild': releaseBuild, 254 'releaseBuild': releaseBuild,
168 'version': version, 255 'version': version,
169 'experimentalAPI': experimentalAPI, 256 'experimentalAPI': experimentalAPI,
170 'devenv': devenv, 257 'devenv': devenv,
171 'metadata': metadata, 258 'metadata': metadata,
172 } 259 }
173 260
174 files = Files(getPackageFiles(params), getIgnoredFiles(params)) 261 files = Files(getPackageFiles(params), getIgnoredFiles(params))
175 files['manifest.json'] = createManifest(params) 262 files['manifest.json'] = createManifest(params)
176 if metadata.has_section('mapping'): 263 if metadata.has_section('mapping'):
177 files.readMappedFiles(baseDir, metadata.items('mapping')) 264 files.readMappedFiles(metadata.items('mapping'))
178 files.read(baseDir) 265 files.read(baseDir)
179 266
180 if metadata.has_section('convert_js'): 267 if metadata.has_section('convert_js'):
181 convertJS(params, files) 268 convertJS(params, files)
182 269
270 if metadata.has_section('import_locales'):
271 importGeckoLocales(params, files)
272
183 if devenv: 273 if devenv:
184 files['devenvPoller__.js'] = createPoller(params) 274 files['devenvPoller__.js'] = createPoller(params)
185 275
186 zipdata = files.zipToString() 276 zipdata = files.zipToString()
187 signature = None 277 signature = None
188 pubkey = None 278 pubkey = None
189 if keyFile != None: 279 if keyFile != None:
190 signature = signBinary(zipdata, keyFile) 280 signature = signBinary(zipdata, keyFile)
191 pubkey = getPublicKey(keyFile) 281 pubkey = getPublicKey(keyFile)
192 writePackage(outFile, pubkey, signature, zipdata) 282 writePackage(outFile, pubkey, signature, zipdata)
(...skipping 23 matching lines...) Expand all
216 def shutdown_server(server): 306 def shutdown_server(server):
217 time.sleep(10) 307 time.sleep(10)
218 server.shutdown() 308 server.shutdown()
219 thread.start_new_thread(shutdown_server, (server,)) 309 thread.start_new_thread(shutdown_server, (server,))
220 server.serve_forever() 310 server.serve_forever()
221 311
222 if connections[0] == 0: 312 if connections[0] == 0:
223 print 'Warning: No incoming connections, extension probably not active in th e browser yet' 313 print 'Warning: No incoming connections, extension probably not active in th e browser yet'
224 else: 314 else:
225 print 'Handled %i connection(s)' % connections[0] 315 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