Author: fw Date: 2011-04-24 15:35:27 +0000 (Sun, 24 Apr 2011) New Revision: 16581 Modified: bin/list-queue Log: bin/list-queue: remove dependency on debian_support Modified: bin/list-queue ==================================================================--- bin/list-queue 2011-04-24 15:27:54 UTC (rev 16580) +++ bin/list-queue 2011-04-24 15:35:27 UTC (rev 16581) @@ -33,20 +33,14 @@ # End Configuration ###################################################################### -import sys +import json import os.path -def setup_path(): - dirname = os.path.dirname - base = dirname(dirname(os.path.realpath(sys.argv[0]))) - sys.path.insert(0, os.path.join(base, "lib", "python")) -setup_path() - +import re import sqlite3 -import json +import sys +from debian.deb822 import Changes from debian.debfile import DebFile -from debian.deb822 import Changes -import debian_support def createdb(): cache = os.path.expanduser("~/.cache") @@ -100,7 +94,7 @@ result = {} for row in db.execute("SELECT * FROM package"): name, size, mtime = row[0:3] - pkg = debian_support.BinaryPackage(row[3:]) + pkg = tuple(row[3:]) result[name] = (size, mtime, pkg) return result @@ -131,6 +125,29 @@ for (key, value) in data.items(): data[key] = value[2:] +# See debian_support.BinaryPackage.loadtuple(). +def deb822totuple(data, re_source=re.compile( + r''^([a-zA-Z0-9.+-]+)(?:\s+\(([a-zA-Z0-9.+:~-]+)\))?$'')): + """Turns an Deb822-like object into a 5-tuple. + + Returns (PACKAGE-NAME, VERSION, ARCHITECTURE, SOURCE, + SOURCE-VERSION).""" + + pkg = data["Package"] + version = data["Version"] + if "Source" in data: + source = data.get("Source", None) + match = re_source.match(source) + if match is None: + raise ValueError("invalid Source field: " + repr(source)) + src, src_version = match.groups() + if src_version is None: + src_version = version + else: + src = pkg + src_version = version + return (pkg, version, data["Architecture"], src, src_version) + def updatepackages(db, ondisk): "Updates the package table from the file system." indb = readpackages(db) @@ -141,10 +158,9 @@ def do_update(): for (path, stat) in need_update: deb = DebFile(path) - pkg = debian_support.BinaryPackage() - pkg.load822(deb.debcontrol()) + pkg = deb822totuple(deb.debcontrol()) indb[path] = stat + (pkg,) - yield (path,) + stat + pkg.astuple() + yield (path,) + stat + pkg db.executemany("INSERT INTO package VALUES (?, ?, ?, ?, ?, ?, ?, ?)", do_update()) @@ -194,7 +210,7 @@ Returns a list of tuples (PACKAGE-NAME, VERSION, ARCHITECTURE, SOURCE-NAME, SOURCE-VERSION, TUPLE-OF-DISTRIBUTIONS). """ - return [pkg.astuple() + (sorted(dists.get(path, ())),) + return [pkg + (sorted(dists.get(path, ())),) for (path, (pkg,)) in debs.items()] def main():