From: martin@piware.de <> Date: Fri, 22 Sep 2006 20:29:33 +0000 (+0200) Subject: use new archive_tools.py for mirror-orphans X-Git-Url: https://piware.de/gitweb/?p=bin.git;a=commitdiff_plain;h=41540a1ca74f57d6a941d867b8dec015c23eda7e use new archive_tools.py for mirror-orphans --- diff --git a/mirror-orphans b/mirror-orphans index a44ba89..c7c7f3f 100755 --- a/mirror-orphans +++ b/mirror-orphans @@ -1,83 +1,7 @@ #!/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')