summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBenjamin Drung <bdrung@ubuntu.com>2010-03-24 18:49:43 +0100
committerBenjamin Drung <bdrung@ubuntu.com>2010-03-24 18:49:43 +0100
commitb0522fc2f94ded572464ce2162083aecde26b9b8 (patch)
tree3a122dafc28ac5db1f1765dbcb69b203bcb9fea9 /src
parent53d3311e21628379d3003a196e8112169d97b686 (diff)
* Use optparse instead of getopts and ignore unknown options (LP: #543862).
- update src/dh_xul-ext
Diffstat (limited to 'src')
-rwxr-xr-xsrc/dh_xul-ext76
1 files changed, 38 insertions, 38 deletions
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)