3 import os, os.path, gzip, sys
7 def get_package_versions_file(f, map):
11 for line in gzip.open(f):
14 if (not currpkg) or (not currversion):
15 print >> sys.stderr, "Error: end of package record without all data available"
17 map.setdefault(currpkg, []).append(currversion)
22 attr = line.split(":", 1)
27 if attr[0] == "Package":
29 print >> sys.stderr, "Error: read two Packages: lines in a row"
31 currpkg = attr[1].strip()
33 if attr[0] == "Version":
35 print >> sys.stderr, "Error: read two Version: lines in a row"
37 currversion = attr[1].strip()
39 colpos = currversion.find(':')
41 currversion = currversion[colpos+1:]
43 def get_package_versions_tree(rootdir):
44 """Generate a archive map from a Debian-style package archive directory.
46 rootdir: path to archive root path
47 return: mapping: sourcepackage -> [versions]
52 for release in os.listdir(rootdir + "/dists"):
53 for comp in os.listdir(rootdir + "/dists/" + release):
54 compdir = rootdir + "/dists/" + release + "/" + comp
55 if not os.path.isdir(compdir):
57 get_package_versions_file(compdir + "/source/Sources.gz", map)
58 for arch in os.listdir(compdir):
59 if arch.startswith('binary-'):
60 get_package_versions_file(compdir + '/' + arch + '/Packages.gz', map)
64 known_versions = get_package_versions_tree(mirrordir)
66 for path, dirs, files in os.walk(os.path.join(mirrordir, 'pool')):
68 (pkg, version) = (f.split('_'))[0:2]
69 if f.endswith('.deb'):
71 elif f.endswith('.dsc'):
72 version = version[:-4]
73 elif f.endswith('.diff.gz'):
74 version = version[:-8]
75 elif f.endswith('.tar.gz'):
78 print os.path.join(path, f)
81 if not version in known_versions.get(pkg, ()):
82 print os.path.join(path, f)