summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBenjamin Drung <bdrung@ubuntu.com>2011-07-09 12:01:34 +0200
committerBenjamin Drung <bdrung@ubuntu.com>2011-07-09 12:01:34 +0200
commitdf58f3a3d891a494232d6e49a5a1862a557e8930 (patch)
treef3b2f5e9c1dce38d1fcc476030559b95657ea65d /src
parent352439516b288bb80a0c712e991cc440980f7e7c (diff)
Convert tabs to spaces in Python scripts and make pylint happier.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/dh_xul-ext18
-rwxr-xr-xsrc/install-xpi398
-rwxr-xr-xsrc/moz-version209
-rw-r--r--src/moz_version.py242
-rwxr-xr-xsrc/xpi-repack167
5 files changed, 542 insertions, 492 deletions
diff --git a/src/dh_xul-ext b/src/dh_xul-ext
index 832ba9b..8413b3f 100755
--- a/src/dh_xul-ext
+++ b/src/dh_xul-ext
@@ -15,10 +15,8 @@
# 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
@@ -27,7 +25,7 @@ import RDF
# error codes
COMMAND_LINE_SYNTAX_ERROR = 1
-MULTIPLE_INSTALL_RDFs = 2
+MULTIPLE_INSTALL_RDFS = 2
class XulApp(object):
def __init__(self, xul_id, package, sol, eol):
@@ -85,7 +83,7 @@ def get_supported_apps(script_name, xul_apps, install_rdf, package,
id_max_min = []
model = RDF.Model()
parser = RDF.Parser(name="rdfxml")
- stream = parser.parse_into_model(model, "file:" + install_rdf)
+ parser.parse_into_model(model, "file:" + install_rdf)
query = RDF.Query(
"""
PREFIX em: <http://www.mozilla.org/2004/em-rdf#>
@@ -170,7 +168,8 @@ def get_provided_package_names(package, supported_apps):
lines = open("debian/rules").readlines()
lines = filter(lambda x: x.find("MOZ_XPI_EXT_NAME") != -1, lines)
if len(lines) > 0:
- ext_name = lines[-1][line.find("=")+1:].strip()
+ line = lines[-1]
+ ext_name = line[line.find("=")+1:].strip()
provides = set()
provides.add("xul-ext-" + ext_name)
@@ -216,7 +215,7 @@ def generate_substvars(script_name, xul_apps, package, verbose=False):
basepath_len = len(os.path.realpath("debian/" + package))
rdfs = map(lambda x: x[basepath_len:], install_rdfs)
print >> sys.stderr, "\n".join(rdfs)
- sys.exit(MULTIPLE_INSTALL_RDFs)
+ sys.exit(MULTIPLE_INSTALL_RDFS)
install_rdf = install_rdfs.pop()
filename = "debian/" + package + ".substvars"
@@ -274,7 +273,7 @@ class UnknownOptionIgnoringOptionParser(optparse.OptionParser):
optparse.OptionParser._process_short_opts(self, rargs, values)
-if __name__ == "__main__":
+def main():
script_name = os.path.basename(sys.argv[0])
epilog = "See %s(1) for more info." % (script_name)
parser = UnknownOptionIgnoringOptionParser(epilog=epilog)
@@ -284,7 +283,7 @@ if __name__ == "__main__":
parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
default=False, help="print more information")
- (options, args) = parser.parse_args()
+ options = parser.parse_args()[0]
if len(options.packages) == 0:
options.packages = get_all_packages()
@@ -303,3 +302,6 @@ if __name__ == "__main__":
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
index 0e547eb..0c7b6f7 100755
--- a/src/install-xpi
+++ b/src/install-xpi
@@ -30,207 +30,235 @@ 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")
- stream = parser.parse_into_model(model, "file:" + rdf_path)
- query = RDF.Query("PREFIX em: <http://www.mozilla.org/2004/em-rdf#> " + 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(script_name, install_rdf, verbose=False):
- target_applications = get_query_field_id_as_list(install_rdf,
- "SELECT ?id WHERE { ?x1 em:targetApplication ?x2 . ?x2 em:id ?id }")
- return target_applications
+ ret = []
+ model = RDF.Model()
+ parser = RDF.Parser(name="rdfxml")
+ parser.parse_into_model(model, "file:" + rdf_path)
+ query = RDF.Query("PREFIX em: <http://www.mozilla.org/2004/em-rdf#> " + \
+ 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()
+ 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)
- (p, arch) = filter(lambda (x, y): x == package, zip(packages, architectures))[0]
- return arch
+ 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):
- st = os.stat(filename)
- mode = st[stat.ST_MODE]
- return mode & 0777
+ 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
+ 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:
- pattern_list = ("copying", "gpl.txt", "licence", "license", "licence.txt", "license.txt")
- for name in filter(lambda x: not x.endswith('/'), xpi_content):
- basename = os.path.basename(name).lower()
- if basename in 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
- preferences = filter(lambda f: os.path.dirname(f) == os.path.join("defaults", "preferences") 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"))
- target_applications = get_target_applications(script_name, os.path.join(copy_dir, "install.rdf"))
- 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)
+ 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]
+ 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] <xpi-file>" % (os.path.basename(sys.argv[0]))
+ epilog = "See %s(1) for more info." % (os.path.basename(sys.argv[0]))
+ parser = optparse.OptionParser(usage=usage, epilog=epilog)
+
+ parser.add_option("--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__":
- usage = "%s [options] <xpi-file>" % (os.path.basename(sys.argv[0]))
- epilog = "See %s(1) for more info." % (os.path.basename(sys.argv[0]))
- parser = optparse.OptionParser(usage=usage, epilog=epilog)
-
- parser.add_option("--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, script_name + ": Error: Multiple xpi files specified: " + ", ".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)
+ main()
diff --git a/src/moz-version b/src/moz-version
index cea49b7..85ec81a 100755
--- a/src/moz-version
+++ b/src/moz-version
@@ -24,49 +24,55 @@ import getopt
import os
import sys
-from moz_version import compare_versions, convert_debian_to_moz_version, convert_moz_to_debian_version
+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
+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
+ name = os.path.basename(sys.argv[0])
+ print >> output, """Usage: %s [options] action
Actions:
-c, --compare version1 comparator version2
@@ -80,70 +86,75 @@ Options:
-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)
-
+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__":
- 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) # will print something like "option -a not recognized"
- usage(sys.stderr)
- sys.exit(COMMAND_LINE_SYNTAX_ERROR)
-
- actions = set()
- silent = False
- verbose = False
-
- for o, a 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)
+ main()
diff --git a/src/moz_version.py b/src/moz_version.py
index 24c4680..b65f678 100644
--- a/src/moz_version.py
+++ b/src/moz_version.py
@@ -23,143 +23,145 @@
import sys
def decode_part(part):
- """Decodes a version part (like 5pre4) to <number-a><string-b><number-c><string-d>"""
- subpart = [0,"",0,""]
-
- # Split <number-a>
- 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 <string-b>
- 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 <number-c>
- 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
+ """Decodes a version part (like 5pre4) to
+ <number-a><string-b><number-c><string-d>"""
+ subpart = [0, "", 0, ""]
+
+ # Split <number-a>
+ 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 <string-b>
+ 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 <number-c>
+ 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
+ """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)
+ # 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
+ 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)
+ 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,""]])
+ 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
+ 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 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)
+ # remove epoch
+ parts = upstream_version.split(':')
+ if len(parts) > 1:
+ del parts[0]
+ upstream_version = ':'.join(parts)
- return upstream_version
+ return upstream_version
def convert_debian_to_moz_version(debian_version, verbose=False):
- upstream_version = extract_upstream_version(debian_version)
+ 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)
+ # 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
+ 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
- for i in xrange(len(parts)):
- (number_a, string_b, number_c, string_d) = parts[i]
- part = ""
- if string_d != "":
- part = "~" + string_d
- if number_c != 0 or string_d != "":
- part = str(number_c) + part
- if string_b != "":
- part = "~" + string_b + part
- parts[i] = str(number_a) + part
- debian_version = ".".join(parts)
- if epoch != 0:
- debian_version = str(epoch) + ":" + debian_version
- return debian_version
+ parts = decode_version(moz_version, verbose)
+ # tranform parts
+ for i in xrange(len(parts)):
+ (number_a, string_b, number_c, string_d) = parts[i]
+ part = ""
+ if string_d != "":
+ part = "~" + string_d
+ if number_c != 0 or string_d != "":
+ part = str(number_c) + part
+ if string_b != "":
+ part = "~" + string_b + part
+ parts[i] = str(number_a) + part
+ debian_version = ".".join(parts)
+ if epoch != 0:
+ debian_version = str(epoch) + ":" + debian_version
+ return debian_version
diff --git a/src/xpi-repack b/src/xpi-repack
index fa8429b..0852dfc 100755
--- a/src/xpi-repack
+++ b/src/xpi-repack
@@ -29,50 +29,52 @@ import sys
COMMAND_LINE_SYNTAX_ERROR = 1
def remove_recursive(path):
- """equivalent to rm -rf path"""
- if os.path.exists(path):
- for i in os.listdir(path):
- full_path = os.path.join(path, i)
- if os.path.isdir(full_path):
- remove_recursive(full_path)
- else:
- os.remove(full_path)
- os.rmdir(path)
-
-def repack_xpi(script_name, package, upstream_version, xpi_file, verbose):
- # extract xpi file
- tmp_dir = "/tmp"
- extract_dir = package + "-" + upstream_version
- full_extract_dir = os.path.join(tmp_dir, extract_dir)
- remove_recursive(full_extract_dir)
- subprocess.check_call(["xpi-unpack", xpi_file, full_extract_dir])
-
- # check, if source 3.0 (quilt) format is used
- extension = ".gz"
- if os.path.isfile("debian/source/format"):
- source_format = open("debian/source/format").readline().strip()
- if source_format == "3.0 (quilt)":
- extension = ".bz2"
-
- # pack source
- tar_file = package + "_" + upstream_version + ".orig.tar"
- full_tar_file = os.path.realpath(os.path.join(os.path.dirname(xpi_file), tar_file))
- cmd = ["tar", "-ca", "-C", tmp_dir, "-f", full_tar_file + extension, extract_dir]
- if verbose:
- print " ".join(cmd)
- subprocess.check_call(cmd)
-
- # remove temporary directory
- remove_recursive(full_extract_dir)
+ """equivalent to rm -rf path"""
+ if os.path.exists(path):
+ for i in os.listdir(path):
+ full_path = os.path.join(path, i)
+ if os.path.isdir(full_path):
+ remove_recursive(full_path)
+ else:
+ os.remove(full_path)
+ os.rmdir(path)
+
+def repack_xpi(package, upstream_version, xpi_file, verbose):
+ # extract xpi file
+ tmp_dir = "/tmp"
+ extract_dir = package + "-" + upstream_version
+ full_extract_dir = os.path.join(tmp_dir, extract_dir)
+ remove_recursive(full_extract_dir)
+ subprocess.check_call(["xpi-unpack", xpi_file, full_extract_dir])
+
+ # check, if source 3.0 (quilt) format is used
+ extension = ".gz"
+ if os.path.isfile("debian/source/format"):
+ source_format = open("debian/source/format").readline().strip()
+ if source_format == "3.0 (quilt)":
+ extension = ".bz2"
+
+ # pack source
+ tar_file = package + "_" + upstream_version + ".orig.tar"
+ full_tar_file = os.path.realpath(os.path.join(os.path.dirname(xpi_file),
+ tar_file))
+ cmd = ["tar", "-ca", "-C", tmp_dir, "-f", full_tar_file + extension,
+ extract_dir]
+ if verbose:
+ print " ".join(cmd)
+ subprocess.check_call(cmd)
+
+ # remove temporary directory
+ remove_recursive(full_extract_dir)
def get_source_package_name():
- lines = open("debian/control").readlines()
- package_lines = filter(lambda x: x.find("Source:") >= 0, lines)
- packages = map(lambda x: x[x.find(":")+1:].strip(), package_lines)
- return packages[0]
+ lines = open("debian/control").readlines()
+ package_lines = filter(lambda x: x.find("Source:") >= 0, lines)
+ packages = map(lambda x: x[x.find(":")+1:].strip(), package_lines)
+ return packages[0]
def usage(output):
- print >> output, """Usage: %s [options] <xpi-file>
+ print >> output, """Usage: %s [options] <xpi-file>
Options:
-p, --package=<value> specify source package name
@@ -82,45 +84,50 @@ General options:
-h, --help display this help and exit
-v, --verbose print more information
-See %s(1) for more info.""" % (os.path.basename(sys.argv[0]), os.path.basename(sys.argv[0]))
+See %s(1) for more info.""" % (os.path.basename(sys.argv[0]),
+ os.path.basename(sys.argv[0]))
+
+def main():
+ try:
+ long_opts = ["help", "package=", "upstream-version=", "verbose"]
+ opts, args = getopt.gnu_getopt(sys.argv[1:], "hp:u:v", long_opts)
+ except getopt.GetoptError, e:
+ # will print something like "option -a not recognized"
+ print >> sys.stderr, str(e)
+ usage(sys.stderr)
+ sys.exit(COMMAND_LINE_SYNTAX_ERROR)
+
+ package = None
+ upstream_version = None
+ verbose = False
+
+ for o, a in opts:
+ if o in ("-h", "--help"):
+ usage(sys.stdout)
+ sys.exit()
+ elif o in ("-u", "--upstream-version"):
+ upstream_version = a
+ elif o in ("-p", "--package"):
+ package = a
+ elif o in ("-v", "--verbose"):
+ verbose = True
+ else:
+ assert False, "unhandled option"
+
+ if package is None:
+ package = get_source_package_name()
+
+ script_name = os.path.basename(sys.argv[0])
+
+ if len(args) == 0:
+ print >> sys.stderr, "%s: Error: No xpi file specified." % (script_name)
+ sys.exit(COMMAND_LINE_SYNTAX_ERROR)
+ elif len(args) > 1:
+ print >> sys.stderr, script_name + ": Error: Multiple xpi files " + \
+ "specified: " + ", ".join(args)
+ sys.exit(COMMAND_LINE_SYNTAX_ERROR)
+
+ repack_xpi(package, upstream_version, args[0], verbose)
if __name__ == "__main__":
- try:
- long_opts = ["help", "package=", "upstream-version=", "verbose"]
- opts, args = getopt.gnu_getopt(sys.argv[1:], "hp:u:v", long_opts)
- except getopt.GetoptError, e:
- # will print something like "option -a not recognized"
- print >> sys.stderr, str(e)
- usage(sys.stderr)
- sys.exit(COMMAND_LINE_SYNTAX_ERROR)
-
- package = None
- upstream_version = None
- verbose = False
-
- for o, a in opts:
- if o in ("-h", "--help"):
- usage(sys.stdout)
- sys.exit()
- elif o in ("-u", "--upstream-version"):
- upstream_version = a
- elif o in ("-p", "--package"):
- package = a
- elif o in ("-v", "--verbose"):
- verbose = True
- else:
- assert False, "unhandled option"
-
- if package is None:
- package = get_source_package_name()
-
- script_name = os.path.basename(sys.argv[0])
-
- if len(args) == 0:
- print >> sys.stderr, "%s: Error: No xpi file specified." % (script_name)
- sys.exit(COMMAND_LINE_SYNTAX_ERROR)
- elif len(args) > 1:
- print >> sys.stderr, script_name + ": Error: Multiple xpi files specified: " + ", ".join(args)
- sys.exit(COMMAND_LINE_SYNTAX_ERROR)
-
- repack_xpi(script_name, package, upstream_version, args[0], verbose)
+ main()