| OLD | NEW |
| 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 os, sys, re, subprocess, buildtools | 18 import os, sys, re, subprocess, buildtools |
| 19 from getopt import getopt, GetoptError | 19 from getopt import getopt, GetoptError |
| 20 | 20 |
| 21 knownTypes = ('gecko', 'chrome') |
| 22 |
| 21 class Command(object): | 23 class Command(object): |
| 22 name = property(lambda self: self._name) | 24 name = property(lambda self: self._name) |
| 23 shortDescription = property(lambda self: self._shortDescription, | 25 shortDescription = property(lambda self: self._shortDescription, |
| 24 lambda self, value: self.__dict__.update({'_shortDescription': value})) | 26 lambda self, value: self.__dict__.update({'_shortDescription': value})) |
| 25 description = property(lambda self: self._description, | 27 description = property(lambda self: self._description, |
| 26 lambda self, value: self.__dict__.update({'_description': value})) | 28 lambda self, value: self.__dict__.update({'_description': value})) |
| 27 params = property(lambda self: self._params, | 29 params = property(lambda self: self._params, |
| 28 lambda self, value: self.__dict__.update({'_params': value})) | 30 lambda self, value: self.__dict__.update({'_params': value})) |
| 29 supportedTypes = property(lambda self: self._supportedTypes, | 31 supportedTypes = property(lambda self: self._supportedTypes, |
| 30 lambda self, value: self.__dict__.update({'_supportedTypes': value})) | 32 lambda self, value: self.__dict__.update({'_supportedTypes': value})) |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 | 350 |
| 349 def generateDocs(baseDir, scriptName, opts, args, type): | 351 def generateDocs(baseDir, scriptName, opts, args, type): |
| 350 if len(args) == 0: | 352 if len(args) == 0: |
| 351 print 'No target directory specified for the documentation' | 353 print 'No target directory specified for the documentation' |
| 352 usage(scriptName, type, 'docs') | 354 usage(scriptName, type, 'docs') |
| 353 return | 355 return |
| 354 targetDir = args[0] | 356 targetDir = args[0] |
| 355 | 357 |
| 356 toolkit = None | 358 toolkit = None |
| 357 for option, value in opts: | 359 for option, value in opts: |
| 358 if option in ('-t', '--toolkit'): | 360 if option in ('-k', '--toolkit'): |
| 359 toolkit = value | 361 toolkit = value |
| 360 | 362 |
| 361 if toolkit == None: | 363 if toolkit == None: |
| 362 toolkit = os.path.join(baseDir, 'jsdoc-toolkit') | 364 toolkit = os.path.join(baseDir, 'jsdoc-toolkit') |
| 363 if not os.path.exists(toolkit): | 365 if not os.path.exists(toolkit): |
| 364 subprocess.Popen(['hg', 'clone', 'https://hg.adblockplus.org/jsdoc-toolkit
/', toolkit]).communicate() | 366 subprocess.Popen(['hg', 'clone', 'https://hg.adblockplus.org/jsdoc-toolkit
/', toolkit]).communicate() |
| 365 | 367 |
| 366 command = [sys.executable, | 368 command = [sys.executable, |
| 367 os.path.join(toolkit, 'jsrun.py'), | 369 os.path.join(toolkit, 'jsrun.py'), |
| 368 '-t=' + os.path.join(toolkit, 'templates', 'jsdoc'), | 370 '-t=' + os.path.join(toolkit, 'templates', 'jsdoc'), |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 with addCommand(showDescriptions, 'showdesc') as command: | 471 with addCommand(showDescriptions, 'showdesc') as command: |
| 470 command.shortDescription = 'Print description strings for all locales' | 472 command.shortDescription = 'Print description strings for all locales' |
| 471 command.description = 'Display description strings for all locales as specifie
d in the corresponding meta.properties files.' | 473 command.description = 'Display description strings for all locales as specifie
d in the corresponding meta.properties files.' |
| 472 command.addOption('Only include the given locales', short='l', long='locales',
value='l1,l2,l3') | 474 command.addOption('Only include the given locales', short='l', long='locales',
value='l1,l2,l3') |
| 473 command.params = '[options]' | 475 command.params = '[options]' |
| 474 command.supportedTypes = ('gecko') | 476 command.supportedTypes = ('gecko') |
| 475 | 477 |
| 476 with addCommand(generateDocs, 'docs') as command: | 478 with addCommand(generateDocs, 'docs') as command: |
| 477 command.shortDescription = 'Generate documentation' | 479 command.shortDescription = 'Generate documentation' |
| 478 command.description = 'Generate documentation files and write them into the sp
ecified directory.' | 480 command.description = 'Generate documentation files and write them into the sp
ecified directory.' |
| 479 command.addOption('JsDoc Toolkit location', short='t', long='toolkit', value='
dir') | 481 command.addOption('JsDoc Toolkit location', short='k', long='toolkit', value='
dir') |
| 480 command.params = '[options] <directory>' | 482 command.params = '[options] <directory>' |
| 481 command.supportedTypes = ('gecko') | 483 command.supportedTypes = ('gecko') |
| 482 | 484 |
| 483 with addCommand(runReleaseAutomation, 'release') as command: | 485 with addCommand(runReleaseAutomation, 'release') as command: |
| 484 command.shortDescription = 'Run release automation' | 486 command.shortDescription = 'Run release automation' |
| 485 command.description = 'Note: If you are not the project owner then you '\ | 487 command.description = 'Note: If you are not the project owner then you '\ |
| 486 'probably don\'t want to run this!\n\n'\ | 488 'probably don\'t want to run this!\n\n'\ |
| 487 'Runs release automation: creates downloads for the new version, tags '\ | 489 'Runs release automation: creates downloads for the new version, tags '\ |
| 488 'source code repository as well as downloads and buildtools repository.' | 490 'source code repository as well as downloads and buildtools repository.' |
| 489 command.addOption('File containing private key and certificates required to si
gn the release', short='k', long='key', value='file', types=('gecko')) | 491 command.addOption('File containing private key and certificates required to si
gn the release', short='k', long='key', value='file', types=('gecko')) |
| 490 command.addOption('Directory containing downloads repository (if omitted ../do
wnloads is assumed)', short='d', long='downloads', value='dir') | 492 command.addOption('Directory containing downloads repository (if omitted ../do
wnloads is assumed)', short='d', long='downloads', value='dir') |
| 491 command.params = '[options] <version>' | 493 command.params = '[options] <version>' |
| 492 command.supportedTypes = ('gecko') | 494 command.supportedTypes = ('gecko') |
| 493 | 495 |
| 494 with addCommand(syncLocales, 'synclocales') as command: | 496 with addCommand(syncLocales, 'synclocales') as command: |
| 495 command.shortDescription = 'Sync locales with a Firefox extension' | 497 command.shortDescription = 'Sync locales with a Firefox extension' |
| 496 command.description = 'Updates locale files with strings from a Firefox extens
ion corresponding to the entries in [locale_sync] metadata section.' | 498 command.description = 'Updates locale files with strings from a Firefox extens
ion corresponding to the entries in [locale_sync] metadata section.' |
| 497 command.params = '<firefox_addon_directory>' | 499 command.params = '<firefox_addon_directory>' |
| 498 command.supportedTypes = ('chrome') | 500 command.supportedTypes = ('chrome') |
| 499 | 501 |
| 500 with addCommand(updatePSL, 'updatepsl') as command: | 502 with addCommand(updatePSL, 'updatepsl') as command: |
| 501 command.shortDescription = 'Updates Public Suffix List' | 503 command.shortDescription = 'Updates Public Suffix List' |
| 502 command.description = 'Downloads Public Suffix List (see http://publicsuffix.o
rg/) and generates lib/publicSuffixList.js from it.' | 504 command.description = 'Downloads Public Suffix List (see http://publicsuffix.o
rg/) and generates lib/publicSuffixList.js from it.' |
| 503 command.supportedTypes = ('chrome') | 505 command.supportedTypes = ('chrome') |
| 504 | 506 |
| 505 def processArgs(baseDir, args, type='gecko'): | 507 def getType(baseDir, args): |
| 508 # Look for an explicit type parameter |
| 509 for i in range(len(args)): |
| 510 if args[i] == '-t' and i < len(args) - 1: |
| 511 type = args[i + 1] |
| 512 del args[i + 1] |
| 513 del args[i] |
| 514 if type not in knownTypes: |
| 515 print ''' |
| 516 Unknown type %s specified, supported types are: %s |
| 517 ''' % (type, knownTypes) |
| 518 return None |
| 519 else: |
| 520 return type |
| 521 |
| 522 # Try to guess repository type |
| 523 types = [] |
| 524 for t in knownTypes: |
| 525 if os.path.exists(os.path.join(baseDir, 'metadata.%s' % t)): |
| 526 types.append(t) |
| 527 |
| 528 if len(types) == 1: |
| 529 return types[0] |
| 530 elif len(types) > 1: |
| 531 print ''' |
| 532 Ambiguous repository type, please specify -t parameter explicitly, e.g. |
| 533 -t %s |
| 534 ''' % types[0] |
| 535 return None |
| 536 else: |
| 537 print ''' |
| 538 No metadata file found in this repository, a metadata file like |
| 539 metadata.%s is required. |
| 540 ''' % knownTypes[0] |
| 541 return None |
| 542 |
| 543 def processArgs(baseDir, args): |
| 506 global commands | 544 global commands |
| 507 | 545 |
| 508 scriptName = os.path.basename(args[0]) | 546 scriptName = os.path.basename(args[0]) |
| 509 args = args[1:] | 547 args = args[1:] |
| 548 type = getType(baseDir, args) |
| 549 if type == None: |
| 550 return |
| 551 |
| 510 if len(args) == 0: | 552 if len(args) == 0: |
| 511 args = ['build'] | 553 args = ['build'] |
| 512 print ''' | 554 print ''' |
| 513 No command given, assuming "build". For a list of commands run: | 555 No command given, assuming "build". For a list of commands run: |
| 514 | 556 |
| 515 %s help | 557 %s help |
| 516 ''' % scriptName | 558 ''' % scriptName |
| 517 | 559 |
| 518 command = args[0] | 560 command = args[0] |
| 519 if command in commands: | 561 if command in commands: |
| 520 if commands[command].isSupported(type): | 562 if commands[command].isSupported(type): |
| 521 try: | 563 try: |
| 522 opts, args = commands[command].parseArgs(type, args[1:]) | 564 opts, args = commands[command].parseArgs(type, args[1:]) |
| 523 except GetoptError, e: | 565 except GetoptError, e: |
| 524 print str(e) | 566 print str(e) |
| 525 usage(scriptName, type, command) | 567 usage(scriptName, type, command) |
| 526 sys.exit(2) | 568 sys.exit(2) |
| 527 for option, value in opts: | 569 for option, value in opts: |
| 528 if option in ('-h', '--help'): | 570 if option in ('-h', '--help'): |
| 529 usage(scriptName, type, command) | 571 usage(scriptName, type, command) |
| 530 sys.exit() | 572 sys.exit() |
| 531 commands[command](baseDir, scriptName, opts, args, type) | 573 commands[command](baseDir, scriptName, opts, args, type) |
| 532 else: | 574 else: |
| 533 print 'Command %s is not supported for this application type' % command | 575 print 'Command %s is not supported for this application type' % command |
| 534 usage(scriptName, type) | 576 usage(scriptName, type) |
| 535 else: | 577 else: |
| 536 print 'Command %s is unrecognized' % command | 578 print 'Command %s is unrecognized' % command |
| 537 usage(scriptName, type) | 579 usage(scriptName, type) |
| OLD | NEW |