summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Drung <bdrung@ubuntu.com>2010-03-24 20:58:55 +0100
committerBenjamin Drung <bdrung@ubuntu.com>2010-03-24 20:58:55 +0100
commit7dd58a382d9d8a7081b9bfc5af5a42ab9977d6bf (patch)
treed1e4f9c26484d80f81036b703546c3dd8e27cb14
parent4222954b74ca897b37a5b3721f6698e4caf03b82 (diff)
* Use optparse instead of getopts.
- update src/install-xpi
-rw-r--r--debian/changelog4
-rwxr-xr-xsrc/install-xpi97
2 files changed, 37 insertions, 64 deletions
diff --git a/debian/changelog b/debian/changelog
index 1029cd3..df2a0b8 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -17,8 +17,10 @@ mozilla-devscripts (0.21) UNRELEASED; urgency=low
* Use optparse instead of getopts and ignore unknown options (LP: #543862).
- update man/dh_xul-ext.1
- update src/dh_xul-ext
+ * Use optparse instead of getopts.
+ - update src/install-xpi
- -- Benjamin Drung <bdrung@ubuntu.com> Wed, 24 Mar 2010 20:19:56 +0100
+ -- Benjamin Drung <bdrung@ubuntu.com> Wed, 24 Mar 2010 20:55:24 +0100
mozilla-devscripts (0.20) unstable; urgency=low
diff --git a/src/install-xpi b/src/install-xpi
index 4fc6013..74aae57 100755
--- a/src/install-xpi
+++ b/src/install-xpi
@@ -21,7 +21,7 @@
# THE SOFTWARE.
import csv
-import getopt
+import optparse
import os
import stat
import subprocess
@@ -86,7 +86,8 @@ def incompatible_apps(target_applications):
incompatible_apps = filter(lambda x: x in app_list, incompatible_apps)
return incompatible_apps
-def install_xpi(script_name, package, xpi_file, exclude, install_dir, links, correct_permissions, remove_licenses, verbose=False):
+def install_xpi(script_name, package, xpi_file, exclude, install_dir, links,
+ correct_permissions, remove_licenses, verbose=False):
# get xpi file content list
if not os.path.isfile(xpi_file):
print >> sys.stderr, "%s: Error: xpi file %s does not exist." % (script_name, xpi_file)
@@ -170,65 +171,33 @@ def get_first_package():
packages = map(lambda x: x[x.find(":")+1:].strip(), package_lines)
return packages[0]
-def usage(output):
- print >> output, """Usage: %s [options] <xpi-file>
-
-Options:
- -x, --exclude=<file> do not install specified file
- -i, --install-dir=<value> install extension into the specified directory
- -l, --link=<directory> link from directory to extension directory
- -p, --package=<value> install the extension into specified package
- --preserve-permissions do not adjust the file permissions
- -r, --remove-license-files do not install license files
-
-General options:
- -h, --help display this help and exit
- -v, --verbose print more information
-
-See %s(1) for more info.""" % (os.path.basename(sys.argv[0]), os.path.basename(sys.argv[0]))
-
if __name__ == "__main__":
- try:
- long_opts = ["exclude", "help", "install-dir", "link", "package",
- "preserve-permissions", "remove-license-files", "verbose"]
- opts, args = getopt.gnu_getopt(sys.argv[1:], "hi:l:p:rvx:", 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)
-
- correct_permissions = True
- install_dir = None
- links = set()
- package = None
- remove_licenses = False
- verbose = False
- exclude = list()
-
- for o, a in opts:
- if o in ("-x", "--exclude"):
- exclude.append(a)
- elif o in ("-h", "--help"):
- usage(sys.stdout)
- sys.exit()
- elif o in ("-i", "--install-dir"):
- install_dir = a
- elif o in ("-l", "--link"):
- links.add(a)
- elif o in ("-p", "--package"):
- package = a
- elif o in ("preserve-permissions"):
- correct_permissions = False
- elif o in ("-r", "--remove-license-files"):
- remove_licenses = True
- elif o in ("-v", "--verbose"):
- verbose = True
- else:
- assert False, "unhandled option"
-
- if package is None:
- package = get_first_package()
+ usage = "%s [options] <xpi-file>" % (os.path.basename(sys.argv[0]))
+ epilog = "See %s(1) for more info." % (os.path.basename(sys.argv[0]))
+ parser = optparse.OptionParser(usage=usage, epilog=epilog)
+
+ parser.add_option("-x", "--exclude", metavar="FILE",
+ help="do not install specified FILE",
+ dest="exclude", action="append", default=list())
+ parser.add_option("-i", "--install-dir", metavar="DIRECTORY",
+ help="install extension into the specified DIRECTORY",
+ dest="install_dir")
+ parser.add_option("-l", "--link", metavar="DIRECTORY",
+ help="link from DIRECTORY to extension directory",
+ dest="links", action="append", default=list())
+ parser.add_option("-p", "--package", metavar="PACKAGE",
+ help="install the extension into specified PACKAGE",
+ dest="package", default=get_first_package())
+ parser.add_option("--preserve-permissions",
+ help="do not adjust the file permissions",
+ dest="correct_permissions", action="store_false", default=True)
+ parser.add_option("-r", "--remove-license-files",
+ help="do not install license files",
+ dest="remove_licenses", action="store_true", default=False)
+ parser.add_option("-v", "--verbose", help="print more information",
+ dest="verbose", action="store_true", default=False)
+
+ (options, args) = parser.parse_args()
script_name = os.path.basename(sys.argv[0])
@@ -239,7 +208,9 @@ if __name__ == "__main__":
print >> sys.stderr, script_name + ": Error: Multiple xpi files specified: " + ", ".join(args)
sys.exit(COMMAND_LINE_SYNTAX_ERROR)
- if verbose:
- print script_name + ": Install %s into package %s." % (args[0], package)
+ if options.verbose:
+ print script_name + ": Install %s into package %s." % (args[0], options.package)
- install_xpi(script_name, package, args[0], exclude, install_dir, links, correct_permissions, remove_licenses, verbose)
+ install_xpi(script_name, options.package, args[0], options.exclude,
+ options.install_dir, set(options.links), options.correct_permissions,
+ options.remove_licenses, options.verbose)