Left: | ||
Right: |
OLD | NEW |
---|---|
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 os | 5 import os |
6 import sys | 6 import sys |
7 import re | 7 import re |
8 import subprocess | 8 import subprocess |
9 import shutil | 9 import shutil |
10 import buildtools | |
11 from getopt import getopt, GetoptError | 10 from getopt import getopt, GetoptError |
12 from StringIO import StringIO | 11 from StringIO import StringIO |
13 from zipfile import ZipFile | 12 from zipfile import ZipFile |
14 | 13 |
15 knownTypes = ('gecko', 'gecko-webext', 'chrome', 'safari', 'generic', 'edge') | 14 knownTypes = ('gecko-webext', 'chrome', 'safari', 'generic', 'edge') |
16 | 15 |
17 | 16 |
18 class Command(object): | 17 class Command(object): |
19 name = property(lambda self: self._name) | 18 name = property(lambda self: self._name) |
20 shortDescription = property( | 19 shortDescription = property( |
21 lambda self: self._shortDescription, | 20 lambda self: self._shortDescription, |
22 lambda self, value: self.__dict__.update({'_shortDescription': value}) | 21 lambda self, value: self.__dict__.update({'_shortDescription': value}) |
23 ) | 22 ) |
24 description = property( | 23 description = property( |
25 lambda self: self._description, | 24 lambda self: self._description, |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
171 'name': command.name, | 170 'name': command.name, |
172 'params': command.params, | 171 'params': command.params, |
173 'description': description, | 172 'description': description, |
174 'options': '\n'.join(options) | 173 'options': '\n'.join(options) |
175 } | 174 } |
176 | 175 |
177 | 176 |
178 def runBuild(baseDir, scriptName, opts, args, type): | 177 def runBuild(baseDir, scriptName, opts, args, type): |
179 kwargs = {} | 178 kwargs = {} |
180 for option, value in opts: | 179 for option, value in opts: |
181 if option in {'-l', '--locales'} and type == 'gecko': | 180 if option in {'-b', '--build'}: |
182 kwargs['locales'] = value.split(',') | |
183 elif option in {'-b', '--build'}: | |
184 kwargs['buildNum'] = value | 181 kwargs['buildNum'] = value |
185 no_gecko_build = type not in {'gecko', 'gecko-webext'} | 182 if type != 'gecko-webext' and not kwargs['buildNum'].isdigit(): |
186 if no_gecko_build and not kwargs['buildNum'].isdigit(): | |
187 raise TypeError('Build number must be numerical') | 183 raise TypeError('Build number must be numerical') |
188 elif option in {'-k', '--key'}: | 184 elif option in {'-k', '--key'}: |
189 kwargs['keyFile'] = value | 185 kwargs['keyFile'] = value |
190 elif option in {'-m', '--multi-compartment'} and type == 'gecko': | |
191 kwargs['multicompartment'] = True | |
192 elif option in {'-r', '--release'}: | 186 elif option in {'-r', '--release'}: |
193 kwargs['releaseBuild'] = True | 187 kwargs['releaseBuild'] = True |
194 if len(args) > 0: | 188 if len(args) > 0: |
195 kwargs['outFile'] = args[0] | 189 kwargs['outFile'] = args[0] |
196 | 190 |
197 if type == 'gecko': | 191 if type in {'chrome', 'gecko-webext'}: |
198 import buildtools.packagerGecko as packager | |
199 elif type in {'chrome', 'gecko-webext'}: | |
200 import buildtools.packagerChrome as packager | 192 import buildtools.packagerChrome as packager |
201 elif type == 'safari': | 193 elif type == 'safari': |
202 import buildtools.packagerSafari as packager | 194 import buildtools.packagerSafari as packager |
203 elif type == 'edge': | 195 elif type == 'edge': |
204 import buildtools.packagerEdge as packager | 196 import buildtools.packagerEdge as packager |
205 | 197 |
206 packager.createBuild(baseDir, type=type, **kwargs) | 198 packager.createBuild(baseDir, type=type, **kwargs) |
207 | 199 |
208 | 200 |
209 def runAutoInstall(baseDir, scriptName, opts, args, type): | |
210 if len(args) == 0: | |
211 print 'Port of the Extension Auto-Installer needs to be specified' | |
212 usage(scriptName, type, 'autoinstall') | |
213 return | |
214 | |
215 multicompartment = False | |
216 for option, value in opts: | |
217 if option in ('-m', '--multi-compartment'): | |
218 multicompartment = True | |
219 | |
220 if ':' in args[0]: | |
221 host, port = args[0].rsplit(':', 1) | |
222 else: | |
223 host, port = ('localhost', args[0]) | |
224 | |
225 import buildtools.packagerGecko as packager | |
226 packager.autoInstall(baseDir, type, host, port, multicompartment=multicompar tment) | |
227 | |
228 | |
229 def createDevEnv(baseDir, scriptName, opts, args, type): | 201 def createDevEnv(baseDir, scriptName, opts, args, type): |
230 if type == 'safari': | 202 if type == 'safari': |
231 import buildtools.packagerSafari as packager | 203 import buildtools.packagerSafari as packager |
232 else: | 204 else: |
233 import buildtools.packagerChrome as packager | 205 import buildtools.packagerChrome as packager |
234 | 206 |
235 file = StringIO() | 207 file = StringIO() |
236 packager.createBuild(baseDir, type=type, outFile=file, devenv=True, releaseB uild=True) | 208 packager.createBuild(baseDir, type=type, outFile=file, devenv=True, releaseB uild=True) |
237 | 209 |
238 from buildtools.packager import getDevEnvPath | 210 from buildtools.packager import getDevEnvPath |
239 devenv_dir = getDevEnvPath(baseDir, type) | 211 devenv_dir = getDevEnvPath(baseDir, type) |
240 | 212 |
241 shutil.rmtree(devenv_dir, ignore_errors=True) | 213 shutil.rmtree(devenv_dir, ignore_errors=True) |
242 | 214 |
243 file.seek(0) | 215 file.seek(0) |
244 with ZipFile(file, 'r') as zip_file: | 216 with ZipFile(file, 'r') as zip_file: |
245 zip_file.extractall(devenv_dir) | 217 zip_file.extractall(devenv_dir) |
246 | 218 |
247 | 219 |
248 def readLocaleConfig(baseDir, type, metadata): | 220 def readLocaleConfig(baseDir, type, metadata): |
249 if type == 'gecko': | 221 if type != 'generic': |
Vasily Kuznetsov
2017/10/10 12:44:33
We could swap the branches of this if statement to
tlucas
2017/10/10 12:50:13
Well, imho the "not generic" platforms are those m
| |
250 import buildtools.packagerGecko as packager | |
251 localeDir = packager.getLocalesDir(baseDir) | |
252 localeConfig = { | |
253 'name_format': 'BCP-47', | |
254 'file_format': 'gecko-dtd', | |
255 'default_locale': packager.defaultLocale | |
256 } | |
257 elif type in {'chrome', 'gecko-webext'}: | |
258 import buildtools.packagerChrome as packager | 222 import buildtools.packagerChrome as packager |
259 localeDir = os.path.join(baseDir, '_locales') | 223 localeDir = os.path.join(baseDir, '_locales') |
260 localeConfig = { | 224 localeConfig = { |
261 'name_format': 'ISO-15897', | |
262 'file_format': 'chrome-json', | |
263 'default_locale': packager.defaultLocale, | 225 'default_locale': packager.defaultLocale, |
264 } | 226 } |
265 else: | 227 else: |
266 localeDir = os.path.join( | 228 localeDir = os.path.join( |
267 baseDir, *metadata.get('locales', 'base_path').split('/') | 229 baseDir, *metadata.get('locales', 'base_path').split('/') |
268 ) | 230 ) |
269 localeConfig = { | 231 localeConfig = { |
270 'name_format': metadata.get('locales', 'name_format'), | |
271 'file_format': metadata.get('locales', 'file_format'), | |
272 'default_locale': metadata.get('locales', 'default_locale') | 232 'default_locale': metadata.get('locales', 'default_locale') |
273 } | 233 } |
274 | 234 |
275 localeConfig['base_path'] = localeDir | 235 localeConfig['base_path'] = localeDir |
276 | 236 |
277 locales = [(locale, os.path.join(localeDir, locale)) | 237 locales = [(locale.replace('_', '-'), os.path.join(localeDir, locale)) |
278 for locale in os.listdir(localeDir)] | 238 for locale in os.listdir(localeDir)] |
279 if localeConfig['name_format'] == 'ISO-15897': | |
280 locales = [(locale.replace('_', '-'), localePath) | |
281 for locale, localePath in locales] | |
282 localeConfig['locales'] = dict(locales) | 239 localeConfig['locales'] = dict(locales) |
283 | 240 |
284 return localeConfig | 241 return localeConfig |
285 | 242 |
286 | 243 |
287 def setupTranslations(baseDir, scriptName, opts, args, type): | 244 def setupTranslations(baseDir, scriptName, opts, args, type): |
288 if len(args) < 1: | 245 if len(args) < 1: |
289 print 'Project key is required to update translation master files.' | 246 print 'Project key is required to update translation master files.' |
290 usage(scriptName, type, 'setuptrans') | 247 usage(scriptName, type, 'setuptrans') |
291 return | 248 return |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
356 from buildtools.packager import readMetadata | 313 from buildtools.packager import readMetadata |
357 metadata = readMetadata(baseDir, type) | 314 metadata = readMetadata(baseDir, type) |
358 | 315 |
359 basename = metadata.get('general', 'basename') | 316 basename = metadata.get('general', 'basename') |
360 localeConfig = readLocaleConfig(baseDir, type, metadata) | 317 localeConfig = readLocaleConfig(baseDir, type, metadata) |
361 | 318 |
362 import buildtools.localeTools as localeTools | 319 import buildtools.localeTools as localeTools |
363 localeTools.getTranslations(localeConfig, basename, key) | 320 localeTools.getTranslations(localeConfig, basename, key) |
364 | 321 |
365 | 322 |
366 def showDescriptions(baseDir, scriptName, opts, args, type): | |
367 locales = None | |
368 for option, value in opts: | |
369 if option in ('-l', '--locales'): | |
370 locales = value.split(',') | |
371 | |
372 import buildtools.packagerGecko as packager | |
373 if locales == None: | |
374 locales = packager.getLocales(baseDir) | |
375 elif locales == 'all': | |
376 locales = packager.getLocales(baseDir, True) | |
377 | |
378 data = packager.readLocaleMetadata(baseDir, locales) | |
379 localeCodes = data.keys() | |
380 localeCodes.sort() | |
381 for localeCode in localeCodes: | |
382 locale = data[localeCode] | |
383 print ('''%s | |
384 %s | |
385 %s | |
386 %s | |
387 %s | |
388 ''' % (localeCode, | |
389 locale['name'] if 'name' in locale else 'None', | |
390 locale['description'] if 'description' in locale else 'None', | |
391 locale['description.short'] if 'description.short' in locale else 'N one', | |
392 locale['description.long'] if 'description.long' in locale else 'Non e', | |
393 )).encode('utf-8') | |
394 | |
395 | |
396 def generateDocs(baseDir, scriptName, opts, args, type): | 323 def generateDocs(baseDir, scriptName, opts, args, type): |
397 if len(args) == 0: | 324 if len(args) == 0: |
398 print 'No target directory specified for the documentation' | 325 print 'No target directory specified for the documentation' |
399 usage(scriptName, type, 'docs') | 326 usage(scriptName, type, 'docs') |
400 return | 327 return |
401 targetDir = args[0] | 328 targetDir = args[0] |
402 | 329 |
403 source_dir = os.path.join(baseDir, 'lib') | 330 source_dir = os.path.join(baseDir, 'lib') |
404 sources = [source_dir] | 331 sources = [source_dir] |
405 | 332 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
457 publicSuffixListUpdater.updatePSL(baseDir) | 384 publicSuffixListUpdater.updatePSL(baseDir) |
458 | 385 |
459 | 386 |
460 with addCommand(lambda baseDir, scriptName, opts, args, type: usage(scriptName, type), ('help', '-h', '--help')) as command: | 387 with addCommand(lambda baseDir, scriptName, opts, args, type: usage(scriptName, type), ('help', '-h', '--help')) as command: |
461 command.shortDescription = 'Show this message' | 388 command.shortDescription = 'Show this message' |
462 | 389 |
463 with addCommand(runBuild, 'build') as command: | 390 with addCommand(runBuild, 'build') as command: |
464 command.shortDescription = 'Create a build' | 391 command.shortDescription = 'Create a build' |
465 command.description = 'Creates an extension build with given file name. If o utput_file is missing a default name will be chosen.' | 392 command.description = 'Creates an extension build with given file name. If o utput_file is missing a default name will be chosen.' |
466 command.params = '[options] [output_file]' | 393 command.params = '[options] [output_file]' |
467 command.addOption('Only include the given locales (if omitted: all locales n ot marked as incomplete)', short='l', long='locales', value='l1,l2,l3', types=(' gecko')) | |
468 command.addOption('Use given build number (if omitted the build number will be retrieved from Mercurial)', short='b', long='build', value='num') | 394 command.addOption('Use given build number (if omitted the build number will be retrieved from Mercurial)', short='b', long='build', value='num') |
469 command.addOption('File containing private key and certificates required to sign the package', short='k', long='key', value='file', types=('chrome', 'safari ')) | 395 command.addOption('File containing private key and certificates required to sign the package', short='k', long='key', value='file', types=('chrome', 'safari ')) |
470 command.addOption('Create a build for leak testing', short='m', long='multi- compartment', types=('gecko')) | |
471 command.addOption('Create a release build', short='r', long='release') | 396 command.addOption('Create a release build', short='r', long='release') |
472 command.supportedTypes = ('gecko', 'gecko-webext', 'chrome', 'safari', 'edge ') | 397 command.supportedTypes = ('gecko-webext', 'chrome', 'safari', 'edge') |
473 | |
474 with addCommand(runAutoInstall, 'autoinstall') as command: | |
475 command.shortDescription = 'Install extension automatically' | |
476 command.description = 'Will automatically install the extension in a browser running Extension Auto-Installer. If host parameter is omitted assumes that the browser runs on localhost.' | |
477 command.params = '[<host>:]<port>' | |
478 command.addOption('Create a build for leak testing', short='m', long='multi- compartment') | |
479 command.supportedTypes = ('gecko') | |
480 | 398 |
481 with addCommand(createDevEnv, 'devenv') as command: | 399 with addCommand(createDevEnv, 'devenv') as command: |
482 command.shortDescription = 'Set up a development environment' | 400 command.shortDescription = 'Set up a development environment' |
483 command.description = 'Will set up or update the devenv folder as an unpacke d extension folder for development.' | 401 command.description = 'Will set up or update the devenv folder as an unpacke d extension folder for development.' |
484 command.supportedTypes = ('gecko-webext', 'chrome', 'safari') | 402 command.supportedTypes = ('gecko-webext', 'chrome', 'safari') |
485 | 403 |
486 with addCommand(setupTranslations, 'setuptrans') as command: | 404 with addCommand(setupTranslations, 'setuptrans') as command: |
487 command.shortDescription = 'Sets up translation languages' | 405 command.shortDescription = 'Sets up translation languages' |
488 command.description = 'Sets up translation languages for the project on crow din.net.' | 406 command.description = 'Sets up translation languages for the project on crow din.net.' |
489 command.params = '[options] project-key' | 407 command.params = '[options] project-key' |
490 command.supportedTypes = ('gecko', 'chrome', 'generic') | |
491 | 408 |
492 with addCommand(updateTranslationMaster, 'translate') as command: | 409 with addCommand(updateTranslationMaster, 'translate') as command: |
493 command.shortDescription = 'Updates translation master files' | 410 command.shortDescription = 'Updates translation master files' |
494 command.description = 'Updates the translation master files in the project o n crowdin.net.' | 411 command.description = 'Updates the translation master files in the project o n crowdin.net.' |
495 command.params = '[options] project-key' | 412 command.params = '[options] project-key' |
496 command.supportedTypes = ('gecko', 'chrome', 'generic') | |
497 | 413 |
498 with addCommand(uploadTranslations, 'uploadtrans') as command: | 414 with addCommand(uploadTranslations, 'uploadtrans') as command: |
499 command.shortDescription = 'Uploads existing translations' | 415 command.shortDescription = 'Uploads existing translations' |
500 command.description = 'Uploads already existing translations to the project on crowdin.net.' | 416 command.description = 'Uploads already existing translations to the project on crowdin.net.' |
501 command.params = '[options] project-key' | 417 command.params = '[options] project-key' |
502 command.supportedTypes = ('gecko', 'chrome', 'generic') | |
503 | 418 |
504 with addCommand(getTranslations, 'gettranslations') as command: | 419 with addCommand(getTranslations, 'gettranslations') as command: |
505 command.shortDescription = 'Downloads translation updates' | 420 command.shortDescription = 'Downloads translation updates' |
506 command.description = 'Downloads updated translations from crowdin.net.' | 421 command.description = 'Downloads updated translations from crowdin.net.' |
507 command.params = '[options] project-key' | 422 command.params = '[options] project-key' |
508 command.supportedTypes = ('gecko', 'chrome', 'generic') | |
509 | |
510 with addCommand(showDescriptions, 'showdesc') as command: | |
511 command.shortDescription = 'Print description strings for all locales' | |
512 command.description = 'Display description strings for all locales as specif ied in the corresponding meta.properties files.' | |
513 command.addOption('Only include the given locales', short='l', long='locales ', value='l1,l2,l3') | |
514 command.params = '[options]' | |
515 command.supportedTypes = ('gecko') | |
516 | 423 |
517 with addCommand(generateDocs, 'docs') as command: | 424 with addCommand(generateDocs, 'docs') as command: |
518 command.shortDescription = 'Generate documentation (requires node.js)' | 425 command.shortDescription = 'Generate documentation (requires node.js)' |
519 command.description = ('Generate documentation files and write them into ' | 426 command.description = ('Generate documentation files and write them into ' |
520 'the specified directory.') | 427 'the specified directory.') |
521 command.addOption('Suppress JsDoc output', short='q', long='quiet') | 428 command.addOption('Suppress JsDoc output', short='q', long='quiet') |
522 command.params = '[options] <directory>' | 429 command.params = '[options] <directory>' |
523 command.supportedTypes = ('gecko', 'chrome') | 430 command.supportedTypes = ('chrome',) |
524 | 431 |
525 with addCommand(runReleaseAutomation, 'release') as command: | 432 with addCommand(runReleaseAutomation, 'release') as command: |
526 command.shortDescription = 'Run release automation' | 433 command.shortDescription = 'Run release automation' |
527 command.description = 'Note: If you are not the project owner then you ' "probably don't want to run this!\n\n" 'Runs release automation: crea tes downloads for the new version, tags ' 'source code repository as well as downloads and buildtools repository.' | 434 command.description = 'Note: If you are not the project owner then you ' "probably don't want to run this!\n\n" 'Runs release automation: crea tes downloads for the new version, tags ' 'source code repository as well as downloads and buildtools repository.' |
528 command.addOption('File containing private key and certificates required to sign the release.', short='k', long='key', value='file', types=('chrome', 'safar i', 'edge')) | 435 command.addOption('File containing private key and certificates required to sign the release.', short='k', long='key', value='file', types=('chrome', 'safar i', 'edge')) |
529 command.addOption('Directory containing downloads repository (if omitted ../ downloads is assumed)', short='d', long='downloads', value='dir') | 436 command.addOption('Directory containing downloads repository (if omitted ../ downloads is assumed)', short='d', long='downloads', value='dir') |
530 command.params = '[options] <version>' | 437 command.params = '[options] <version>' |
531 command.supportedTypes = ('gecko', 'chrome', 'safari', 'edge') | 438 command.supportedTypes = ('chrome', 'safari', 'edge') |
532 | 439 |
533 with addCommand(updatePSL, 'updatepsl') as command: | 440 with addCommand(updatePSL, 'updatepsl') as command: |
534 command.shortDescription = 'Updates Public Suffix List' | 441 command.shortDescription = 'Updates Public Suffix List' |
535 command.description = 'Downloads Public Suffix List (see http://publicsuffix .org/) and generates lib/publicSuffixList.js from it.' | 442 command.description = 'Downloads Public Suffix List (see http://publicsuffix .org/) and generates lib/publicSuffixList.js from it.' |
536 command.supportedTypes = ('chrome',) | 443 command.supportedTypes = ('chrome',) |
537 | 444 |
538 | 445 |
539 def getType(baseDir, scriptName, args): | 446 def getType(baseDir, scriptName, args): |
540 # Look for an explicit type parameter (has to be the first parameter) | 447 # Look for an explicit type parameter (has to be the first parameter) |
541 if len(args) >= 2 and args[0] == '-t': | 448 if len(args) >= 2 and args[0] == '-t': |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
601 if option in ('-h', '--help'): | 508 if option in ('-h', '--help'): |
602 usage(scriptName, type, command) | 509 usage(scriptName, type, command) |
603 sys.exit() | 510 sys.exit() |
604 commands[command](baseDir, scriptName, opts, args, type) | 511 commands[command](baseDir, scriptName, opts, args, type) |
605 else: | 512 else: |
606 print 'Command %s is not supported for this application type' % comm and | 513 print 'Command %s is not supported for this application type' % comm and |
607 usage(scriptName, type) | 514 usage(scriptName, type) |
608 else: | 515 else: |
609 print 'Command %s is unrecognized' % command | 516 print 'Command %s is unrecognized' % command |
610 usage(scriptName, type) | 517 usage(scriptName, type) |
OLD | NEW |