summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--debian/changelog9
-rw-r--r--man/xpi-repack.153
-rw-r--r--src/Makefile1
-rwxr-xr-xsrc/xpi-repack126
4 files changed, 188 insertions, 1 deletions
diff --git a/debian/changelog b/debian/changelog
index 5f932f6..7f9c4cc 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,11 +1,18 @@
mozilla-devscripts (0.21) UNRELEASED; urgency=low
+ [ Micah Gersten <micahg@ubuntu.com> ]
* xulapp.mk:
- add testing and tools directory to clean target for xulrunner-1.9.2
build system
- update src/xulapp.mk.in
- -- Micah Gersten <micahg@ubuntu.com> Tue, 09 Mar 2010 00:28:00 -0600
+ [ Benjamin Drung <bdrung@ubuntu.com> ]
+ * add new xpi-repack script
+ - add man/xpi-repack.1
+ - add src/xpi-repack
+ - update src/Makefile
+
+ -- Benjamin Drung <bdrung@ubuntu.com> Wed, 10 Mar 2010 18:02:17 +0100
mozilla-devscripts (0.20) unstable; urgency=low
diff --git a/man/xpi-repack.1 b/man/xpi-repack.1
new file mode 100644
index 0000000..657b3f7
--- /dev/null
+++ b/man/xpi-repack.1
@@ -0,0 +1,53 @@
+.\"Copyright (c) 2010 Benjamin Drung <bdrung@ubuntu.com>
+.\"
+.\"Permission is hereby granted, free of charge, to any person obtaining a copy
+.\"of this software and associated documentation files (the "Software"), to deal
+.\"in the Software without restriction, including without limitation the rights
+.\"to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+.\"copies of the Software, and to permit persons to whom the Software is
+.\"furnished to do so, subject to the following conditions:
+.\"
+.\"The above copyright notice and this permission notice shall be included in
+.\"all copies or substantial portions of the Software.
+.\"
+.\"THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+.\"IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+.\"FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+.\"AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+.\"LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+.\"OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+.\"THE SOFTWARE.
+.TH XPI-REPACK "1" "March 2010" "xpi-repack" "mozilla-devscripts suite"
+.SH NAME
+xpi-repack \- repack a xpi file into a tarball
+.SH SYNOPSIS
+.B xpi-repack
+[\fIoptions\fP]
+\fIxpi-file\fR
+.SH DESCRIPTION
+.B xpi-repack
+is a helper tool for packaging XUL extensions. It repacks the given xpi file
+into a proper tarball that can be used as source tarball for the Debian package.
+It is designed to work with uscan. Here is an example for debian/watch:
+
+version=3
+.br
+ftp://ftp.mozilla.org/pub/mozilla.org/addons/<id>/<package>-([\\d\\.]+)\-.*\\.xpi debian xpi-repack
+.SH OPTIONS
+.TP
+\fB\-h\fR, \fB\-\-help\fR
+Display a brief help message.
+.TP
+\fB\-p\fR \fIpackage\fP, \fB\-\-package\fR=\fIpackage\fP
+The \fIpackage\fP name will be used for naming the resulting tarball. If this
+parameter is not provided, the source package name in debian/control will be
+used.
+.TP
+\fB\-u\fR \fIversion\fP, \fB\-\-upstream\-version\fR=\fIversion\fP
+The \fIversion\fP will be used for naming the resulting tarball. You have to
+specify this parameter.
+.TP
+\fB\-v\fR, \fB\-\-verbose\fR
+Print more information.
+.SH AUTHOR
+Benjamin Drung <bdrung@gmail.com>
diff --git a/src/Makefile b/src/Makefile
index f802774..593e620 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -57,6 +57,7 @@ bindir_files = \
dh_xul-ext \
install-xpi \
xpi-pack \
+ xpi-repack \
xpi-unpack \
moz-version
diff --git a/src/xpi-repack b/src/xpi-repack
new file mode 100755
index 0000000..fa8429b
--- /dev/null
+++ b/src/xpi-repack
@@ -0,0 +1,126 @@
+#!/usr/bin/python
+
+# Copyright (c) 2010 Benjamin Drung <bdrung@ubuntu.com>
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+
+import getopt
+import os
+import subprocess
+import sys
+
+# error codes
+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)
+
+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]
+
+def usage(output):
+ print >> output, """Usage: %s [options] <xpi-file>
+
+Options:
+ -p, --package=<value> specify source package name
+ -u, --upstream-version=<version> specify the upstream version
+
+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 = ["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)