| Left: | ||
| Right: |
| 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 104 | 106 |
| 105 def usage(scriptName, type, commandName=None): | 107 def usage(scriptName, type, commandName=None): |
| 106 if commandName == None: | 108 if commandName == None: |
| 107 global commandsList | 109 global commandsList |
| 108 descriptions = [] | 110 descriptions = [] |
| 109 for command in commandsList: | 111 for command in commandsList: |
| 110 if not command.isSupported(type): | 112 if not command.isSupported(type): |
| 111 continue | 113 continue |
| 112 commandText = ('%s %s' % (command.name, command.params)).ljust(39) | 114 commandText = ('%s %s' % (command.name, command.params)).ljust(39) |
| 113 descriptionParts = splitByLength(command.shortDescription, 29) | 115 descriptionParts = splitByLength(command.shortDescription, 29) |
| 114 descriptions.append(' %s %s %s' % (scriptName, commandText, descriptionPa rts[0])) | 116 descriptions.append(' %s [-t %s] %s %s' % (scriptName, type, commandText, descriptionParts[0])) |
| 115 for part in descriptionParts[1:]: | 117 for part in descriptionParts[1:]: |
| 116 descriptions.append(' %s %s %s' % (' ' * len(scriptName), ' ' * len(com mandText), part)) | 118 descriptions.append(' %s %s %s %s' % (' ' * len(scriptName), ' ' * len(type), ' ' * len(commandText), part)) |
| 117 print '''Usage: | 119 print '''Usage: |
| 118 | 120 |
| 119 %(descriptions)s | 121 %(descriptions)s |
| 120 | 122 |
| 121 For details on a command run: | 123 For details on a command run: |
| 122 | 124 |
| 123 %(scriptName)s <command> --help | 125 %(scriptName)s [-t %(type)s] <command> --help |
| 124 ''' % { | 126 ''' % { |
| 125 'scriptName': scriptName, | 127 'scriptName': scriptName, |
| 128 'type': type, | |
| 126 'descriptions': '\n'.join(descriptions) | 129 'descriptions': '\n'.join(descriptions) |
| 127 } | 130 } |
| 128 else: | 131 else: |
| 129 global commands | 132 global commands |
| 130 command = commands[commandName] | 133 command = commands[commandName] |
| 131 description = '\n'.join(map(lambda s: '\n'.join(splitByLength(s, 80)), comma nd.description.split('\n'))) | 134 description = '\n'.join(map(lambda s: '\n'.join(splitByLength(s, 80)), comma nd.description.split('\n'))) |
| 132 options = [] | 135 options = [] |
| 133 for descr, short, long, value, types in command.options: | 136 for descr, short, long, value, types in command.options: |
| 134 if types != None and type not in types: | 137 if types != None and type not in types: |
| 135 continue | 138 continue |
| 136 if short == None: | 139 if short == None: |
| 137 shortText = '' | 140 shortText = '' |
| 138 elif value == None: | 141 elif value == None: |
| 139 shortText = '-%s' % short | 142 shortText = '-%s' % short |
| 140 else: | 143 else: |
| 141 shortText = '-%s %s' % (short, value) | 144 shortText = '-%s %s' % (short, value) |
| 142 if long == None: | 145 if long == None: |
| 143 longText = '' | 146 longText = '' |
| 144 elif value == None: | 147 elif value == None: |
| 145 longText = '--%s' % long | 148 longText = '--%s' % long |
| 146 else: | 149 else: |
| 147 longText = '--%s=%s' % (long, value) | 150 longText = '--%s=%s' % (long, value) |
| 148 descrParts = splitByLength(descr, 46) | 151 descrParts = splitByLength(descr, 46) |
| 149 options.append(' %s %s %s' % (shortText.ljust(11), longText.ljust(19), de scrParts[0])) | 152 options.append(' %s %s %s' % (shortText.ljust(11), longText.ljust(19), de scrParts[0])) |
| 150 for part in descrParts[1:]: | 153 for part in descrParts[1:]: |
| 151 options.append(' %s %s %s' % (' ' * 11, ' ' * 19, part)) | 154 options.append(' %s %s %s' % (' ' * 11, ' ' * 19, part)) |
| 152 print '''%(scriptName)s %(name)s %(params)s | 155 print '''%(scriptName)s [-t %(type)s] %(name)s %(params)s |
| 153 | 156 |
| 154 %(description)s | 157 %(description)s |
| 155 | 158 |
| 156 Options: | 159 Options: |
| 157 %(options)s | 160 %(options)s |
| 158 ''' % { | 161 ''' % { |
| 159 'scriptName': scriptName, | 162 'scriptName': scriptName, |
| 163 'type': type, | |
| 160 'name': command.name, | 164 'name': command.name, |
| 161 'params': command.params, | 165 'params': command.params, |
| 162 'description': description, | 166 'description': description, |
| 163 'options': '\n'.join(options) | 167 'options': '\n'.join(options) |
| 164 } | 168 } |
| 165 | 169 |
| 166 | 170 |
| 167 def runBuild(baseDir, scriptName, opts, args, type): | 171 def runBuild(baseDir, scriptName, opts, args, type): |
| 168 locales = None | 172 locales = None |
| 169 buildNum = None | 173 buildNum = None |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 495 command.shortDescription = 'Sync locales with a Firefox extension' | 499 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.' | 500 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>' | 501 command.params = '<firefox_addon_directory>' |
| 498 command.supportedTypes = ('chrome') | 502 command.supportedTypes = ('chrome') |
| 499 | 503 |
| 500 with addCommand(updatePSL, 'updatepsl') as command: | 504 with addCommand(updatePSL, 'updatepsl') as command: |
| 501 command.shortDescription = 'Updates Public Suffix List' | 505 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.' | 506 command.description = 'Downloads Public Suffix List (see http://publicsuffix.o rg/) and generates lib/publicSuffixList.js from it.' |
| 503 command.supportedTypes = ('chrome') | 507 command.supportedTypes = ('chrome') |
| 504 | 508 |
| 505 def processArgs(baseDir, args, type='gecko'): | 509 def getType(baseDir, scriptName, args): |
| 510 # Look for an explicit type parameter (has to be the first parameter) | |
| 511 if len(args) >= 2 and args[0] == '-t': | |
|
Felix Dahlke
2013/01/25 08:30:49
Hard coding that -t needs to be the very first par
| |
| 512 type = args[1] | |
| 513 del args[1] | |
| 514 del args[0] | |
| 515 if type not in knownTypes: | |
| 516 print ''' | |
| 517 Unknown type %s specified, supported types are: %s | |
| 518 ''' % (type, ', '.join(knownTypes)) | |
| 519 return None | |
| 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 %s -t %s build | |
| 534 ''' % (scriptName, 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, scriptName, args) | |
|
Felix Dahlke
2013/01/25 08:30:49
There's a rogue white space before "args". Utter n
Wladimir Palant
2013/01/25 10:23:49
Fixed that before pushing.
| |
| 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 |