summaryrefslogtreecommitdiff
path: root/xpi-repack
diff options
context:
space:
mode:
Diffstat (limited to 'xpi-repack')
-rwxr-xr-xxpi-repack64
1 files changed, 23 insertions, 41 deletions
diff --git a/xpi-repack b/xpi-repack
index f6705a2..1642f42 100755
--- a/xpi-repack
+++ b/xpi-repack
@@ -1,6 +1,6 @@
#!/usr/bin/python
-# Copyright (c) 2010-2011, Benjamin Drung <bdrung@debian.org>
+# Copyright (c) 2010-2014, Benjamin Drung <bdrung@debian.org>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
@@ -14,7 +14,7 @@
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-import getopt
+import argparse
import os
import subprocess
import sys
@@ -22,6 +22,7 @@ import sys
# error codes
COMMAND_LINE_SYNTAX_ERROR = 1
+
def remove_recursive(path):
"""equivalent to rm -rf path"""
if os.path.exists(path):
@@ -33,6 +34,7 @@ def remove_recursive(path):
os.remove(full_path)
os.rmdir(path)
+
def repack_xpi(package, upstream_version, xpi_file, verbose):
# extract xpi file
tmp_dir = "/tmp"
@@ -61,6 +63,7 @@ def repack_xpi(package, upstream_version, xpi_file, verbose):
# remove temporary directory
remove_recursive(full_extract_dir)
+
def get_source_package_name(script_name):
if not os.path.isfile("debian/control"):
sys.stderr.write(script_name + ": Error: debian/control file is "
@@ -72,6 +75,7 @@ def get_source_package_name(script_name):
packages = map(lambda x: x[x.find(":")+1:].strip(), package_lines)
return packages[0]
+
def usage(output):
print >> output, """Usage: %s [options] <xpi-file>
@@ -86,47 +90,25 @@ General options:
See %s(1) for more info.""" % (os.path.basename(sys.argv[0]),
os.path.basename(sys.argv[0]))
-def main():
- try:
- long_opts = ["help", "package=", "upstream-version=", "verbose"]
- opts, args = getopt.gnu_getopt(sys.argv[1:], "hp:u:v", long_opts)
- except getopt.GetoptError, e:
- # will print something like "option -a not recognized"
- print >> sys.stderr, str(e)
- usage(sys.stderr)
- sys.exit(COMMAND_LINE_SYNTAX_ERROR)
-
- package = None
- upstream_version = None
- verbose = False
-
- for o, a in opts:
- if o in ("-h", "--help"):
- usage(sys.stdout)
- sys.exit()
- elif o in ("-u", "--upstream-version"):
- upstream_version = a
- elif o in ("-p", "--package"):
- package = a
- elif o in ("-v", "--verbose"):
- verbose = True
- else:
- assert False, "unhandled option"
+def main():
script_name = os.path.basename(sys.argv[0])
-
- if package is None:
- package = get_source_package_name(script_name)
-
- if len(args) == 0:
- print >> sys.stderr, "%s: Error: No xpi file specified." % (script_name)
- sys.exit(COMMAND_LINE_SYNTAX_ERROR)
- elif len(args) > 1:
- print >> sys.stderr, script_name + ": Error: Multiple xpi files " + \
- "specified: " + ", ".join(args)
- sys.exit(COMMAND_LINE_SYNTAX_ERROR)
-
- repack_xpi(package, upstream_version, args[0], verbose)
+ epilog = "See {prog}(1) for more info.".format(prog=script_name)
+ parser = argparse.ArgumentParser(epilog=epilog)
+ parser.add_argument("xpi_file", metavar="<xpi-file>",
+ help=".xpi file that should be repacked")
+ parser.add_argument("-p", "--package", help="specify source package name")
+ parser.add_argument("-u", "--upstream-version", dest="version",
+ help="specify the upstream version")
+ parser.add_argument("-v", "--verbose", action="store_true",
+ help="print more information")
+
+ args = parser.parse_args()
+
+ if not args.package:
+ args.package = get_source_package_name(script_name)
+
+ repack_xpi(args.package, args.version, args.xpi_file, args.verbose)
if __name__ == "__main__":
main()