From 55869ffc370604e71307910774169aaad154c0d4 Mon Sep 17 00:00:00 2001 From: Benjamin Drung Date: Tue, 11 Oct 2011 23:32:08 +0200 Subject: Move scripts and Python modules one level up to correct installation directory. --- Makefile | 2 +- data/xpi.mk | 142 ++++++++++ data/xul-app-data.csv.Debian | 5 + data/xul-app-data.csv.Ubuntu | 4 + debian/copyright | 10 +- dh_xul-ext | 381 ++++++++++++++++++++++++++ install-xpi | 258 +++++++++++++++++ moz-version | 154 +++++++++++ moz_version.py | 212 ++++++++++++++ perl/Debian/Buildsystem/xul_ext.pm | 43 +++ perl/Debian/Sequence/xul_ext.pm | 8 + setup.py | 10 +- src/Buildsystem/xul_ext.pm | 43 --- src/Sequence/xul_ext.pm | 8 - src/dh_xul-ext | 381 -------------------------- src/install-xpi | 258 ----------------- src/moz-version | 154 ----------- src/moz_version.py | 212 -------------- src/xpi-pack | 89 ------ src/xpi-repack | 127 --------- src/xpi-unpack | 76 ----- src/xpi.mk | 142 ---------- src/xul-app-data.csv.Debian | 5 - src/xul-app-data.csv.Ubuntu | 4 - tests/dh_xul-ext/all/debian/rules | 2 +- tests/dh_xul-ext/all_environment/debian/rules | 2 +- tests/dh_xul-ext/debian/debian/rules | 2 +- tests/dh_xul-ext/ubuntu/debian/rules | 2 +- tests/test-moz-version | 2 +- xpi-pack | 89 ++++++ xpi-repack | 127 +++++++++ xpi-unpack | 76 +++++ 32 files changed, 1515 insertions(+), 1515 deletions(-) create mode 100644 data/xpi.mk create mode 100644 data/xul-app-data.csv.Debian create mode 100644 data/xul-app-data.csv.Ubuntu create mode 100755 dh_xul-ext create mode 100755 install-xpi create mode 100755 moz-version create mode 100644 moz_version.py create mode 100644 perl/Debian/Buildsystem/xul_ext.pm create mode 100644 perl/Debian/Sequence/xul_ext.pm delete mode 100644 src/Buildsystem/xul_ext.pm delete mode 100644 src/Sequence/xul_ext.pm delete mode 100755 src/dh_xul-ext delete mode 100755 src/install-xpi delete mode 100755 src/moz-version delete mode 100644 src/moz_version.py delete mode 100755 src/xpi-pack delete mode 100755 src/xpi-repack delete mode 100755 src/xpi-unpack delete mode 100644 src/xpi.mk delete mode 100644 src/xul-app-data.csv.Debian delete mode 100644 src/xul-app-data.csv.Ubuntu create mode 100755 xpi-pack create mode 100755 xpi-repack create mode 100755 xpi-unpack diff --git a/Makefile b/Makefile index 7ebe77d..3d78412 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,6 @@ install: python setup.py install --root="$(DESTDIR)" --no-compile --install-layout=deb clean: - rm -rf build src/*.pyc + rm -rf build *.pyc .PHONY: build clean install test diff --git a/data/xpi.mk b/data/xpi.mk new file mode 100644 index 0000000..77b8720 --- /dev/null +++ b/data/xpi.mk @@ -0,0 +1,142 @@ +# -*- mode: makefile; coding: utf-8 -*- + +# Copyright (c) 2008-2009 Canonical Ltd. +# Author(s): Alexander Sack +# Fabien Tassin +# Benjamin Drung +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + +# +# Usage: include this file in your CDBS debian/rules file and define the +# following variables: +# +# MOZ_EXTENSION_PKG (OPTIONAL): +# if defined the given binary package name is used to ship +# this xpi; otherwise the first binary package listed in +# debian/control is used +# +# MOZ_XPI_FILE (OPTIONAL): +# if defined the given .xpi file is used; otherwise we try to +# guess one using wildcard (*.xpi) +# +# MOZ_XPI_BUILD_COMMAND (OPTIONAL): +# if defined the given command will be run _before_ the extension +# gets packaged up the standard .xpi way. Thus, the build command +# should produce an .xpi in top level directory. Note: If this +# command is specified, MOZ_XPI_CLEAN_COMMAND (see below) will be +# run during |clean|. If the .xpi file will not be build from +# source, you have to set this variable to nothing. +# +# MOZ_XPI_CLEAN_COMMAND (OPTIONAL): +# only has an effect if MOZ_XPI_BUILD_COMMAND (see above) is set. +# It defaults to `rm -f *.xpi`. +# +# MOZ_XPI_MOZILLA_EXTRA_DIRS (OPTIONAL): +# defines extra directories to link the extension in. Usually +# xpi.mk creates the right links based on targetApplication +# parsed in install.rdf; if you need more directories, use this. +# +# MOZ_XPI_DOCUMENTED_LICENSE_FILES (OPTIONAL): +# defines extra license files which need to be excluded during +# the installation of the XPI file to the packaging tree. When +# using parameter, be sure that you documented _all_ excluded +# license files in debian/copyright appropriately. If not defined +# the common license file names are guessed. +# +# MOZ_XPI_EXT_NAME (OPTIONAL): +# defines the name of the extension (without any prefixes like +# mozilla- or xul-ext-). If not defined MOZ_EXTENSION_PKG with +# stripped prefixes is used. This value is used to determine +# xpi:Provides. +# +# MOZ_XPI_PRESERVE_PERMISSIONS (OPTIONAL): +# if defined (set to 1), the permission of the installed files +# will not be changed. If not defined or set to $(null), the +# permission of the files will be set to 644 and the permissions +# of scripts (files containing a shebang) will be set to 755. +# +# MOZ_XPI_INSTALL_DIRECTORY (OPTIONAL): +# The xpi file will be installed in the specified directory. +# This directory must be an absolute path. Use this parameter +# with care. +# +# MOZ_XPI_DISABLE_SYSTEM_PREFS (OPTIONAL): +# if defined (set to 1), no system preference file will be +# created in /etc. +# +# Unused variables (can be removed): +# +# MOZ_XPI_EMID (OPTIONAL): +# if defined the given id is used to determine the link name +# in the Firefox extensions directory. if not defined we try +# our best to extract the em:id from the install.rdf file shipped +# by any xpi +# '''Note''': this variable is not used any more + +MOZ_EXTENSION_PKG ?= $(strip $(shell grep ^Package: debian/control | head -n 1 | sed "s/^Package://")) + +MOZ_XPI_BUILD_COMMAND ?= xpi-pack $(CURDIR) $(MOZ_EXTENSION_PKG).xpi +MOZ_XPI_CLEAN_COMMAND ?= rm -f *.xpi + +ifneq (,$(MOZ_XPI_FILE)) +xpi_file = $(wildcard $(MOZ_XPI_FILE)) +else +xpi_file = $(wildcard *.xpi) +endif + +ifneq (,$(MOZ_XPI_PRESERVE_PERMISSIONS)) +install_xpi_extra_parameter += --preserve-permissions +endif + +ifneq (,$(MOZ_XPI_DISABLE_SYSTEM_PREFS)) +install_xpi_extra_parameter += --disable-system-prefs +endif + +ifneq (,$(MOZ_XPI_INSTALL_DIRECTORY)) +install_xpi_extra_parameter += -i $(MOZ_XPI_INSTALL_DIRECTORY) +endif + +ifeq ($(origin MOZ_XPI_DOCUMENTED_LICENSE_FILES),undefined) +install_xpi_extra_parameter += --remove-license-files +else +install_xpi_extra_parameter += $(foreach exclude,$(MOZ_XPI_DOCUMENTED_LICENSE_FILES),-x $(exclude)) +endif + +install_xpi_extra_parameter += $(foreach dir,$(MOZ_XPI_MOZILLA_EXTRA_DIRS),-l $(dir)) + +# ### cdbs hooks +# build xpi using MOZ_XPI_BUILD_COMMAND if defined +build/$(MOZ_EXTENSION_PKG):: +ifneq (,$(MOZ_XPI_BUILD_COMMAND)) + $(MOZ_XPI_BUILD_COMMAND) +endif + +install/$(MOZ_EXTENSION_PKG):: xpi-install + +xpi-install: + install-xpi -p$(MOZ_EXTENSION_PKG) $(xpi_file) $(install_xpi_extra_parameter) + dh_xul-ext -p$(MOZ_EXTENSION_PKG) + +# clean build and remove all .xpi in top-level if a MOZ_XPI_BUILD_COMMAND is defined +ifneq (,$(MOZ_XPI_BUILD_COMMAND)) +clean:: + dh_testdir + dh_clean + $(MOZ_XPI_CLEAN_COMMAND) +endif + +.PHONY: clean xpi-install diff --git a/data/xul-app-data.csv.Debian b/data/xul-app-data.csv.Debian new file mode 100644 index 0000000..eb98c84 --- /dev/null +++ b/data/xul-app-data.csv.Debian @@ -0,0 +1,5 @@ +id,package,sol,eol +{ec8030f7-c20a-464f-9b0e-13a3a9e97384},iceweasel,2.0,* +{3550f703-e582-4d05-9a08-453d09bdfdc6},icedove,1.5.0.7,* +{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a},iceape,1.0.6,* +{a79fe89b-6662-4ff4-8e88-09950ad4dfde},conkeror,0.9,* diff --git a/data/xul-app-data.csv.Ubuntu b/data/xul-app-data.csv.Ubuntu new file mode 100644 index 0000000..031c5e0 --- /dev/null +++ b/data/xul-app-data.csv.Ubuntu @@ -0,0 +1,4 @@ +id,package,sol,eol +{ec8030f7-c20a-464f-9b0e-13a3a9e97384},firefox,3.6a1pre,* +{3550f703-e582-4d05-9a08-453d09bdfdc6},thunderbird,2.0,* +{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a},seamonkey,1.1.6,* diff --git a/debian/copyright b/debian/copyright index 6abb7fe..680d4db 100644 --- a/debian/copyright +++ b/debian/copyright @@ -24,20 +24,20 @@ Copyright: 2007-2009, Sasa Bodiroza 2007-2009, Fabien Tassin License: GPL-2+ -Files: man/xpi-pack.1 man/xpi-unpack.1 +Files: xpi-pack xpi-unpack Copyright: 2007-2009, Sasa Bodiroza + 2007-2009, Alexander Sack License: GPL-2+ -Files: src/xpi.mk +Files: data/xpi.mk Copyright: 2008-2009 Canonical Ltd. License: GPL-2+ -Files: src/xpi-pack src/xpi-unpack +Files: man/xpi-pack.1 man/xpi-unpack.1 Copyright: 2007-2009, Sasa Bodiroza - 2007-2009, Alexander Sack License: GPL-2+ -Files: src/Buildsystem/xul_ext.pm src/Sequence/xul_ext.pm +Files: perl/Debian/Buildsystem/xul_ext.pm perl/Debian/Sequence/xul_ext.pm Copyright: 2010, Mike Hommey License: GPL-2+ diff --git a/dh_xul-ext b/dh_xul-ext new file mode 100755 index 0000000..e87fd6b --- /dev/null +++ b/dh_xul-ext @@ -0,0 +1,381 @@ +#!/usr/bin/python + +# Copyright (c) 2009-2011, Benjamin Drung +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +import csv +import glob +import optparse +import os +import subprocess +import sys + +from moz_version import (compare_versions, convert_moz_to_debian_version, + moz_to_next_debian_version) + +import RDF + +_VENDOR_ENV = "DH_XUL_EXT_VENDOR" +# error codes +COMMAND_LINE_SYNTAX_ERROR = 1 +MULTIPLE_INSTALL_RDFS = 2 + +class XulApp(object): + def __init__(self, xul_id, package, sol, eol): + self.xul_id = xul_id + self.package = package + self.sol = sol + self.eol = eol + self.min_version = None + self.max_version = None + + def __str__(self): + return self.xul_id + ": " + self.package + " (" + self.sol + " to " + \ + self.eol + ")" + + def get_breaks(self): + """Return a string for ${xpi:Breaks} for the XUL application.""" + breaks = [] + if self.min_version: + deb_min_version = convert_moz_to_debian_version(self.min_version) + breaks.append(self.package + " (<< " + deb_min_version + ")") + if self.max_version: + deb_max_version = moz_to_next_debian_version(self.max_version) + breaks.append(self.package + " (>= " + deb_max_version + ")") + return ", ".join(breaks) + + def get_eol(self): + return self.eol + + def get_id(self): + return self.xul_id + + def get_package(self): + return self.package + + def get_sol(self): + return self.sol + + def get_versioned_package(self): + versioned_package = self.package + if self.min_version: + deb_min_version = convert_moz_to_debian_version(self.min_version) + versioned_package += " (>= " + deb_min_version + ")" + return versioned_package + + def is_same_package(self, xul_app): + return self.xul_id == xul_app.xul_id and self.package == xul_app.package + + def set_max_version(self, max_version): + if compare_versions(self.eol, max_version) > 0: + self.max_version = max_version + + def set_min_version(self, min_version): + if compare_versions(self.sol, min_version) < 0: + self.min_version = min_version + + def update_version(self, sol, eol): + if compare_versions(self.sol, sol) > 0: + self.sol = sol + if compare_versions(self.eol, eol) < 0: + self.eol = eol + + +def _get_data_dir(): + """Get the data directory based on the module location.""" + if __file__.startswith("/usr/bin"): + data_dir = "/usr/share/mozilla-devscripts" + else: + data_dir = os.path.join(os.path.dirname(__file__), "data") + return data_dir + +def get_vendor(): + """This function returns the vendor (e.g. Debian, Ubuntu) that should be + used for calculating the dependencies. DH_XUL_EXT_VENDOR will be used + if set. Otherwise dpkg-vendor will be used for determining the vendor.""" + if _VENDOR_ENV in os.environ: + vendor = os.environ[_VENDOR_ENV] + else: + cmd = ["dpkg-vendor", "--query", "Vendor"] + process = subprocess.Popen(cmd, stdout=subprocess.PIPE) + vendor = process.communicate()[0].strip() + return vendor + +def get_xul_apps(script_name, all_distros): + vendor = get_vendor() + data_dir = _get_data_dir() + if all_distros or vendor == "all": + csv_filenames = sorted(glob.glob(os.path.join(data_dir, + "xul-app-data.csv.*"))) + else: + csv_filename = os.path.join(data_dir, "xul-app-data.csv." + vendor) + if not os.path.isfile(csv_filename): + print >> sys.stderr, ('%s: Unknown vendor "%s" specified.' % + (script_name, vendor)) + sys.exit(1) + csv_filenames = [csv_filename] + + xul_apps = [] + for csv_filename in csv_filenames: + csvfile = open(csv_filename) + csv_reader = csv.DictReader(csvfile) + for row in csv_reader: + xul_app = XulApp(row["id"], row["package"], row["sol"], row["eol"]) + existing = [x for x in xul_apps if x.is_same_package(xul_app)] + if existing: + xul_app = existing[0] + xul_app.update_version(row["sol"], row["eol"]) + else: + xul_apps.append(xul_app) + + return xul_apps + +def _get_id_max_min_triple(install_rdf): + """create array of id_max_min triples""" + id_max_min = [] + model = RDF.Model() + parser = RDF.Parser(name="rdfxml") + parser.parse_into_model(model, "file:" + install_rdf) + query = RDF.Query( + """ + PREFIX em: + SELECT ?id ?max ?min + WHERE { + ?x1 em:targetApplication ?x2 . + ?x2 em:id ?id . + OPTIONAL { + ?x2 em:maxVersion ?max . + ?x2 em:minVersion ?min . + } . + } + """, query_language="sparql") + results = query.execute(model) + # append to id_max_min tripe to array + for target in results: + id_max_min.append ((target["id"].literal_value["string"], + target["max"].literal_value["string"], + target["min"].literal_value["string"])) + return id_max_min + +def get_supported_apps(script_name, xul_apps, install_rdf, package, + verbose=False): + id_max_min = _get_id_max_min_triple(install_rdf) + if verbose: + print "%s: %s supports %i XUL application(s):" % (script_name, package, + len(id_max_min)) + for (appid, max_version, min_version) in id_max_min: + print "%s %s to %s" % (appid, min_version, max_version) + + # find supported apps/packages + supported_apps = list() + for xul_app in xul_apps: + supported_app = [x for x in id_max_min if x[0] == xul_app.get_id()] + if len(supported_app) == 1: + # package is supported by extension + (appid, max_version, min_version) = supported_app.pop() + if compare_versions(xul_app.get_sol(), max_version) <= 0: + if compare_versions(xul_app.get_eol(), min_version) >= 0: + xul_app.set_min_version(min_version) + xul_app.set_max_version(max_version) + supported_apps.append(xul_app) + if verbose: + print "%s: %s supports %s." % (script_name, package, + xul_app.get_package()) + elif verbose: + print "%s: %s does not support %s (any more)." % \ + (script_name, package, xul_app.get_package()) + elif verbose: + print "%s: %s does not support %s (yet)." % \ + (script_name, package, xul_app.get_package()) + elif len(supported_app) > 1: + print ("%s: Found error in %s. There are multiple entries for " + "application ID %s.") % (script_name, install_rdf, + xul_app.get_id()) + + return supported_apps + +def get_all_packages(): + lines = open("debian/control").readlines() + package_lines = [x for x in lines if x.find("Package:") >= 0] + packages = [p[p.find(":")+1:].strip() for p in package_lines] + return packages + +def get_source_package_name(): + source = None + control_file = open("debian/control") + for line in control_file: + if line.startswith("Source:"): + source = line[line.find(":")+1:].strip() + break + return source + +def has_no_xpi_depends(): + lines = open("debian/control").readlines() + xpi_depends_lines = [l for l in lines if l.find("${xpi:Depends}") >= 0] + return len(xpi_depends_lines) == 0 + +def get_provided_package_names(package, supported_apps): + ext_name = package + for prefix in ("firefox-", "iceweasel-", "mozilla-", "xul-ext-"): + if ext_name.startswith(prefix): + ext_name = ext_name[len(prefix):] + + # check if MOZ_XPI_EXT_NAME is defined in debian/rules + lines = open("debian/rules").readlines() + lines = [l for l in lines if l.find("MOZ_XPI_EXT_NAME") != -1] + if len(lines) > 0: + line = lines[-1] + ext_name = line[line.find("=")+1:].strip() + + provides = set() + provides.add("xul-ext-" + ext_name) + if ext_name == get_source_package_name(): + provides.add(ext_name) + + for xul_app in supported_apps: + app = xul_app.get_package() + for i in xrange(len(app) - 1, -1, -1): + if app[i] == '-': + app = app[:i] + elif not app[i].isdigit() and not app[i] == '.': + break + provides.add(app + "-" + ext_name) + + # remove package name from provide list + provides.discard(package) + + return list(provides) + +def find_install_rdfs(path): + install_rdfs = set() + + if os.path.isfile(path) and os.path.basename(path) == "install.rdf": + install_rdfs.add(os.path.realpath(path)) + + if os.path.isdir(path): + # recursive walk + content = [os.path.join(path, d) for d in os.listdir(path)] + install_rdfs = reduce(lambda x, d: x.union(find_install_rdfs(d)), + content, install_rdfs) + + return install_rdfs + +def generate_substvars(script_name, xul_apps, package, verbose=False): + install_rdfs = find_install_rdfs("debian/" + package) + if len(install_rdfs) == 0: + if verbose: + print script_name + ": " + package + \ + " does not contain a XUL extension (no install.rdf found)." + return + elif len(install_rdfs) > 1: + print >> sys.stderr, ("%s: %s contains multiple install.rdf files. " + "That's not supported.") % (script_name, package) + basepath_len = len(os.path.realpath("debian/" + package)) + rdfs = [x[basepath_len:] for x in install_rdfs] + print >> sys.stderr, "\n".join(rdfs) + sys.exit(MULTIPLE_INSTALL_RDFS) + install_rdf = install_rdfs.pop() + + filename = "debian/" + package + ".substvars" + if os.path.exists(filename): + substvars_file = open(filename) + lines = substvars_file.readlines() + substvars_file.close() + else: + lines = list() + + # remove existing varibles + lines = [s for s in lines if not s.startswith("xpi:")] + + supported_apps = get_supported_apps(script_name, xul_apps, install_rdf, + package, verbose) + packages = [a.get_versioned_package() for a in supported_apps] + if has_no_xpi_depends(): + # Use xpi:Recommends instead of xpi:Depends for backwards compatibility + print ("%s: Warning: Please add ${xpi:Depends} to Depends. Using only " + "${xpi:Recommends} is deprecated.") % (script_name) + lines.append("xpi:Recommends=" + " | ".join(packages) + "\n") + else: + lines.append("xpi:Depends=" + " | ".join(packages) + "\n") + lines.append("xpi:Recommends=\n") + packages = [a.get_breaks() for a in supported_apps] + lines.append("xpi:Breaks=" + ", ".join(sorted(packages)) + "\n") + packages = [a.get_package() for a in supported_apps] + lines.append("xpi:Enhances=" + ", ".join(sorted(packages)) + "\n") + packages = get_provided_package_names(package, supported_apps) + lines.append("xpi:Provides=" + ", ".join(sorted(packages)) + "\n") + + # write new variables + substvars_file = open(filename, "w") + substvars_file.writelines(lines) + substvars_file.close() + + +class UnknownOptionIgnoringOptionParser(optparse.OptionParser): + def __init__ (self, **options): + optparse.OptionParser.__init__(self, **options) + self.unknown_options = [] + + 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) + + +def main(): + script_name = os.path.basename(sys.argv[0]) + epilog = "See %s(1) for more info." % (script_name) + parser = UnknownOptionIgnoringOptionParser(epilog=epilog) + parser.add_option("-a", "--all", action="store_true", dest="all", + help="expand substvars to all known XUL applications " + "(not only of your distribution)", default=False) + 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 = parser.parse_args()[0] + + if len(options.packages) == 0: + options.packages = get_all_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(script_name, options.all) + 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 + + for package in options.packages: + generate_substvars(script_name, xul_apps, package, options.verbose) + +if __name__ == "__main__": + main() diff --git a/install-xpi b/install-xpi new file mode 100755 index 0000000..ddd7b1a --- /dev/null +++ b/install-xpi @@ -0,0 +1,258 @@ +#!/usr/bin/python + +# Copyright (c) 2009-2011, Benjamin Drung +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +import csv +import optparse +import os +import stat +import subprocess +import sys +import zipfile + +import RDF + +LICENSE_PATTERN_LIST = ( + "copying", + "gpl.txt", + "licence", + "license", + "licence.txt", + "license.txt" +) + +# error codes +COMMAND_LINE_SYNTAX_ERROR = 1 +XPI_FILE_DOES_NOT_EXISTS = 2 + +def get_query_field_id_as_list(rdf_path, query_string): + ret = [] + model = RDF.Model() + parser = RDF.Parser(name="rdfxml") + parser.parse_into_model(model, "file:" + rdf_path) + query = RDF.Query("PREFIX em: " + \ + query_string, query_language="sparql") + results = query.execute(model) + for result in results: + ret.append(result["id"].literal_value["string"]) + return ret + +def get_target_applications(install_rdf): + target_applications = get_query_field_id_as_list(install_rdf, + "SELECT ?id WHERE { ?x1 em:targetApplication ?x2 . ?x2 em:id ?id }") + return target_applications + +def get_extension_id(install_rdf): + extension_ids = set(get_query_field_id_as_list(install_rdf, + "SELECT ?id WHERE {?x1 em:targetApplication ?x2 . ?x1 em:id ?id }")) + return extension_ids.pop() + +def get_arch(package): + lines = open("debian/control").readlines() + package_lines = filter(lambda x: x.find("Package:") >= 0, lines) + packages = map(lambda x: x[x.find(":")+1:].strip(), package_lines) + architecture_lines = filter(lambda x: x.find("Architecture:") >= 0, lines) + architectures = map(lambda x: x[x.find(":")+1:].strip(), architecture_lines) + (_, arch) = filter(lambda (x, y): x == package, + zip(packages, architectures))[0] + return arch + +def get_mode(filename): + statinfo = os.stat(filename) + mode = statinfo[stat.ST_MODE] + return mode & 0777 + +def get_xul_apps(): + csvfile = open("/usr/share/mozilla-devscripts/xul-app-data.csv") + csv_reader = csv.DictReader(csvfile) + rows = [] + for row in csv_reader: + rows.append(row) + return rows + +def install_xpi(script_name, package, xpi_file, exclude, install_dir, links, + correct_permissions, remove_licenses, system_prefs, 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) + sys.exit(XPI_FILE_DOES_NOT_EXISTS) + zfobj = zipfile.ZipFile(xpi_file) + xpi_content = zfobj.namelist() + + # determine installation directory + if get_arch(package) == "all": + lib_share_dir = "share" + else: + lib_share_dir = "lib" + if install_dir is None: + install_dir = os.path.join("usr", lib_share_dir, "xul-ext", + package.replace("xul-ext-", "")) + copy_dir = os.path.join("debian", package, install_dir.strip("/")) + if verbose: + print "%s: install directory: %s" % (script_name, install_dir) + + # remove documented license files + if remove_licenses: + for name in filter(lambda x: not x.endswith('/'), xpi_content): + basename = os.path.basename(name).lower() + if basename in LICENSE_PATTERN_LIST: + exclude.append(name) + print "%s: exclude license file %s" % (script_name, name) + + # create directory and extract xpi file + if not os.path.isdir(copy_dir): + os.makedirs(copy_dir) + command = ["unzip", "-o", "-d", copy_dir, xpi_file] + if len(exclude) > 0: + command.append("-x") + command.extend(exclude) + print " ".join(command) + subprocess.call(command) + + # correct permissons of files to 644 and directories to 755 + if correct_permissions: + for name in xpi_content: + filename = os.path.join(copy_dir, name) + if os.path.exists(filename): + mode = get_mode(filename) + if os.path.isdir(filename) and mode != 0755: + print "%s: correct permission from %s to %s of %s" % \ + (script_name, oct(mode), oct(0755), name) + os.chmod(filename, 0755) + elif os.path.isfile(filename): + header = open(filename, "r").read(2) + if header != "#!" and mode != 0644: + # file without shebang + print "%s: correct permission from %s to %s of %s" % \ + (script_name, oct(mode), oct(0644), name) + os.chmod(filename, 0644) + elif header == "#!" and mode != 0755: + # file with shebang + print "%s: correct permission from %s to %s of %s" % \ + (script_name, oct(mode), oct(0755), name) + os.chmod(filename, 0755) + + # create a system preference file in /etc + if system_prefs: + # search for preference files + pref_dir = os.path.join("defaults", "preferences") + preferences = filter(lambda f: os.path.dirname(f) == pref_dir and \ + f.endswith(".js"), xpi_content) + if len(preferences) > 0: + prefdir = os.path.join("etc", "xul-ext") + full_prefdir = os.path.join("debian", package, prefdir) + if not os.path.exists(full_prefdir): + os.makedirs(full_prefdir) + prefname = package.replace("xul-ext-", "") + ".js" + # create system preference file + f = open(os.path.join(full_prefdir, prefname), "w") + if os.path.isfile(os.path.join("debian", package + ".js")): + # use debian/package.js as configuration file if it exists + content = open(os.path.join("debian", package + ".js")).read() + # replace @INSTALLDIR@ by the actual installation directory + content = content.replace("@INSTALLDIR@", + os.path.join("/", install_dir)) + f.write(content) + else: + f.write("// Place your preferences for " + package + + " in this file.\n") + f.write("// You can override here the preferences specified " + "in\n") + map(lambda x: f.write("// " + + os.path.join("/", install_dir, x) + + "\n"), preferences) + f.close() + link_source = os.path.join(prefdir, prefname) + link_target = os.path.join(install_dir, "defaults", "preferences", + "000system.js") + command = ["dh_link", "-p" + package, link_source, link_target] + if verbose: + print " ".join(command) + subprocess.call(command) + + # get symlinks list + extension_id = get_extension_id(os.path.join(copy_dir, "install.rdf")) + filename = os.path.join(copy_dir, "install.rdf") + target_applications = get_target_applications(filename) + for target_application in target_applications: + destination = os.path.join("/usr", lib_share_dir, "mozilla/extensions", + target_application, extension_id) + links.add(destination) + + # create symlinks + for link in links: + command = ["dh_link", "-p" + package, install_dir, link] + print " ".join(command) + subprocess.call(command) + +def get_first_package(): + lines = open("debian/control").readlines() + package_lines = filter(lambda x: x.find("Package:") >= 0, lines) + packages = map(lambda x: x[x.find(":")+1:].strip(), package_lines) + return packages[0] + +def main(): + usage = "%s [options] " % (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("--disable-system-prefs", + help="do not create a system preference file in /etc", + dest="system_prefs", action="store_false", default=True) + 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]) + + 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, "%s: Error: Multiple xpi files specified: %s" % \ + (script_name, ", ".join(args)) + sys.exit(COMMAND_LINE_SYNTAX_ERROR) + + if options.verbose: + print script_name + ": Install %s into package %s." % \ + (args[0], options.package) + + install_xpi(script_name, options.package, args[0], options.exclude, + options.install_dir, set(options.links), + options.correct_permissions, options.remove_licenses, + options.system_prefs, options.verbose) + +if __name__ == "__main__": + main() diff --git a/moz-version b/moz-version new file mode 100755 index 0000000..6362b31 --- /dev/null +++ b/moz-version @@ -0,0 +1,154 @@ +#!/usr/bin/python + +# Copyright (c) 2009-2011, Benjamin Drung +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# 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 os +import sys + +from moz_version import (compare_versions, convert_debian_to_moz_version, + convert_moz_to_debian_version) + +# error codes +COMMAND_LINE_SYNTAX_ERROR = 2 +INVALID_COMPARATOR = 3 +EMPTY_VERSION_STRING = 4 + +COMPARATORS = ("lt", "le", "eq", "ne", "ge", "gt") + +def moz_version_compare(version1, comparator, version2, silent=False, + verbose=False): + """Return true if the expression version1 comparator version2 is valid, + otherwise false""" + if comparator not in COMPARATORS: + if not silent: + print >> sys.stderr, "E: The comparator " + comparator + \ + " is not valid. It should one of " + \ + ", ".join(COMPARATORS) + "." + sys.exit(INVALID_COMPARATOR) + + if version1.strip() == "" or version2.strip() == "": + if not silent: + print >> sys.stderr, "E: At least one version string is empty." + sys.exit(EMPTY_VERSION_STRING) + + if verbose: + symbol = {"lt": "<", "le": "<=", "eq": "=", "ne": "!=", + "ge": ">=", "gt": ">"} + print "I: Comparing %s %s %s." % \ + (version1, symbol[comparator], version2) + + if comparator == "lt": + return compare_versions(version1, version2, verbose) < 0 + elif comparator == "le": + return compare_versions(version1, version2, verbose) <= 0 + elif comparator == "eq": + return compare_versions(version1, version2, verbose) == 0 + elif comparator == "ne": + return compare_versions(version1, version2, verbose) != 0 + elif comparator == "ge": + return compare_versions(version1, version2, verbose) >= 0 + elif comparator == "gt": + return compare_versions(version1, version2, verbose) > 0 + + +def usage(output): + name = os.path.basename(sys.argv[0]) + print >> output, """Usage: %s [options] action + +Actions: + -c, --compare version1 comparator version2 + compare both Mozilla version numbers + comparator must be one of %s + -d, --to-deb version converts Mozilla into a Debian upstream version + -m, --to-moz version converts Debian into a Mozilla version + +Options: + -h, --help display this help and exit + -s, --silent do not print anything and die silent on errors + -v, --verbose print more information + +See %s(1) for more info.""" % (name, ", ".join(COMPARATORS), name) + + +def main(): + try: + long_opts = ["compare", "help", "silent", "to-deb", "to-moz", "verbose"] + opts, args = getopt.gnu_getopt(sys.argv[1:], "cdhmsv", long_opts) + except getopt.GetoptError, e: + # print help information and exit: + print >> sys.stderr, str(e) + usage(sys.stderr) + sys.exit(COMMAND_LINE_SYNTAX_ERROR) + + actions = set() + silent = False + verbose = False + + for o, _ in opts: + if o in ("-c", "--compare"): + actions.add("compare") + elif o in ("-d", "--to-deb"): + actions.add("to-deb") + elif o in ("-h", "--help"): + usage(sys.stdout) + sys.exit() + elif o in ("-m", "--to-moz"): + actions.add("to-moz") + elif o in ("-s", "--silent"): + silent = True + elif o in ("-v", "--verbose"): + verbose = True + else: + assert False, "unhandled option" + + if len(actions) != 1: + if not silent: + print >> sys.stderr, "E: You must specify an action." + usage(sys.stderr) + sys.exit(COMMAND_LINE_SYNTAX_ERROR) + + action = actions.pop() + + if action == "compare": + if len(args) != 3: + if not silent: + usage(sys.stderr) + sys.exit(COMMAND_LINE_SYNTAX_ERROR) + if moz_version_compare(args[0], args[1], args[2], silent, verbose): + if verbose: + print "I: Compare expression true." + sys.exit(0) + else: + if verbose: + print "I: Compare expression false." + sys.exit(1) + elif action == "to-deb": + if len(args) != 1: + if not silent: + print >> sys.stderr, "E: The action --to-deb takes exactly " + \ + "one argument." + sys.exit(COMMAND_LINE_SYNTAX_ERROR) + print convert_moz_to_debian_version(args[0], 0, verbose) + elif action == "to-moz": + if len(args) != 1: + if not silent: + print >> sys.stderr, "E: The action --to-moz takes exactly " + \ + "one argument." + sys.exit(COMMAND_LINE_SYNTAX_ERROR) + print convert_debian_to_moz_version(args[0], verbose) + +if __name__ == "__main__": + main() diff --git a/moz_version.py b/moz_version.py new file mode 100644 index 0000000..c4cebed --- /dev/null +++ b/moz_version.py @@ -0,0 +1,212 @@ +# Copyright (c) 2009-2011, Benjamin Drung +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +# Reference: https://developer.mozilla.org/en/Toolkit_version_format + +import sys + +def decode_part(part): + """Decodes a version part (like 5pre4) to + """ + subpart = [0, "", 0, ""] + + # Split + length = 0 + for i in xrange(len(part)): + if part[i].isdigit() or part[i] in ("-"): + length += 1 + else: + break + if length > 0: + subpart[0] = int(part[0:length]) + part = part[length:] + + # Split + length = 0 + for i in xrange(len(part)): + if not (part[i].isdigit() or part[i] in ("-")): + length += 1 + else: + break + subpart[1] = part[0:length] + part = part[length:] + + # Split + length = 0 + for i in xrange(len(part)): + if part[i].isdigit() or part[i] in ("-"): + length += 1 + else: + break + if length > 0: + subpart[2] = int(part[0:length]) + subpart[3] = part[length:] + + # if string-b is a plus sign, number-a is incremented to be compatible with + # the Firefox 1.0.x version format: 1.0+ is the same as 1.1pre + if subpart[1] == "+": + subpart[0] += 1 + subpart[1] = "pre" + + # if the version part is a single asterisk, it is interpreted as an + # infinitely-large number: 1.5.0.* is the same as 1.5.0.(infinity) + if subpart[1] == "*": + subpart[0] = sys.maxint + subpart[1] = "" + + return subpart + +def decode_version(version, verbose=False): + """Decodes a version string like 1.1pre1a""" + parts = version.split(".") + decoded_parts = map(decode_part, parts) + if verbose: + print "I: Split %s up into %s." % (version, decoded_parts) + return decoded_parts + +def compare_subpart((a, b)): + # A string-part that exists is always less-then a nonexisting string-part + if a == "": + if b == "": + return 0 + else: + return 1 + elif b == "": + if a == "": + return 0 + else: + return -1 + else: + return cmp(a, b) + +def compare_part((x, y)): + compared_subparts = filter(lambda x: x != 0, + map(compare_subpart, zip(x, y))) + if compared_subparts: + return compared_subparts[0] + else: + return 0 + +def compare_versions(version1, version2, verbose=False): + a = decode_version(version1, verbose) + b = decode_version(version2, verbose) + + if len(a) < len(b): + a.extend((len(b) - len(a)) * [[0, "", 0, ""]]) + if len(b) < len(a): + b.extend((len(a) - len(b)) * [[0, "", 0, ""]]) + + result = filter(lambda x: x != 0, map(compare_part, zip(a, b))) + if result: + return result[0] + else: + return 0 + +def extract_upstream_version(debian_version): + # remove last part separated by a dash (1.0-2 -> 1.0) + parts = debian_version.split('-') + if len(parts) > 1: + del parts[-1] + upstream_version = '-'.join(parts) + + # remove epoch + parts = upstream_version.split(':') + if len(parts) > 1: + del parts[0] + upstream_version = ':'.join(parts) + + return upstream_version + +def _convert_part_to_debian(part): + """Converts a Mozilla version part (like 5pre4) to a Debian version.""" + (number_a, string_b, number_c, string_d) = part + debian_version = "" + if string_d != "": + debian_version = "~" + string_d + if number_c != 0 or string_d != "": + debian_version = str(number_c) + debian_version + if string_b != "": + debian_version = "~" + string_b + debian_version + debian_version = str(number_a) + debian_version + return debian_version + +def convert_debian_to_moz_version(debian_version, verbose=False): + upstream_version = extract_upstream_version(debian_version) + + # compatibility: strip +nobinonly and +build + parts = upstream_version.split('+') + if len(parts) > 1 and parts[-1] == "nobinonly": + del parts[-1] + if len(parts) > 1 and parts[-1].startswith("build"): + del parts[-1] + upstream_version = '+'.join(parts) + + moz_version = upstream_version.replace("~", "") + return moz_version + +def convert_moz_to_debian_version(moz_version, epoch=0, verbose=False): + parts = decode_version(moz_version, verbose) + # tranform parts + parts = [_convert_part_to_debian(p) for p in parts] + debian_version = ".".join(parts) + if epoch != 0: + debian_version = str(epoch) + ":" + debian_version + return debian_version + +def moz_to_next_debian_version(moz_version, epoch=0, verbose=False): + """Convert a given Mozilla version to the next Debian version. + + Compared to convert_moz_to_debian_version it does following: + * append 0 to a trailing letter, or + * append + to a trailing number, or + * replace a trailing * with +. + + Examples: + 9.0a => 9.0~a0 + 9.0a1 => 9.0~a1+ + 9.0 => 9.0+ + 9.0.* => 9.0.+ + """ + parts = decode_version(moz_version, verbose) + # tranform last parts + (number_a, string_b, number_c, string_d) = parts[-1] + last_part = "" + if string_d != "": + last_part = "~" + string_d + "0" + if number_c != 0 or string_d != "": + if last_part: + last_part = str(number_c) + last_part + else: + if number_c == sys.maxint: + last_part = "+" + else: + last_part = str(number_c) + "+" + if string_b != "": + if last_part: + last_part = "~" + string_b + last_part + else: + last_part = "~" + string_b + "0" + if last_part: + last_part = str(number_a) + last_part + else: + if number_a == sys.maxint: + last_part = "+" + else: + last_part = str(number_a) + "+" + + parts = [_convert_part_to_debian(p) for p in parts[:-1]] + [last_part] + debian_version = ".".join(parts) + if epoch != 0: + debian_version = str(epoch) + ":" + debian_version + return debian_version diff --git a/perl/Debian/Buildsystem/xul_ext.pm b/perl/Debian/Buildsystem/xul_ext.pm new file mode 100644 index 0000000..89c8763 --- /dev/null +++ b/perl/Debian/Buildsystem/xul_ext.pm @@ -0,0 +1,43 @@ +# A debhelper build system class for handling XUL extensions. +# +# Copyright: © 2010 Mike Hommey +# License: GPL-2+ + +package Debian::Debhelper::Buildsystem::xul_ext; + +use strict; +use base 'Debian::Debhelper::Buildsystem'; +use Debian::Debhelper::Dh_Lib; + +sub DESCRIPTION { + "XUL Extensions" +} + +sub check_auto_buildable { + my $this=shift; + return (-e $this->get_sourcepath("install.rdf")) ? 1 : 0; +} + +sub new { + my $class=shift; + my $this=$class->SUPER::new(@_); + $this->enforce_in_source_building(); + return $this; +} + +sub build { + my $this=shift; + $this->doit_in_sourcedir("xpi-pack", ".", $dh{FIRSTPACKAGE} . ".xpi"); +} + +sub install { + my $this=shift; + $this->doit_in_sourcedir("install-xpi", $dh{FIRSTPACKAGE} . ".xpi"); +} + +sub clean { + my $this=shift; + $this->doit_in_sourcedir("rm", "-f", $dh{FIRSTPACKAGE} . ".xpi"); +} + +1 diff --git a/perl/Debian/Sequence/xul_ext.pm b/perl/Debian/Sequence/xul_ext.pm new file mode 100644 index 0000000..515deea --- /dev/null +++ b/perl/Debian/Sequence/xul_ext.pm @@ -0,0 +1,8 @@ +#!/usr/bin/perl +use warnings; +use strict; +use Debian::Debhelper::Dh_Lib; + +insert_after("dh_install", "dh_xul-ext"); + +1; diff --git a/setup.py b/setup.py index ad48412..d5a2cf7 100644 --- a/setup.py +++ b/setup.py @@ -29,15 +29,15 @@ SCRIPTS = [ if __name__ == '__main__': setup(name='mozilla-devscripts', version=get_debian_version(), - scripts=[os.path.join('src', s) for s in SCRIPTS], - py_modules=['src/moz_version'], + scripts=SCRIPTS, + py_modules=['moz_version'], data_files=[('share/doc/mozilla-devscripts', ['README']), ('share/man/man1', glob.glob("man/*.1")), ('share/mozilla-devscripts', - ['src/xpi.mk'] + glob.glob('src/xul-app-data.csv.*')), + ['data/xpi.mk'] + glob.glob('data/xul-app-data.csv.*')), ('share/perl5/Debian/Debhelper/Buildsystem', - ['src/Buildsystem/xul_ext.pm']), + ['perl/Debian/Buildsystem/xul_ext.pm']), ('share/perl5/Debian/Debhelper/Sequence', - ['src/Sequence/xul_ext.pm']), + ['perl/Debian/Sequence/xul_ext.pm']), ], ) diff --git a/src/Buildsystem/xul_ext.pm b/src/Buildsystem/xul_ext.pm deleted file mode 100644 index 89c8763..0000000 --- a/src/Buildsystem/xul_ext.pm +++ /dev/null @@ -1,43 +0,0 @@ -# A debhelper build system class for handling XUL extensions. -# -# Copyright: © 2010 Mike Hommey -# License: GPL-2+ - -package Debian::Debhelper::Buildsystem::xul_ext; - -use strict; -use base 'Debian::Debhelper::Buildsystem'; -use Debian::Debhelper::Dh_Lib; - -sub DESCRIPTION { - "XUL Extensions" -} - -sub check_auto_buildable { - my $this=shift; - return (-e $this->get_sourcepath("install.rdf")) ? 1 : 0; -} - -sub new { - my $class=shift; - my $this=$class->SUPER::new(@_); - $this->enforce_in_source_building(); - return $this; -} - -sub build { - my $this=shift; - $this->doit_in_sourcedir("xpi-pack", ".", $dh{FIRSTPACKAGE} . ".xpi"); -} - -sub install { - my $this=shift; - $this->doit_in_sourcedir("install-xpi", $dh{FIRSTPACKAGE} . ".xpi"); -} - -sub clean { - my $this=shift; - $this->doit_in_sourcedir("rm", "-f", $dh{FIRSTPACKAGE} . ".xpi"); -} - -1 diff --git a/src/Sequence/xul_ext.pm b/src/Sequence/xul_ext.pm deleted file mode 100644 index 515deea..0000000 --- a/src/Sequence/xul_ext.pm +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/perl -use warnings; -use strict; -use Debian::Debhelper::Dh_Lib; - -insert_after("dh_install", "dh_xul-ext"); - -1; diff --git a/src/dh_xul-ext b/src/dh_xul-ext deleted file mode 100755 index c7328de..0000000 --- a/src/dh_xul-ext +++ /dev/null @@ -1,381 +0,0 @@ -#!/usr/bin/python - -# Copyright (c) 2009-2011, Benjamin Drung -# -# Permission to use, copy, modify, and/or distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -import csv -import glob -import optparse -import os -import subprocess -import sys - -from moz_version import (compare_versions, convert_moz_to_debian_version, - moz_to_next_debian_version) - -import RDF - -_VENDOR_ENV = "DH_XUL_EXT_VENDOR" -# error codes -COMMAND_LINE_SYNTAX_ERROR = 1 -MULTIPLE_INSTALL_RDFS = 2 - -class XulApp(object): - def __init__(self, xul_id, package, sol, eol): - self.xul_id = xul_id - self.package = package - self.sol = sol - self.eol = eol - self.min_version = None - self.max_version = None - - def __str__(self): - return self.xul_id + ": " + self.package + " (" + self.sol + " to " + \ - self.eol + ")" - - def get_breaks(self): - """Return a string for ${xpi:Breaks} for the XUL application.""" - breaks = [] - if self.min_version: - deb_min_version = convert_moz_to_debian_version(self.min_version) - breaks.append(self.package + " (<< " + deb_min_version + ")") - if self.max_version: - deb_max_version = moz_to_next_debian_version(self.max_version) - breaks.append(self.package + " (>= " + deb_max_version + ")") - return ", ".join(breaks) - - def get_eol(self): - return self.eol - - def get_id(self): - return self.xul_id - - def get_package(self): - return self.package - - def get_sol(self): - return self.sol - - def get_versioned_package(self): - versioned_package = self.package - if self.min_version: - deb_min_version = convert_moz_to_debian_version(self.min_version) - versioned_package += " (>= " + deb_min_version + ")" - return versioned_package - - def is_same_package(self, xul_app): - return self.xul_id == xul_app.xul_id and self.package == xul_app.package - - def set_max_version(self, max_version): - if compare_versions(self.eol, max_version) > 0: - self.max_version = max_version - - def set_min_version(self, min_version): - if compare_versions(self.sol, min_version) < 0: - self.min_version = min_version - - def update_version(self, sol, eol): - if compare_versions(self.sol, sol) > 0: - self.sol = sol - if compare_versions(self.eol, eol) < 0: - self.eol = eol - - -def _get_data_dir(): - """Get the data directory based on the module location.""" - if __file__.startswith("/usr/bin"): - data_dir = "/usr/share/mozilla-devscripts" - else: - data_dir = os.path.dirname(__file__) - return data_dir - -def get_vendor(): - """This function returns the vendor (e.g. Debian, Ubuntu) that should be - used for calculating the dependencies. DH_XUL_EXT_VENDOR will be used - if set. Otherwise dpkg-vendor will be used for determining the vendor.""" - if _VENDOR_ENV in os.environ: - vendor = os.environ[_VENDOR_ENV] - else: - cmd = ["dpkg-vendor", "--query", "Vendor"] - process = subprocess.Popen(cmd, stdout=subprocess.PIPE) - vendor = process.communicate()[0].strip() - return vendor - -def get_xul_apps(script_name, all_distros): - vendor = get_vendor() - data_dir = _get_data_dir() - if all_distros or vendor == "all": - csv_filenames = sorted(glob.glob(os.path.join(data_dir, - "xul-app-data.csv.*"))) - else: - csv_filename = os.path.join(data_dir, "xul-app-data.csv." + vendor) - if not os.path.isfile(csv_filename): - print >> sys.stderr, ('%s: Unknown vendor "%s" specified.' % - (script_name, vendor)) - sys.exit(1) - csv_filenames = [csv_filename] - - xul_apps = [] - for csv_filename in csv_filenames: - csvfile = open(csv_filename) - csv_reader = csv.DictReader(csvfile) - for row in csv_reader: - xul_app = XulApp(row["id"], row["package"], row["sol"], row["eol"]) - existing = [x for x in xul_apps if x.is_same_package(xul_app)] - if existing: - xul_app = existing[0] - xul_app.update_version(row["sol"], row["eol"]) - else: - xul_apps.append(xul_app) - - return xul_apps - -def _get_id_max_min_triple(install_rdf): - """create array of id_max_min triples""" - id_max_min = [] - model = RDF.Model() - parser = RDF.Parser(name="rdfxml") - parser.parse_into_model(model, "file:" + install_rdf) - query = RDF.Query( - """ - PREFIX em: - SELECT ?id ?max ?min - WHERE { - ?x1 em:targetApplication ?x2 . - ?x2 em:id ?id . - OPTIONAL { - ?x2 em:maxVersion ?max . - ?x2 em:minVersion ?min . - } . - } - """, query_language="sparql") - results = query.execute(model) - # append to id_max_min tripe to array - for target in results: - id_max_min.append ((target["id"].literal_value["string"], - target["max"].literal_value["string"], - target["min"].literal_value["string"])) - return id_max_min - -def get_supported_apps(script_name, xul_apps, install_rdf, package, - verbose=False): - id_max_min = _get_id_max_min_triple(install_rdf) - if verbose: - print "%s: %s supports %i XUL application(s):" % (script_name, package, - len(id_max_min)) - for (appid, max_version, min_version) in id_max_min: - print "%s %s to %s" % (appid, min_version, max_version) - - # find supported apps/packages - supported_apps = list() - for xul_app in xul_apps: - supported_app = [x for x in id_max_min if x[0] == xul_app.get_id()] - if len(supported_app) == 1: - # package is supported by extension - (appid, max_version, min_version) = supported_app.pop() - if compare_versions(xul_app.get_sol(), max_version) <= 0: - if compare_versions(xul_app.get_eol(), min_version) >= 0: - xul_app.set_min_version(min_version) - xul_app.set_max_version(max_version) - supported_apps.append(xul_app) - if verbose: - print "%s: %s supports %s." % (script_name, package, - xul_app.get_package()) - elif verbose: - print "%s: %s does not support %s (any more)." % \ - (script_name, package, xul_app.get_package()) - elif verbose: - print "%s: %s does not support %s (yet)." % \ - (script_name, package, xul_app.get_package()) - elif len(supported_app) > 1: - print ("%s: Found error in %s. There are multiple entries for " - "application ID %s.") % (script_name, install_rdf, - xul_app.get_id()) - - return supported_apps - -def get_all_packages(): - lines = open("debian/control").readlines() - package_lines = [x for x in lines if x.find("Package:") >= 0] - packages = [p[p.find(":")+1:].strip() for p in package_lines] - return packages - -def get_source_package_name(): - source = None - control_file = open("debian/control") - for line in control_file: - if line.startswith("Source:"): - source = line[line.find(":")+1:].strip() - break - return source - -def has_no_xpi_depends(): - lines = open("debian/control").readlines() - xpi_depends_lines = [l for l in lines if l.find("${xpi:Depends}") >= 0] - return len(xpi_depends_lines) == 0 - -def get_provided_package_names(package, supported_apps): - ext_name = package - for prefix in ("firefox-", "iceweasel-", "mozilla-", "xul-ext-"): - if ext_name.startswith(prefix): - ext_name = ext_name[len(prefix):] - - # check if MOZ_XPI_EXT_NAME is defined in debian/rules - lines = open("debian/rules").readlines() - lines = [l for l in lines if l.find("MOZ_XPI_EXT_NAME") != -1] - if len(lines) > 0: - line = lines[-1] - ext_name = line[line.find("=")+1:].strip() - - provides = set() - provides.add("xul-ext-" + ext_name) - if ext_name == get_source_package_name(): - provides.add(ext_name) - - for xul_app in supported_apps: - app = xul_app.get_package() - for i in xrange(len(app) - 1, -1, -1): - if app[i] == '-': - app = app[:i] - elif not app[i].isdigit() and not app[i] == '.': - break - provides.add(app + "-" + ext_name) - - # remove package name from provide list - provides.discard(package) - - return list(provides) - -def find_install_rdfs(path): - install_rdfs = set() - - if os.path.isfile(path) and os.path.basename(path) == "install.rdf": - install_rdfs.add(os.path.realpath(path)) - - if os.path.isdir(path): - # recursive walk - content = [os.path.join(path, d) for d in os.listdir(path)] - install_rdfs = reduce(lambda x, d: x.union(find_install_rdfs(d)), - content, install_rdfs) - - return install_rdfs - -def generate_substvars(script_name, xul_apps, package, verbose=False): - install_rdfs = find_install_rdfs("debian/" + package) - if len(install_rdfs) == 0: - if verbose: - print script_name + ": " + package + \ - " does not contain a XUL extension (no install.rdf found)." - return - elif len(install_rdfs) > 1: - print >> sys.stderr, ("%s: %s contains multiple install.rdf files. " - "That's not supported.") % (script_name, package) - basepath_len = len(os.path.realpath("debian/" + package)) - rdfs = [x[basepath_len:] for x in install_rdfs] - print >> sys.stderr, "\n".join(rdfs) - sys.exit(MULTIPLE_INSTALL_RDFS) - install_rdf = install_rdfs.pop() - - filename = "debian/" + package + ".substvars" - if os.path.exists(filename): - substvars_file = open(filename) - lines = substvars_file.readlines() - substvars_file.close() - else: - lines = list() - - # remove existing varibles - lines = [s for s in lines if not s.startswith("xpi:")] - - supported_apps = get_supported_apps(script_name, xul_apps, install_rdf, - package, verbose) - packages = [a.get_versioned_package() for a in supported_apps] - if has_no_xpi_depends(): - # Use xpi:Recommends instead of xpi:Depends for backwards compatibility - print ("%s: Warning: Please add ${xpi:Depends} to Depends. Using only " - "${xpi:Recommends} is deprecated.") % (script_name) - lines.append("xpi:Recommends=" + " | ".join(packages) + "\n") - else: - lines.append("xpi:Depends=" + " | ".join(packages) + "\n") - lines.append("xpi:Recommends=\n") - packages = [a.get_breaks() for a in supported_apps] - lines.append("xpi:Breaks=" + ", ".join(sorted(packages)) + "\n") - packages = [a.get_package() for a in supported_apps] - lines.append("xpi:Enhances=" + ", ".join(sorted(packages)) + "\n") - packages = get_provided_package_names(package, supported_apps) - lines.append("xpi:Provides=" + ", ".join(sorted(packages)) + "\n") - - # write new variables - substvars_file = open(filename, "w") - substvars_file.writelines(lines) - substvars_file.close() - - -class UnknownOptionIgnoringOptionParser(optparse.OptionParser): - def __init__ (self, **options): - optparse.OptionParser.__init__(self, **options) - self.unknown_options = [] - - 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) - - -def main(): - script_name = os.path.basename(sys.argv[0]) - epilog = "See %s(1) for more info." % (script_name) - parser = UnknownOptionIgnoringOptionParser(epilog=epilog) - parser.add_option("-a", "--all", action="store_true", dest="all", - help="expand substvars to all known XUL applications " - "(not only of your distribution)", default=False) - 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 = parser.parse_args()[0] - - if len(options.packages) == 0: - options.packages = get_all_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(script_name, options.all) - 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 - - for package in options.packages: - generate_substvars(script_name, xul_apps, package, options.verbose) - -if __name__ == "__main__": - main() diff --git a/src/install-xpi b/src/install-xpi deleted file mode 100755 index ddd7b1a..0000000 --- a/src/install-xpi +++ /dev/null @@ -1,258 +0,0 @@ -#!/usr/bin/python - -# Copyright (c) 2009-2011, Benjamin Drung -# -# Permission to use, copy, modify, and/or distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -import csv -import optparse -import os -import stat -import subprocess -import sys -import zipfile - -import RDF - -LICENSE_PATTERN_LIST = ( - "copying", - "gpl.txt", - "licence", - "license", - "licence.txt", - "license.txt" -) - -# error codes -COMMAND_LINE_SYNTAX_ERROR = 1 -XPI_FILE_DOES_NOT_EXISTS = 2 - -def get_query_field_id_as_list(rdf_path, query_string): - ret = [] - model = RDF.Model() - parser = RDF.Parser(name="rdfxml") - parser.parse_into_model(model, "file:" + rdf_path) - query = RDF.Query("PREFIX em: " + \ - query_string, query_language="sparql") - results = query.execute(model) - for result in results: - ret.append(result["id"].literal_value["string"]) - return ret - -def get_target_applications(install_rdf): - target_applications = get_query_field_id_as_list(install_rdf, - "SELECT ?id WHERE { ?x1 em:targetApplication ?x2 . ?x2 em:id ?id }") - return target_applications - -def get_extension_id(install_rdf): - extension_ids = set(get_query_field_id_as_list(install_rdf, - "SELECT ?id WHERE {?x1 em:targetApplication ?x2 . ?x1 em:id ?id }")) - return extension_ids.pop() - -def get_arch(package): - lines = open("debian/control").readlines() - package_lines = filter(lambda x: x.find("Package:") >= 0, lines) - packages = map(lambda x: x[x.find(":")+1:].strip(), package_lines) - architecture_lines = filter(lambda x: x.find("Architecture:") >= 0, lines) - architectures = map(lambda x: x[x.find(":")+1:].strip(), architecture_lines) - (_, arch) = filter(lambda (x, y): x == package, - zip(packages, architectures))[0] - return arch - -def get_mode(filename): - statinfo = os.stat(filename) - mode = statinfo[stat.ST_MODE] - return mode & 0777 - -def get_xul_apps(): - csvfile = open("/usr/share/mozilla-devscripts/xul-app-data.csv") - csv_reader = csv.DictReader(csvfile) - rows = [] - for row in csv_reader: - rows.append(row) - return rows - -def install_xpi(script_name, package, xpi_file, exclude, install_dir, links, - correct_permissions, remove_licenses, system_prefs, 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) - sys.exit(XPI_FILE_DOES_NOT_EXISTS) - zfobj = zipfile.ZipFile(xpi_file) - xpi_content = zfobj.namelist() - - # determine installation directory - if get_arch(package) == "all": - lib_share_dir = "share" - else: - lib_share_dir = "lib" - if install_dir is None: - install_dir = os.path.join("usr", lib_share_dir, "xul-ext", - package.replace("xul-ext-", "")) - copy_dir = os.path.join("debian", package, install_dir.strip("/")) - if verbose: - print "%s: install directory: %s" % (script_name, install_dir) - - # remove documented license files - if remove_licenses: - for name in filter(lambda x: not x.endswith('/'), xpi_content): - basename = os.path.basename(name).lower() - if basename in LICENSE_PATTERN_LIST: - exclude.append(name) - print "%s: exclude license file %s" % (script_name, name) - - # create directory and extract xpi file - if not os.path.isdir(copy_dir): - os.makedirs(copy_dir) - command = ["unzip", "-o", "-d", copy_dir, xpi_file] - if len(exclude) > 0: - command.append("-x") - command.extend(exclude) - print " ".join(command) - subprocess.call(command) - - # correct permissons of files to 644 and directories to 755 - if correct_permissions: - for name in xpi_content: - filename = os.path.join(copy_dir, name) - if os.path.exists(filename): - mode = get_mode(filename) - if os.path.isdir(filename) and mode != 0755: - print "%s: correct permission from %s to %s of %s" % \ - (script_name, oct(mode), oct(0755), name) - os.chmod(filename, 0755) - elif os.path.isfile(filename): - header = open(filename, "r").read(2) - if header != "#!" and mode != 0644: - # file without shebang - print "%s: correct permission from %s to %s of %s" % \ - (script_name, oct(mode), oct(0644), name) - os.chmod(filename, 0644) - elif header == "#!" and mode != 0755: - # file with shebang - print "%s: correct permission from %s to %s of %s" % \ - (script_name, oct(mode), oct(0755), name) - os.chmod(filename, 0755) - - # create a system preference file in /etc - if system_prefs: - # search for preference files - pref_dir = os.path.join("defaults", "preferences") - preferences = filter(lambda f: os.path.dirname(f) == pref_dir and \ - f.endswith(".js"), xpi_content) - if len(preferences) > 0: - prefdir = os.path.join("etc", "xul-ext") - full_prefdir = os.path.join("debian", package, prefdir) - if not os.path.exists(full_prefdir): - os.makedirs(full_prefdir) - prefname = package.replace("xul-ext-", "") + ".js" - # create system preference file - f = open(os.path.join(full_prefdir, prefname), "w") - if os.path.isfile(os.path.join("debian", package + ".js")): - # use debian/package.js as configuration file if it exists - content = open(os.path.join("debian", package + ".js")).read() - # replace @INSTALLDIR@ by the actual installation directory - content = content.replace("@INSTALLDIR@", - os.path.join("/", install_dir)) - f.write(content) - else: - f.write("// Place your preferences for " + package + - " in this file.\n") - f.write("// You can override here the preferences specified " - "in\n") - map(lambda x: f.write("// " + - os.path.join("/", install_dir, x) + - "\n"), preferences) - f.close() - link_source = os.path.join(prefdir, prefname) - link_target = os.path.join(install_dir, "defaults", "preferences", - "000system.js") - command = ["dh_link", "-p" + package, link_source, link_target] - if verbose: - print " ".join(command) - subprocess.call(command) - - # get symlinks list - extension_id = get_extension_id(os.path.join(copy_dir, "install.rdf")) - filename = os.path.join(copy_dir, "install.rdf") - target_applications = get_target_applications(filename) - for target_application in target_applications: - destination = os.path.join("/usr", lib_share_dir, "mozilla/extensions", - target_application, extension_id) - links.add(destination) - - # create symlinks - for link in links: - command = ["dh_link", "-p" + package, install_dir, link] - print " ".join(command) - subprocess.call(command) - -def get_first_package(): - lines = open("debian/control").readlines() - package_lines = filter(lambda x: x.find("Package:") >= 0, lines) - packages = map(lambda x: x[x.find(":")+1:].strip(), package_lines) - return packages[0] - -def main(): - usage = "%s [options] " % (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("--disable-system-prefs", - help="do not create a system preference file in /etc", - dest="system_prefs", action="store_false", default=True) - 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]) - - 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, "%s: Error: Multiple xpi files specified: %s" % \ - (script_name, ", ".join(args)) - sys.exit(COMMAND_LINE_SYNTAX_ERROR) - - if options.verbose: - print script_name + ": Install %s into package %s." % \ - (args[0], options.package) - - install_xpi(script_name, options.package, args[0], options.exclude, - options.install_dir, set(options.links), - options.correct_permissions, options.remove_licenses, - options.system_prefs, options.verbose) - -if __name__ == "__main__": - main() diff --git a/src/moz-version b/src/moz-version deleted file mode 100755 index 6362b31..0000000 --- a/src/moz-version +++ /dev/null @@ -1,154 +0,0 @@ -#!/usr/bin/python - -# Copyright (c) 2009-2011, Benjamin Drung -# -# Permission to use, copy, modify, and/or distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# 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 os -import sys - -from moz_version import (compare_versions, convert_debian_to_moz_version, - convert_moz_to_debian_version) - -# error codes -COMMAND_LINE_SYNTAX_ERROR = 2 -INVALID_COMPARATOR = 3 -EMPTY_VERSION_STRING = 4 - -COMPARATORS = ("lt", "le", "eq", "ne", "ge", "gt") - -def moz_version_compare(version1, comparator, version2, silent=False, - verbose=False): - """Return true if the expression version1 comparator version2 is valid, - otherwise false""" - if comparator not in COMPARATORS: - if not silent: - print >> sys.stderr, "E: The comparator " + comparator + \ - " is not valid. It should one of " + \ - ", ".join(COMPARATORS) + "." - sys.exit(INVALID_COMPARATOR) - - if version1.strip() == "" or version2.strip() == "": - if not silent: - print >> sys.stderr, "E: At least one version string is empty." - sys.exit(EMPTY_VERSION_STRING) - - if verbose: - symbol = {"lt": "<", "le": "<=", "eq": "=", "ne": "!=", - "ge": ">=", "gt": ">"} - print "I: Comparing %s %s %s." % \ - (version1, symbol[comparator], version2) - - if comparator == "lt": - return compare_versions(version1, version2, verbose) < 0 - elif comparator == "le": - return compare_versions(version1, version2, verbose) <= 0 - elif comparator == "eq": - return compare_versions(version1, version2, verbose) == 0 - elif comparator == "ne": - return compare_versions(version1, version2, verbose) != 0 - elif comparator == "ge": - return compare_versions(version1, version2, verbose) >= 0 - elif comparator == "gt": - return compare_versions(version1, version2, verbose) > 0 - - -def usage(output): - name = os.path.basename(sys.argv[0]) - print >> output, """Usage: %s [options] action - -Actions: - -c, --compare version1 comparator version2 - compare both Mozilla version numbers - comparator must be one of %s - -d, --to-deb version converts Mozilla into a Debian upstream version - -m, --to-moz version converts Debian into a Mozilla version - -Options: - -h, --help display this help and exit - -s, --silent do not print anything and die silent on errors - -v, --verbose print more information - -See %s(1) for more info.""" % (name, ", ".join(COMPARATORS), name) - - -def main(): - try: - long_opts = ["compare", "help", "silent", "to-deb", "to-moz", "verbose"] - opts, args = getopt.gnu_getopt(sys.argv[1:], "cdhmsv", long_opts) - except getopt.GetoptError, e: - # print help information and exit: - print >> sys.stderr, str(e) - usage(sys.stderr) - sys.exit(COMMAND_LINE_SYNTAX_ERROR) - - actions = set() - silent = False - verbose = False - - for o, _ in opts: - if o in ("-c", "--compare"): - actions.add("compare") - elif o in ("-d", "--to-deb"): - actions.add("to-deb") - elif o in ("-h", "--help"): - usage(sys.stdout) - sys.exit() - elif o in ("-m", "--to-moz"): - actions.add("to-moz") - elif o in ("-s", "--silent"): - silent = True - elif o in ("-v", "--verbose"): - verbose = True - else: - assert False, "unhandled option" - - if len(actions) != 1: - if not silent: - print >> sys.stderr, "E: You must specify an action." - usage(sys.stderr) - sys.exit(COMMAND_LINE_SYNTAX_ERROR) - - action = actions.pop() - - if action == "compare": - if len(args) != 3: - if not silent: - usage(sys.stderr) - sys.exit(COMMAND_LINE_SYNTAX_ERROR) - if moz_version_compare(args[0], args[1], args[2], silent, verbose): - if verbose: - print "I: Compare expression true." - sys.exit(0) - else: - if verbose: - print "I: Compare expression false." - sys.exit(1) - elif action == "to-deb": - if len(args) != 1: - if not silent: - print >> sys.stderr, "E: The action --to-deb takes exactly " + \ - "one argument." - sys.exit(COMMAND_LINE_SYNTAX_ERROR) - print convert_moz_to_debian_version(args[0], 0, verbose) - elif action == "to-moz": - if len(args) != 1: - if not silent: - print >> sys.stderr, "E: The action --to-moz takes exactly " + \ - "one argument." - sys.exit(COMMAND_LINE_SYNTAX_ERROR) - print convert_debian_to_moz_version(args[0], verbose) - -if __name__ == "__main__": - main() diff --git a/src/moz_version.py b/src/moz_version.py deleted file mode 100644 index c4cebed..0000000 --- a/src/moz_version.py +++ /dev/null @@ -1,212 +0,0 @@ -# Copyright (c) 2009-2011, Benjamin Drung -# -# Permission to use, copy, modify, and/or distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -# Reference: https://developer.mozilla.org/en/Toolkit_version_format - -import sys - -def decode_part(part): - """Decodes a version part (like 5pre4) to - """ - subpart = [0, "", 0, ""] - - # Split - length = 0 - for i in xrange(len(part)): - if part[i].isdigit() or part[i] in ("-"): - length += 1 - else: - break - if length > 0: - subpart[0] = int(part[0:length]) - part = part[length:] - - # Split - length = 0 - for i in xrange(len(part)): - if not (part[i].isdigit() or part[i] in ("-")): - length += 1 - else: - break - subpart[1] = part[0:length] - part = part[length:] - - # Split - length = 0 - for i in xrange(len(part)): - if part[i].isdigit() or part[i] in ("-"): - length += 1 - else: - break - if length > 0: - subpart[2] = int(part[0:length]) - subpart[3] = part[length:] - - # if string-b is a plus sign, number-a is incremented to be compatible with - # the Firefox 1.0.x version format: 1.0+ is the same as 1.1pre - if subpart[1] == "+": - subpart[0] += 1 - subpart[1] = "pre" - - # if the version part is a single asterisk, it is interpreted as an - # infinitely-large number: 1.5.0.* is the same as 1.5.0.(infinity) - if subpart[1] == "*": - subpart[0] = sys.maxint - subpart[1] = "" - - return subpart - -def decode_version(version, verbose=False): - """Decodes a version string like 1.1pre1a""" - parts = version.split(".") - decoded_parts = map(decode_part, parts) - if verbose: - print "I: Split %s up into %s." % (version, decoded_parts) - return decoded_parts - -def compare_subpart((a, b)): - # A string-part that exists is always less-then a nonexisting string-part - if a == "": - if b == "": - return 0 - else: - return 1 - elif b == "": - if a == "": - return 0 - else: - return -1 - else: - return cmp(a, b) - -def compare_part((x, y)): - compared_subparts = filter(lambda x: x != 0, - map(compare_subpart, zip(x, y))) - if compared_subparts: - return compared_subparts[0] - else: - return 0 - -def compare_versions(version1, version2, verbose=False): - a = decode_version(version1, verbose) - b = decode_version(version2, verbose) - - if len(a) < len(b): - a.extend((len(b) - len(a)) * [[0, "", 0, ""]]) - if len(b) < len(a): - b.extend((len(a) - len(b)) * [[0, "", 0, ""]]) - - result = filter(lambda x: x != 0, map(compare_part, zip(a, b))) - if result: - return result[0] - else: - return 0 - -def extract_upstream_version(debian_version): - # remove last part separated by a dash (1.0-2 -> 1.0) - parts = debian_version.split('-') - if len(parts) > 1: - del parts[-1] - upstream_version = '-'.join(parts) - - # remove epoch - parts = upstream_version.split(':') - if len(parts) > 1: - del parts[0] - upstream_version = ':'.join(parts) - - return upstream_version - -def _convert_part_to_debian(part): - """Converts a Mozilla version part (like 5pre4) to a Debian version.""" - (number_a, string_b, number_c, string_d) = part - debian_version = "" - if string_d != "": - debian_version = "~" + string_d - if number_c != 0 or string_d != "": - debian_version = str(number_c) + debian_version - if string_b != "": - debian_version = "~" + string_b + debian_version - debian_version = str(number_a) + debian_version - return debian_version - -def convert_debian_to_moz_version(debian_version, verbose=False): - upstream_version = extract_upstream_version(debian_version) - - # compatibility: strip +nobinonly and +build - parts = upstream_version.split('+') - if len(parts) > 1 and parts[-1] == "nobinonly": - del parts[-1] - if len(parts) > 1 and parts[-1].startswith("build"): - del parts[-1] - upstream_version = '+'.join(parts) - - moz_version = upstream_version.replace("~", "") - return moz_version - -def convert_moz_to_debian_version(moz_version, epoch=0, verbose=False): - parts = decode_version(moz_version, verbose) - # tranform parts - parts = [_convert_part_to_debian(p) for p in parts] - debian_version = ".".join(parts) - if epoch != 0: - debian_version = str(epoch) + ":" + debian_version - return debian_version - -def moz_to_next_debian_version(moz_version, epoch=0, verbose=False): - """Convert a given Mozilla version to the next Debian version. - - Compared to convert_moz_to_debian_version it does following: - * append 0 to a trailing letter, or - * append + to a trailing number, or - * replace a trailing * with +. - - Examples: - 9.0a => 9.0~a0 - 9.0a1 => 9.0~a1+ - 9.0 => 9.0+ - 9.0.* => 9.0.+ - """ - parts = decode_version(moz_version, verbose) - # tranform last parts - (number_a, string_b, number_c, string_d) = parts[-1] - last_part = "" - if string_d != "": - last_part = "~" + string_d + "0" - if number_c != 0 or string_d != "": - if last_part: - last_part = str(number_c) + last_part - else: - if number_c == sys.maxint: - last_part = "+" - else: - last_part = str(number_c) + "+" - if string_b != "": - if last_part: - last_part = "~" + string_b + last_part - else: - last_part = "~" + string_b + "0" - if last_part: - last_part = str(number_a) + last_part - else: - if number_a == sys.maxint: - last_part = "+" - else: - last_part = str(number_a) + "+" - - parts = [_convert_part_to_debian(p) for p in parts[:-1]] + [last_part] - debian_version = ".".join(parts) - if epoch != 0: - debian_version = str(epoch) + ":" + debian_version - return debian_version diff --git a/src/xpi-pack b/src/xpi-pack deleted file mode 100755 index 688839c..0000000 --- a/src/xpi-pack +++ /dev/null @@ -1,89 +0,0 @@ -#!/bin/sh - -# Copyright (c) 2008 Alexander Sack, Sasa Bodiroza -# Description: Script to pack indir to xpifile -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License as -# published by the Free Software Foundation; either version 2, or (at -# your option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -# The script searches indir for unpacked jar files, which must be located in -# ./input_dir/path/to/file.jar!/ dir. It will jar it up to -# ./input_dir/path/to/file.jar, and then remove the contents of unpacked dir. -# After that, it will zip up the contents of indir to xpi file. -# Example: xpi-pack ubufox.out ubufox-ver.xpi - -INDIR=$1; -XPIFILE=$2; - -usage() { - echo "$0 - Script to produce XPI file from input directory." - echo - echo "The output XPI file is placed in top-level of the input directory."; - echo "To place it somewhere else, provide relative or absolute path to the"; - echo "output XPI file." - echo - echo "To run it call:"; - echo "$ $0 input_directory output_xpi_file" - echo - echo " input_directory - directory with the XPI source tree"; - echo " output_xpi_file - name of the produced file"; - exit 1; -} - -if [ "$1" = "--help" -o "$1" = "-h" ] ; then - usage -fi; - -if [ -z $INDIR ] ; then - echo "Missing input directory." - echo - usage; -fi; -if [ -z $XPIFILE ] ; then - echo "Missing XPI name." - echo - usage; -fi; -if [ ! -d $INDIR ] ; then - echo "E: Input directory doesn't exist." - echo - usage; -fi; - -START_DIR=`pwd`; -PACK_JAR_PATHS=""; -cd $INDIR; -for JAR_DIR in `find . -type d -name '*.jar\!'` ; do - JAR_FILE=`echo $JAR_DIR | sed "s/jar\!$/jar/"`; - ABS_JAR_PATH=`cd $JAR_DIR ; pwd`; - ABS_JAR_FILE=`echo $ABS_JAR_PATH | sed "s/jar\!$/jar/"`; - ABS_CUR_DIR=`pwd`; - cd $ABS_JAR_PATH; - echo "Packing $JAR_FILE"; - zip -q -r $ABS_JAR_FILE .; - cd $ABS_CUR_DIR; - PACK_JAR_PATHS="$ABS_JAR_FILE $PACK_JAR_PATHS"; - rm -rf $ABS_JAR_PATH; -done; -echo "Packing $XPIFILE"; -zip -q -r $START_DIR/$XPIFILE * -x debian/\* temp-*/\*; -[ -f $START_DIR/$XPIFILE ] && XPIDIR=`dirname $START_DIR/$XPIFILE` -ABS_XPIDIR=`cd $XPIDIR; pwd`; -echo "Packed XPI file. It is located in $ABS_XPIDIR"; -for JAR_PATH in $PACK_JAR_PATHS ; do - echo "Unpacking and removing $JAR_PATH"; - unzip -q $JAR_PATH -d $JAR_PATH!; - rm -f $JAR_PATH; -done; -cd $START_DIR; diff --git a/src/xpi-repack b/src/xpi-repack deleted file mode 100755 index 8bf5dae..0000000 --- a/src/xpi-repack +++ /dev/null @@ -1,127 +0,0 @@ -#!/usr/bin/python - -# Copyright (c) 2010-2011, Benjamin Drung -# -# Permission to use, copy, modify, and/or distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# 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 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(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] - -Options: - -p, --package= specify source package name - -u, --upstream-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])) - -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__": - main() diff --git a/src/xpi-unpack b/src/xpi-unpack deleted file mode 100755 index aea7d82..0000000 --- a/src/xpi-unpack +++ /dev/null @@ -1,76 +0,0 @@ -#!/bin/sh - -# Copyright (c) 2008 Alexander Sack, Sasa Bodiroza -# Description: Script to unpack xpifile to outdir -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License as -# published by the Free Software Foundation; either version 2, or (at -# your option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -# The script unpacks the xpi file, then searches it for jar files. If it -# finds any it will unzip it to ./outpur_dir/path/to/file.jar!/ dir. -# Example: xpi-unpack ubufox-ver.xpi ubufox.out - -XPIFILE=$1; -OUTDIR=$2; - -usage() { - echo "$0 - Script to unpack XPI file to output directory." - echo - echo "To run it call:"; - echo "$ $0 input_xpi_file output_directory" - echo - echo " input_xpi_file - packed XPI source tree"; - echo " output_directory - location where the unpacke XPI file is placed"; - exit 1; -} - -if [ "$1" = "--help" -o "$1" = "-h" ] ; then - usage; -fi; - -if [ -z $XPIFILE ] ; then - echo "Missing XPI file." - echo - usage -fi; -if [ -z $OUTDIR ] ; then - echo "Missing output directory." - echo - usage -fi; -if [ -d $OUTDIR ] ; then - echo "E: Output directory already exists." - echo - usage -fi; - -if [ ! -f $XPIFILE ] ; then - echo "E: XPI file doesn't exist." - echo - usage -fi; - -mkdir $OUTDIR; -echo "Unpacking $XPIFILE"; - -unzip -q $XPIFILE -d $OUTDIR; -cd $OUTDIR; -for JAR_PATH in `find . -name '*.jar'` ; do - echo "Unpacking $JAR_PATH"; - unzip -q $JAR_PATH -d $JAR_PATH!; - rm -f $JAR_PATH; -done; -cd ..; - -echo "Unpacked xpi file."; diff --git a/src/xpi.mk b/src/xpi.mk deleted file mode 100644 index 77b8720..0000000 --- a/src/xpi.mk +++ /dev/null @@ -1,142 +0,0 @@ -# -*- mode: makefile; coding: utf-8 -*- - -# Copyright (c) 2008-2009 Canonical Ltd. -# Author(s): Alexander Sack -# Fabien Tassin -# Benjamin Drung -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License as -# published by the Free Software Foundation; either version 2, or (at -# your option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - -# -# Usage: include this file in your CDBS debian/rules file and define the -# following variables: -# -# MOZ_EXTENSION_PKG (OPTIONAL): -# if defined the given binary package name is used to ship -# this xpi; otherwise the first binary package listed in -# debian/control is used -# -# MOZ_XPI_FILE (OPTIONAL): -# if defined the given .xpi file is used; otherwise we try to -# guess one using wildcard (*.xpi) -# -# MOZ_XPI_BUILD_COMMAND (OPTIONAL): -# if defined the given command will be run _before_ the extension -# gets packaged up the standard .xpi way. Thus, the build command -# should produce an .xpi in top level directory. Note: If this -# command is specified, MOZ_XPI_CLEAN_COMMAND (see below) will be -# run during |clean|. If the .xpi file will not be build from -# source, you have to set this variable to nothing. -# -# MOZ_XPI_CLEAN_COMMAND (OPTIONAL): -# only has an effect if MOZ_XPI_BUILD_COMMAND (see above) is set. -# It defaults to `rm -f *.xpi`. -# -# MOZ_XPI_MOZILLA_EXTRA_DIRS (OPTIONAL): -# defines extra directories to link the extension in. Usually -# xpi.mk creates the right links based on targetApplication -# parsed in install.rdf; if you need more directories, use this. -# -# MOZ_XPI_DOCUMENTED_LICENSE_FILES (OPTIONAL): -# defines extra license files which need to be excluded during -# the installation of the XPI file to the packaging tree. When -# using parameter, be sure that you documented _all_ excluded -# license files in debian/copyright appropriately. If not defined -# the common license file names are guessed. -# -# MOZ_XPI_EXT_NAME (OPTIONAL): -# defines the name of the extension (without any prefixes like -# mozilla- or xul-ext-). If not defined MOZ_EXTENSION_PKG with -# stripped prefixes is used. This value is used to determine -# xpi:Provides. -# -# MOZ_XPI_PRESERVE_PERMISSIONS (OPTIONAL): -# if defined (set to 1), the permission of the installed files -# will not be changed. If not defined or set to $(null), the -# permission of the files will be set to 644 and the permissions -# of scripts (files containing a shebang) will be set to 755. -# -# MOZ_XPI_INSTALL_DIRECTORY (OPTIONAL): -# The xpi file will be installed in the specified directory. -# This directory must be an absolute path. Use this parameter -# with care. -# -# MOZ_XPI_DISABLE_SYSTEM_PREFS (OPTIONAL): -# if defined (set to 1), no system preference file will be -# created in /etc. -# -# Unused variables (can be removed): -# -# MOZ_XPI_EMID (OPTIONAL): -# if defined the given id is used to determine the link name -# in the Firefox extensions directory. if not defined we try -# our best to extract the em:id from the install.rdf file shipped -# by any xpi -# '''Note''': this variable is not used any more - -MOZ_EXTENSION_PKG ?= $(strip $(shell grep ^Package: debian/control | head -n 1 | sed "s/^Package://")) - -MOZ_XPI_BUILD_COMMAND ?= xpi-pack $(CURDIR) $(MOZ_EXTENSION_PKG).xpi -MOZ_XPI_CLEAN_COMMAND ?= rm -f *.xpi - -ifneq (,$(MOZ_XPI_FILE)) -xpi_file = $(wildcard $(MOZ_XPI_FILE)) -else -xpi_file = $(wildcard *.xpi) -endif - -ifneq (,$(MOZ_XPI_PRESERVE_PERMISSIONS)) -install_xpi_extra_parameter += --preserve-permissions -endif - -ifneq (,$(MOZ_XPI_DISABLE_SYSTEM_PREFS)) -install_xpi_extra_parameter += --disable-system-prefs -endif - -ifneq (,$(MOZ_XPI_INSTALL_DIRECTORY)) -install_xpi_extra_parameter += -i $(MOZ_XPI_INSTALL_DIRECTORY) -endif - -ifeq ($(origin MOZ_XPI_DOCUMENTED_LICENSE_FILES),undefined) -install_xpi_extra_parameter += --remove-license-files -else -install_xpi_extra_parameter += $(foreach exclude,$(MOZ_XPI_DOCUMENTED_LICENSE_FILES),-x $(exclude)) -endif - -install_xpi_extra_parameter += $(foreach dir,$(MOZ_XPI_MOZILLA_EXTRA_DIRS),-l $(dir)) - -# ### cdbs hooks -# build xpi using MOZ_XPI_BUILD_COMMAND if defined -build/$(MOZ_EXTENSION_PKG):: -ifneq (,$(MOZ_XPI_BUILD_COMMAND)) - $(MOZ_XPI_BUILD_COMMAND) -endif - -install/$(MOZ_EXTENSION_PKG):: xpi-install - -xpi-install: - install-xpi -p$(MOZ_EXTENSION_PKG) $(xpi_file) $(install_xpi_extra_parameter) - dh_xul-ext -p$(MOZ_EXTENSION_PKG) - -# clean build and remove all .xpi in top-level if a MOZ_XPI_BUILD_COMMAND is defined -ifneq (,$(MOZ_XPI_BUILD_COMMAND)) -clean:: - dh_testdir - dh_clean - $(MOZ_XPI_CLEAN_COMMAND) -endif - -.PHONY: clean xpi-install diff --git a/src/xul-app-data.csv.Debian b/src/xul-app-data.csv.Debian deleted file mode 100644 index eb98c84..0000000 --- a/src/xul-app-data.csv.Debian +++ /dev/null @@ -1,5 +0,0 @@ -id,package,sol,eol -{ec8030f7-c20a-464f-9b0e-13a3a9e97384},iceweasel,2.0,* -{3550f703-e582-4d05-9a08-453d09bdfdc6},icedove,1.5.0.7,* -{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a},iceape,1.0.6,* -{a79fe89b-6662-4ff4-8e88-09950ad4dfde},conkeror,0.9,* diff --git a/src/xul-app-data.csv.Ubuntu b/src/xul-app-data.csv.Ubuntu deleted file mode 100644 index 031c5e0..0000000 --- a/src/xul-app-data.csv.Ubuntu +++ /dev/null @@ -1,4 +0,0 @@ -id,package,sol,eol -{ec8030f7-c20a-464f-9b0e-13a3a9e97384},firefox,3.6a1pre,* -{3550f703-e582-4d05-9a08-453d09bdfdc6},thunderbird,2.0,* -{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a},seamonkey,1.1.6,* diff --git a/tests/dh_xul-ext/all/debian/rules b/tests/dh_xul-ext/all/debian/rules index d69fe4a..78409f7 100755 --- a/tests/dh_xul-ext/all/debian/rules +++ b/tests/dh_xul-ext/all/debian/rules @@ -5,4 +5,4 @@ override_dh_install: dh_install install.rdf /usr/share/xul-ext/test-package/ - ../../../src/dh_xul-ext -a + ../../../dh_xul-ext -a diff --git a/tests/dh_xul-ext/all_environment/debian/rules b/tests/dh_xul-ext/all_environment/debian/rules index e1630ab..738481a 100755 --- a/tests/dh_xul-ext/all_environment/debian/rules +++ b/tests/dh_xul-ext/all_environment/debian/rules @@ -5,4 +5,4 @@ override_dh_install: dh_install install.rdf /usr/share/xul-ext/test-package/ - DH_XUL_EXT_VENDOR=all ../../../src/dh_xul-ext + DH_XUL_EXT_VENDOR=all ../../../dh_xul-ext diff --git a/tests/dh_xul-ext/debian/debian/rules b/tests/dh_xul-ext/debian/debian/rules index 2872153..26712f4 100755 --- a/tests/dh_xul-ext/debian/debian/rules +++ b/tests/dh_xul-ext/debian/debian/rules @@ -5,4 +5,4 @@ override_dh_install: dh_install install.rdf /usr/share/xul-ext/test-package/ - DEB_VENDOR=Debian ../../../src/dh_xul-ext + DEB_VENDOR=Debian ../../../dh_xul-ext diff --git a/tests/dh_xul-ext/ubuntu/debian/rules b/tests/dh_xul-ext/ubuntu/debian/rules index 8893f54..692843b 100755 --- a/tests/dh_xul-ext/ubuntu/debian/rules +++ b/tests/dh_xul-ext/ubuntu/debian/rules @@ -5,4 +5,4 @@ override_dh_install: dh_install install.rdf /usr/share/xul-ext/test-package/ - DH_XUL_EXT_VENDOR=Ubuntu ../../../src/dh_xul-ext + DH_XUL_EXT_VENDOR=Ubuntu ../../../dh_xul-ext diff --git a/tests/test-moz-version b/tests/test-moz-version index 3b787dc..fc47ab6 100755 --- a/tests/test-moz-version +++ b/tests/test-moz-version @@ -24,7 +24,7 @@ import getopt import os import sys -sys.path.insert(1, os.path.abspath(os.path.dirname(sys.argv[0]) + "/../src")) +sys.path.insert(1, os.path.abspath(os.path.dirname(sys.argv[0]) + "/..")) from moz_version import compare_versions # error codes diff --git a/xpi-pack b/xpi-pack new file mode 100755 index 0000000..688839c --- /dev/null +++ b/xpi-pack @@ -0,0 +1,89 @@ +#!/bin/sh + +# Copyright (c) 2008 Alexander Sack, Sasa Bodiroza +# Description: Script to pack indir to xpifile +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# The script searches indir for unpacked jar files, which must be located in +# ./input_dir/path/to/file.jar!/ dir. It will jar it up to +# ./input_dir/path/to/file.jar, and then remove the contents of unpacked dir. +# After that, it will zip up the contents of indir to xpi file. +# Example: xpi-pack ubufox.out ubufox-ver.xpi + +INDIR=$1; +XPIFILE=$2; + +usage() { + echo "$0 - Script to produce XPI file from input directory." + echo + echo "The output XPI file is placed in top-level of the input directory."; + echo "To place it somewhere else, provide relative or absolute path to the"; + echo "output XPI file." + echo + echo "To run it call:"; + echo "$ $0 input_directory output_xpi_file" + echo + echo " input_directory - directory with the XPI source tree"; + echo " output_xpi_file - name of the produced file"; + exit 1; +} + +if [ "$1" = "--help" -o "$1" = "-h" ] ; then + usage +fi; + +if [ -z $INDIR ] ; then + echo "Missing input directory." + echo + usage; +fi; +if [ -z $XPIFILE ] ; then + echo "Missing XPI name." + echo + usage; +fi; +if [ ! -d $INDIR ] ; then + echo "E: Input directory doesn't exist." + echo + usage; +fi; + +START_DIR=`pwd`; +PACK_JAR_PATHS=""; +cd $INDIR; +for JAR_DIR in `find . -type d -name '*.jar\!'` ; do + JAR_FILE=`echo $JAR_DIR | sed "s/jar\!$/jar/"`; + ABS_JAR_PATH=`cd $JAR_DIR ; pwd`; + ABS_JAR_FILE=`echo $ABS_JAR_PATH | sed "s/jar\!$/jar/"`; + ABS_CUR_DIR=`pwd`; + cd $ABS_JAR_PATH; + echo "Packing $JAR_FILE"; + zip -q -r $ABS_JAR_FILE .; + cd $ABS_CUR_DIR; + PACK_JAR_PATHS="$ABS_JAR_FILE $PACK_JAR_PATHS"; + rm -rf $ABS_JAR_PATH; +done; +echo "Packing $XPIFILE"; +zip -q -r $START_DIR/$XPIFILE * -x debian/\* temp-*/\*; +[ -f $START_DIR/$XPIFILE ] && XPIDIR=`dirname $START_DIR/$XPIFILE` +ABS_XPIDIR=`cd $XPIDIR; pwd`; +echo "Packed XPI file. It is located in $ABS_XPIDIR"; +for JAR_PATH in $PACK_JAR_PATHS ; do + echo "Unpacking and removing $JAR_PATH"; + unzip -q $JAR_PATH -d $JAR_PATH!; + rm -f $JAR_PATH; +done; +cd $START_DIR; diff --git a/xpi-repack b/xpi-repack new file mode 100755 index 0000000..8bf5dae --- /dev/null +++ b/xpi-repack @@ -0,0 +1,127 @@ +#!/usr/bin/python + +# Copyright (c) 2010-2011, Benjamin Drung +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# 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 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(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] + +Options: + -p, --package= specify source package name + -u, --upstream-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])) + +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__": + main() diff --git a/xpi-unpack b/xpi-unpack new file mode 100755 index 0000000..aea7d82 --- /dev/null +++ b/xpi-unpack @@ -0,0 +1,76 @@ +#!/bin/sh + +# Copyright (c) 2008 Alexander Sack, Sasa Bodiroza +# Description: Script to unpack xpifile to outdir +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# The script unpacks the xpi file, then searches it for jar files. If it +# finds any it will unzip it to ./outpur_dir/path/to/file.jar!/ dir. +# Example: xpi-unpack ubufox-ver.xpi ubufox.out + +XPIFILE=$1; +OUTDIR=$2; + +usage() { + echo "$0 - Script to unpack XPI file to output directory." + echo + echo "To run it call:"; + echo "$ $0 input_xpi_file output_directory" + echo + echo " input_xpi_file - packed XPI source tree"; + echo " output_directory - location where the unpacke XPI file is placed"; + exit 1; +} + +if [ "$1" = "--help" -o "$1" = "-h" ] ; then + usage; +fi; + +if [ -z $XPIFILE ] ; then + echo "Missing XPI file." + echo + usage +fi; +if [ -z $OUTDIR ] ; then + echo "Missing output directory." + echo + usage +fi; +if [ -d $OUTDIR ] ; then + echo "E: Output directory already exists." + echo + usage +fi; + +if [ ! -f $XPIFILE ] ; then + echo "E: XPI file doesn't exist." + echo + usage +fi; + +mkdir $OUTDIR; +echo "Unpacking $XPIFILE"; + +unzip -q $XPIFILE -d $OUTDIR; +cd $OUTDIR; +for JAR_PATH in `find . -name '*.jar'` ; do + echo "Unpacking $JAR_PATH"; + unzip -q $JAR_PATH -d $JAR_PATH!; + rm -f $JAR_PATH; +done; +cd ..; + +echo "Unpacked xpi file."; -- cgit v1.2.3