diff options
author | Benjamin Drung <bdrung@debian.org> | 2014-05-09 23:21:30 +0200 |
---|---|---|
committer | Benjamin Drung <bdrung@debian.org> | 2014-05-09 23:21:30 +0200 |
commit | c63a7398cb92e934318041069c17f46f92b59e24 (patch) | |
tree | 542a3d75307acdd632e073ec375e9ae12c67513a | |
parent | 0860cda260e942830caafc4bb506acb85f40f311 (diff) |
PEP8 fixes.
pep8 --max-line-length=99 amo-changelog dh_xul-ext install-xpi \
moz_version.py moz-version setup.py xpi-repack
-rwxr-xr-x | amo-changelog | 6 | ||||
-rwxr-xr-x | dh_xul-ext | 39 | ||||
-rwxr-xr-x | install-xpi | 74 | ||||
-rwxr-xr-x | moz-version | 1 | ||||
-rw-r--r-- | moz_version.py | 10 | ||||
-rw-r--r-- | setup.py | 26 |
6 files changed, 97 insertions, 59 deletions
diff --git a/amo-changelog b/amo-changelog index 02b035b..6a20467 100755 --- a/amo-changelog +++ b/amo-changelog @@ -24,18 +24,20 @@ import sys URL_TEMPLATE = "https://addons.mozilla.org/en-US/addon/{ext}/versions/format:rss" + def main(): ap = argparse.ArgumentParser( description="fetch Version History of an addon from the Mozilla Extensions website.") ap.add_argument("extension", - help="Extension short-name, as used on addons.mozilla.org.") + help="Extension short-name, as used on addons.mozilla.org.") options = ap.parse_args() url = URL_TEMPLATE.format(ext=options.extension) try: fp = urllib2.urlopen(url) except urllib2.HTTPError as e: - print("For extension '%s', error fetching '%s': %s" % (options.extension, url, e), file=sys.stderr) + print("For extension '%s', error fetching '%s': %s" % (options.extension, url, e), + file=sys.stderr) return 1 try: for event, element in etree.iterparse(fp): @@ -35,6 +35,7 @@ INVALID_VERSION_RANGE = 3 FIREFOX_ID = "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}" THUNDERBIRD_ID = "{3550f703-e582-4d05-9a08-453d09bdfdc6}" + class XulApp(object): def __init__(self, xul_id, package, sol, eol): self.xul_id = xul_id @@ -45,8 +46,8 @@ class XulApp(object): self.max_version = None def __str__(self): - return self.xul_id + ": " + self.package + " (" + self.sol + " to " + \ - self.eol + ")" + return(self.xul_id + ": " + self.package + " (" + self.sol + " to " + + self.eol + ")") def defaults_to_compatible(self): """Returns true if the maximum and all later versions of the XUL @@ -57,8 +58,8 @@ class XulApp(object): Firefox/Iceweasel 10 and Thunderbird/Icedove 10 defaults add-ons to compatible.""" - if self.xul_id in (FIREFOX_ID, THUNDERBIRD_ID) and \ - compare_versions(self.max_version, "10") >= 0: + if (self.xul_id in (FIREFOX_ID, THUNDERBIRD_ID) and + compare_versions(self.max_version, "10") >= 0): return True return False @@ -118,6 +119,7 @@ def _get_data_dir(): 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 @@ -126,13 +128,14 @@ def get_vendor(): vendor = os.environ[_VENDOR_ENV] else: cmd = ["dpkg-vendor", "--derives-from", "Ubuntu"] - retval = subprocess.call(cmd); + retval = subprocess.call(cmd) if retval == 0: vendor = "Ubuntu" else: vendor = "Debian" return vendor + def get_xul_apps(script_name, all_distros): vendor = get_vendor() data_dir = _get_data_dir() @@ -162,6 +165,7 @@ def get_xul_apps(script_name, all_distros): return xul_apps + def _get_id_max_min_triple(script_name, package, install_rdf): """create array of id_max_min triples""" id_max_min = [] @@ -169,7 +173,7 @@ def _get_id_max_min_triple(script_name, package, install_rdf): parser = RDF.Parser(name="rdfxml") parser.parse_into_model(model, "file:" + install_rdf) query = RDF.Query( - """ + """ PREFIX em: <http://www.mozilla.org/2004/em-rdf#> SELECT ?id ?max ?min WHERE { @@ -180,7 +184,7 @@ def _get_id_max_min_triple(script_name, package, install_rdf): ?x em:minVersion ?min . } . } - """, query_language="sparql") + """, query_language="sparql") results = query.execute(model) # append to id_max_min tripe to array failures = 0 @@ -188,15 +192,15 @@ def _get_id_max_min_triple(script_name, package, install_rdf): appid = target["id"].literal_value["string"] max_version = target["max"].literal_value["string"] min_version = target["min"].literal_value["string"] - id_max_min.append ((appid, max_version, min_version)) + id_max_min.append((appid, max_version, min_version)) # Sanity check version range if compare_versions(min_version, max_version) > 0: msg = ("%s: %s contains an invalid version range for %s:\n" "%s: minVersion <= maxVersion is required, but %s > %s.\n" "%s: Please either fix the versions or remove the entry " - "from install.xpi.") % \ + "from install.xpi." % (script_name, package, appid, script_name, min_version, - max_version, script_name) + max_version, script_name)) print >> sys.stderr, msg failures += 1 if failures > 0: @@ -204,6 +208,7 @@ def _get_id_max_min_triple(script_name, package, install_rdf): 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(script_name, package, install_rdf) @@ -241,12 +246,14 @@ def get_supported_apps(script_name, xul_apps, install_rdf, package, 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") @@ -256,11 +263,13 @@ def get_source_package_name(): 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-"): @@ -293,6 +302,7 @@ def get_provided_package_names(package, supported_apps): return list(provides) + def find_install_rdfs(path): install_rdfs = set() @@ -307,12 +317,13 @@ def find_install_rdfs(path): 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)." + 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. " @@ -359,7 +370,7 @@ def generate_substvars(script_name, xul_apps, package, verbose=False): class UnknownOptionIgnoringOptionParser(optparse.OptionParser): - def __init__ (self, **options): + def __init__(self, **options): optparse.OptionParser.__init__(self, **options) self.unknown_options = [] @@ -400,7 +411,7 @@ def main(): if options.verbose: for unknown_option in parser.unknown_options: - sys.stderr.write("%s: warning: no such option: %s\n" % \ + sys.stderr.write("%s: warning: no such option: %s\n" % (script_name, unknown_option)) print script_name + ": packages:", ", ".join(options.packages) diff --git a/install-xpi b/install-xpi index c8856e8..ec0af31 100755 --- a/install-xpi +++ b/install-xpi @@ -37,6 +37,7 @@ LICENSE_PATTERN_LIST = ( COMMAND_LINE_SYNTAX_ERROR = 1 XPI_FILE_DOES_NOT_EXISTS = 2 + def get_debian_directory(script_name): """Return the path to the debian/ directory. @@ -62,28 +63,36 @@ def get_debian_directory(script_name): sys.exit(1) return package_directory + 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: <http://www.mozilla.org/2004/em-rdf#> " + \ + 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 { [] em:targetApplication ?x . ?x em:id ?id }") + target_applications = get_query_field_id_as_list( + install_rdf, + "SELECT ?id WHERE { [] em:targetApplication ?x . ?x 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 {?x em:targetApplication [] . ?x em:id ?id }")) + extension_ids = set(get_query_field_id_as_list( + install_rdf, + "SELECT ?id WHERE {?x em:targetApplication [] . ?x em:id ?id }" + )) return extension_ids.pop() + def get_arch(package, debian_directory): lines = open(os.path.join(debian_directory, "control")).readlines() package_lines = filter(lambda x: x.find("Package:") >= 0, lines) @@ -94,11 +103,13 @@ def get_arch(package, debian_directory): 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) @@ -107,9 +118,10 @@ def get_xul_apps(): rows.append(row) return rows + def install_xpi(script_name, package, xpi_file, exclude, install_dir, links, - correct_permissions, remove_licenses, system_prefs, debian_directory, - verbose=False): + correct_permissions, remove_licenses, system_prefs, + debian_directory, 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." % \ @@ -125,7 +137,7 @@ def install_xpi(script_name, package, xpi_file, exclude, install_dir, links, lib_share_dir = "lib" if install_dir is None: install_dir = os.path.join("usr", lib_share_dir, "xul-ext", - package.replace("xul-ext-", "")) + package.replace("xul-ext-", "")) copy_dir = os.path.join(debian_directory, package, install_dir.strip("/")) if verbose: print "%s: install directory: %s" % (script_name, install_dir) @@ -175,8 +187,8 @@ def install_xpi(script_name, package, xpi_file, exclude, install_dir, links, if system_prefs: # search for preference .js files in defaults/preferences/ pref_dir = os.path.join("defaults", "preferences") - preferences = filter(lambda f: os.path.dirname(f) == pref_dir and \ - f.endswith(".js"), xpi_content) + 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_directory, package, prefdir) @@ -216,7 +228,7 @@ def install_xpi(script_name, package, xpi_file, exclude, install_dir, links, 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) + target_application, extension_id) links.add(destination) # create symlinks @@ -225,12 +237,14 @@ def install_xpi(script_name, package, xpi_file, exclude, install_dir, links, print " ".join(command) subprocess.call(command) + def get_first_package(debian_directory): lines = open(os.path.join(debian_directory, "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(): script_name = os.path.basename(sys.argv[0]) usage = "%s [options] <xpi-file>" % (script_name) @@ -238,28 +252,28 @@ def main(): 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) + 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()) + 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") + 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()) + 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=None) - 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) + help="install the extension into specified PACKAGE", + dest="package", default=None) + parser.add_option("--preserve-permissions", dest="correct_permissions", + action="store_false", default=True, + help="do not adjust the file permissions") + parser.add_option("-r", "--remove-license-files", dest="remove_licenses", + action="store_true", default=False, + help="do not install license files") parser.add_option("-v", "--verbose", help="print more information", - dest="verbose", action="store_true", default=False) + dest="verbose", action="store_true", default=False) (options, args) = parser.parse_args() @@ -277,8 +291,8 @@ def main(): options.package = get_first_package(debian_directory) if options.verbose: - print script_name + ": Install %s into package %s." % \ - (args[0], options.package) + 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), diff --git a/moz-version b/moz-version index 6362b31..912501c 100755 --- a/moz-version +++ b/moz-version @@ -28,6 +28,7 @@ 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, diff --git a/moz_version.py b/moz_version.py index c4cebed..04b3cd8 100644 --- a/moz_version.py +++ b/moz_version.py @@ -16,6 +16,7 @@ import sys + def decode_part(part): """Decodes a version part (like 5pre4) to <number-a><string-b><number-c><string-d>""" @@ -67,6 +68,7 @@ def decode_part(part): return subpart + def decode_version(version, verbose=False): """Decodes a version string like 1.1pre1a""" parts = version.split(".") @@ -75,6 +77,7 @@ def decode_version(version, verbose=False): 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 == "": @@ -90,6 +93,7 @@ def compare_subpart((a, b)): else: return cmp(a, b) + def compare_part((x, y)): compared_subparts = filter(lambda x: x != 0, map(compare_subpart, zip(x, y))) @@ -98,6 +102,7 @@ def compare_part((x, y)): else: return 0 + def compare_versions(version1, version2, verbose=False): a = decode_version(version1, verbose) b = decode_version(version2, verbose) @@ -113,6 +118,7 @@ def compare_versions(version1, version2, verbose=False): 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('-') @@ -128,6 +134,7 @@ def extract_upstream_version(debian_version): 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 @@ -141,6 +148,7 @@ def _convert_part_to_debian(part): 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) @@ -155,6 +163,7 @@ def convert_debian_to_moz_version(debian_version, verbose=False): 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 @@ -164,6 +173,7 @@ def convert_moz_to_debian_version(moz_version, epoch=0, verbose=False): 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. @@ -6,6 +6,7 @@ import re from distutils.core import setup + def get_debian_version(): """look what Debian version we have""" version = None @@ -28,17 +29,16 @@ SCRIPTS = [ ] if __name__ == '__main__': - setup(name='mozilla-devscripts', - version=get_debian_version(), - scripts=SCRIPTS, - py_modules=['moz_version'], - data_files=[('share/doc/mozilla-devscripts', ['README']), - ('share/man/man1', glob.glob("man/*.1")), - ('share/mozilla-devscripts', - ['data/xpi.mk'] + glob.glob('data/xul-app-data.csv.*')), - ('share/perl5/Debian/Debhelper/Buildsystem', - ['perl/Debian/Buildsystem/xul_ext.pm']), - ('share/perl5/Debian/Debhelper/Sequence', - ['perl/Debian/Sequence/xul_ext.pm']), - ], + setup( + name='mozilla-devscripts', + version=get_debian_version(), + scripts=SCRIPTS, + py_modules=['moz_version'], + data_files=[ + ('share/doc/mozilla-devscripts', ['README']), + ('share/man/man1', glob.glob("man/*.1")), + ('share/mozilla-devscripts', ['data/xpi.mk'] + glob.glob('data/xul-app-data.csv.*')), + ('share/perl5/Debian/Debhelper/Buildsystem', ['perl/Debian/Buildsystem/xul_ext.pm']), + ('share/perl5/Debian/Debhelper/Sequence', ['perl/Debian/Sequence/xul_ext.pm']), + ], ) |