diff options
-rw-r--r-- | debian/changelog | 4 | ||||
-rwxr-xr-x | src/dh_xul-ext | 76 |
2 files changed, 41 insertions, 39 deletions
diff --git a/debian/changelog b/debian/changelog index 6051f8e..847da0e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -14,8 +14,10 @@ mozilla-devscripts (0.21) UNRELEASED; urgency=low * Install extensions into xul-ext subdirectory; thanks to Daniel Kahn Gillmor for the patch. - update src/install-xpi + * Use optparse instead of getopts and ignore unknown options (LP: #543862). + - update src/dh_xul-ext - -- Benjamin Drung <bdrung@ubuntu.com> Wed, 17 Mar 2010 11:37:57 +0100 + -- Benjamin Drung <bdrung@ubuntu.com> Wed, 24 Mar 2010 18:49:35 +0100 mozilla-devscripts (0.20) unstable; urgency=low diff --git a/src/dh_xul-ext b/src/dh_xul-ext index b9a94d7..3592663 100755 --- a/src/dh_xul-ext +++ b/src/dh_xul-ext @@ -21,8 +21,8 @@ # THE SOFTWARE. import csv -import getopt import glob +import optparse import os import subprocess import sys @@ -184,55 +184,55 @@ def generate_substvars(script_name, xul_apps, package, verbose=False): f.writelines(lines) f.close() -def usage(output): - print >> output, """Usage: %s [options] -Options: - -p, --package=<value> calculate substvars only for the specified package +class UnknownOptionIgnoringOptionParser(optparse.OptionParser): + def __init__ (self, **options): + optparse.OptionParser.__init__(self, **options) + self.unknown_options = [] -General options: - -h, --help display this help and exit - -v, --verbose print more information + def _process_long_opt(self, rargs, values): + option = rargs[0].split("=")[0] + if not option in self._long_opt: + self.unknown_options.append(option) + del rargs[0] + else: + optparse.OptionParser._process_long_opt(self, rargs, values) + + def _process_short_opts(self, rargs, values): + option = rargs[0][0:2] + if not self._short_opt.get(option): + self.unknown_options.append(option) + del rargs[0] + else: + optparse.OptionParser._process_short_opts(self, rargs, values) -See %s(1) for more info.""" % (os.path.basename(sys.argv[0]), os.path.basename(sys.argv[0])) if __name__ == "__main__": - try: - long_opts = ["help", "package", "verbose"] - opts, args = getopt.gnu_getopt(sys.argv[1:], "hp:v", long_opts) - except getopt.GetoptError, e: - # print help information and exit: - print >> sys.stderr, str(e) # will print something like "option -a not recognized" - usage(sys.stderr) - sys.exit(COMMAND_LINE_SYNTAX_ERROR) - - packages = list() - verbose = False - - for o, a in opts: - if o in ("-h", "--help"): - usage(sys.stdout) - sys.exit() - elif o in ("-p", "--package"): - packages.append(a) - elif o in ("-v", "--verbose"): - verbose = True - else: - assert False, "unhandled option" + epilog = "See %s(1) for more info." % (os.path.basename(sys.argv[0])) + parser = UnknownOptionIgnoringOptionParser(epilog=epilog) + parser.add_option("-p", "--package", dest="packages", metavar="PACKAGE", + action="append", default=[], + help="calculate substvars only for the specified PACKAGE") + parser.add_option("-v", "--verbose", action="store_true", dest="verbose", + default=False, help="print more information") + + (options, args) = parser.parse_args() - if len(packages) == 0: - packages = get_all_packages() + if len(options.packages) == 0: + options.packages = get_all_packages() script_name = os.path.basename(sys.argv[0]) - if verbose: - print script_name + ": packages:", ", ".join(packages) + if options.verbose: + for unknown_option in parser.unknown_options: + sys.stderr.write("%s: warning: no such option: %s\n" % (script_name, unknown_option)) + print script_name + ": packages:", ", ".join(options.packages) xul_apps = get_xul_apps() - if verbose and len(xul_apps) > 0: + if options.verbose and len(xul_apps) > 0: print script_name + ": found %i Xul applications:" % (len(xul_apps)) for xul_app in xul_apps: print xul_app["id"] + ": " + xul_app["package"] + " (" + xul_app["sol"] + " to " + xul_app["eol"] + ")" - for package in packages: - generate_substvars(script_name, xul_apps, package, verbose) + for package in options.packages: + generate_substvars(script_name, xul_apps, package, options.verbose) |