# HG changeset patch # User Sascha Teichmann # Date 1294671531 0 # Node ID 6fb5e8b744147307f47c0a6f3a9b28f2ab3c4682 # Parent aeccb5774939eb7f1a23e10338bccf94e9890759 contrib: Do a more conservative approach (full sorting) to figure out the youngest debs. This _much_ slower but it works correctly. TODO: make the heapq.nsmallest() work correct. diff -r aeccb5774939 -r 6fb5e8b74414 contrib/bin/delete-old-debs.py --- a/contrib/bin/delete-old-debs.py Mon Jan 10 11:36:55 2011 +0000 +++ b/contrib/bin/delete-old-debs.py Mon Jan 10 14:58:51 2011 +0000 @@ -15,7 +15,7 @@ import subprocess import logging -from heapq import nsmallest +#from heapq import nsmallest from optparse import OptionParser @@ -27,18 +27,6 @@ FIELD = re.compile("([a-zA-Z]+):\s*(.+)") -# map rich comparison to 'dpkg --compare-versions' -# map == to !=, < to >= and so on to reverse order in heap. -RICH_CMP = dict([ - ("__%s__" % a, lambda se, ot: - subprocess.call([ - "dpkg", "--compare-versions", - se.version, b, ot.version]) == 0) - for a, b in (("eq", "ne"), ("ne", "eq"), - ("lt", "ge"), ("gt", "le"), - ("le", "gt"), ("ge", "lt"))]) - - class DebCmp(object): """Helper class to make deb files comparable by there versions. @@ -48,7 +36,19 @@ self.version = version self.path = path - self.__dict__.update(RICH_CMP) + def __cmp__(self, other): + if self.version == other.version: + return 0 + # switch lt and gt to reverse order in heap + if (subprocess.call([ + "dpkg", "--compare-versions", + self.version, "gt", other.version]) == 0): + return -1 + if (subprocess.call([ + "dpkg", "--compare-versions", + self.version, "lt", other.version]) == 0): + return +1 + return 0 def deb_info(deb, fields=["Package", "Version"]): @@ -89,12 +89,16 @@ for package, debs in packages.iteritems(): if len(debs) > keep: - # full sorting is not required - stay = frozenset([d.path for d in nsmallest(keep, debs)]) + debs.sort() + for deb in debs[keep:]: + yield deb.path - for deb in debs: - if deb.path not in stay: - yield deb.path + ## full sorting is not required + #stay = frozenset([d.path for d in nsmallest(keep, debs)]) + + #for deb in debs: + # if deb.path not in stay: + # yield deb.path def main():