[Treepkg-commits] r501 - trunk/contrib/bin

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Jan 10 15:58:51 CET 2011


Author: teichmann
Date: 2011-01-10 15:58:51 +0100 (Mon, 10 Jan 2011)
New Revision: 501

Modified:
   trunk/contrib/bin/delete-old-debs.py
Log:
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.


Modified: trunk/contrib/bin/delete-old-debs.py
===================================================================
--- trunk/contrib/bin/delete-old-debs.py	2011-01-10 11:36:55 UTC (rev 500)
+++ trunk/contrib/bin/delete-old-debs.py	2011-01-10 14:58:51 UTC (rev 501)
@@ -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,14 +89,18 @@
 
     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():
     usage = "usage: %prog [options] dir ..."
     parser = OptionParser(usage=usage)



More information about the Treepkg-commits mailing list