summaryrefslogtreecommitdiff
path: root/src/xpi-repack
diff options
context:
space:
mode:
Diffstat (limited to 'src/xpi-repack')
-rwxr-xr-xsrc/xpi-repack167
1 files changed, 87 insertions, 80 deletions
diff --git a/src/xpi-repack b/src/xpi-repack
index fa8429b..0852dfc 100755
--- a/src/xpi-repack
+++ b/src/xpi-repack
@@ -29,50 +29,52 @@ import sys
COMMAND_LINE_SYNTAX_ERROR = 1
def remove_recursive(path):
- """equivalent to rm -rf path"""
- if os.path.exists(path):
- for i in os.listdir(path):
- full_path = os.path.join(path, i)
- if os.path.isdir(full_path):
- remove_recursive(full_path)
- else:
- os.remove(full_path)
- os.rmdir(path)
-
-def repack_xpi(script_name, package, upstream_version, xpi_file, verbose):
- # extract xpi file
- tmp_dir = "/tmp"
- extract_dir = package + "-" + upstream_version
- full_extract_dir = os.path.join(tmp_dir, extract_dir)
- remove_recursive(full_extract_dir)
- subprocess.check_call(["xpi-unpack", xpi_file, full_extract_dir])
-
- # check, if source 3.0 (quilt) format is used
- extension = ".gz"
- if os.path.isfile("debian/source/format"):
- source_format = open("debian/source/format").readline().strip()
- if source_format == "3.0 (quilt)":
- extension = ".bz2"
-
- # pack source
- tar_file = package + "_" + upstream_version + ".orig.tar"
- full_tar_file = os.path.realpath(os.path.join(os.path.dirname(xpi_file), tar_file))
- cmd = ["tar", "-ca", "-C", tmp_dir, "-f", full_tar_file + extension, extract_dir]
- if verbose:
- print " ".join(cmd)
- subprocess.check_call(cmd)
-
- # remove temporary directory
- remove_recursive(full_extract_dir)
+ """equivalent to rm -rf path"""
+ if os.path.exists(path):
+ for i in os.listdir(path):
+ full_path = os.path.join(path, i)
+ if os.path.isdir(full_path):
+ remove_recursive(full_path)
+ else:
+ os.remove(full_path)
+ os.rmdir(path)
+
+def repack_xpi(package, upstream_version, xpi_file, verbose):
+ # extract xpi file
+ tmp_dir = "/tmp"
+ extract_dir = package + "-" + upstream_version
+ full_extract_dir = os.path.join(tmp_dir, extract_dir)
+ remove_recursive(full_extract_dir)
+ subprocess.check_call(["xpi-unpack", xpi_file, full_extract_dir])
+
+ # check, if source 3.0 (quilt) format is used
+ extension = ".gz"
+ if os.path.isfile("debian/source/format"):
+ source_format = open("debian/source/format").readline().strip()
+ if source_format == "3.0 (quilt)":
+ extension = ".bz2"
+
+ # pack source
+ tar_file = package + "_" + upstream_version + ".orig.tar"
+ full_tar_file = os.path.realpath(os.path.join(os.path.dirname(xpi_file),
+ tar_file))
+ cmd = ["tar", "-ca", "-C", tmp_dir, "-f", full_tar_file + extension,
+ extract_dir]
+ if verbose:
+ print " ".join(cmd)
+ subprocess.check_call(cmd)
+
+ # remove temporary directory
+ remove_recursive(full_extract_dir)
def get_source_package_name():
- lines = open("debian/control").readlines()
- package_lines = filter(lambda x: x.find("Source:") >= 0, lines)
- packages = map(lambda x: x[x.find(":")+1:].strip(), package_lines)
- return packages[0]
+ lines = open("debian/control").readlines()
+ package_lines = filter(lambda x: x.find("Source:") >= 0, lines)
+ packages = map(lambda x: x[x.find(":")+1:].strip(), package_lines)
+ return packages[0]
def usage(output):
- print >> output, """Usage: %s [options] <xpi-file>
+ print >> output, """Usage: %s [options] <xpi-file>
Options:
-p, --package=<value> specify source package name
@@ -82,45 +84,50 @@ 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]))
+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"
+
+ if package is None:
+ package = get_source_package_name()
+
+ script_name = os.path.basename(sys.argv[0])
+
+ 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)
if __name__ == "__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"
-
- if package is None:
- package = get_source_package_name()
-
- script_name = os.path.basename(sys.argv[0])
-
- 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(script_name, package, upstream_version, args[0], verbose)
+ main()