#!/usr/bin/python
-import os, os.path, gzip, sys
-
-mirrordir = '/mirror'
-
-def get_package_versions_file(f, map):
- currpkg = None
- currversion = None
-
- for line in gzip.open(f):
- line = line.strip()
- if not line:
- if (not currpkg) or (not currversion):
- print >> sys.stderr, "Error: end of package record without all data available"
- sys.exit(1)
- map.setdefault(currpkg, []).append(currversion)
- currpkg = None
- currversion = None
- continue
-
- attr = line.split(":", 1)
-
- if len(attr) < 2:
- continue
-
- if attr[0] == "Package":
- if currpkg:
- print >> sys.stderr, "Error: read two Packages: lines in a row"
- sys.exit(1)
- currpkg = attr[1].strip()
-
- if attr[0] == "Version":
- if currversion:
- print >> sys.stderr, "Error: read two Version: lines in a row"
- sys.exit(1)
- currversion = attr[1].strip()
- # remove epochs
- colpos = currversion.find(':')
- if colpos >= 0:
- currversion = currversion[colpos+1:]
-
-def get_package_versions_tree(rootdir):
- """Generate a archive map from a Debian-style package archive directory.
-
- rootdir: path to archive root path
- return: mapping: sourcepackage -> [versions]
- """
-
- map = {}
-
- for release in os.listdir(rootdir + "/dists"):
- for comp in os.listdir(rootdir + "/dists/" + release):
- compdir = rootdir + "/dists/" + release + "/" + comp
- if not os.path.isdir(compdir):
- continue
- get_package_versions_file(compdir + "/source/Sources.gz", map)
- for arch in os.listdir(compdir):
- if arch.startswith('binary-'):
- get_package_versions_file(compdir + '/' + arch + '/Packages.gz', map)
-
- return map
-
-known_versions = get_package_versions_tree(mirrordir)
-
-for path, dirs, files in os.walk(os.path.join(mirrordir, 'pool')):
- for f in files:
- (pkg, version) = (f.split('_'))[0:2]
- if f.endswith('.deb'):
- pass
- elif f.endswith('.dsc'):
- version = version[:-4]
- elif f.endswith('.diff.gz'):
- version = version[:-8]
- elif f.endswith('.tar.gz'):
- continue
- else:
- print os.path.join(path, f)
- continue
-
- if not version in known_versions.get(pkg, ()):
- print os.path.join(path, f)
+import sys
+sys.path.append('/home/martin/ubuntu/ddeb-retriever/')
+import archive_tools
+archive_tools.archive_cleanup('/mirror')