Bug #184118 - Add an emaint "cleanresume" action that deletes
authorZac Medico <zmedico@gentoo.org>
Mon, 22 Oct 2007 05:45:58 +0000 (05:45 -0000)
committerZac Medico <zmedico@gentoo.org>
Mon, 22 Oct 2007 05:45:58 +0000 (05:45 -0000)
any existing resume lists from the mtimedb. Thanks to Arfrever
Frehtes Taifersar Arahesis for the initial patch.

svn path=/main/trunk/; revision=8224

bin/emaint

index 40abc9e0d2969ac4a168082234947670e38b1d30..64af1f01afc84264496e0e11e3e268201cee194f 100755 (executable)
@@ -343,6 +343,54 @@ class ProgressHandler(object):
        def display(self):
                raise NotImplementedError(self)
 
+class CleanResume(object):
+       def name():
+               return "cleanresume"
+       name = staticmethod(name)
+
+       def check(self, onProgress=None):
+               messages = []
+               mtimedb = portage.mtimedb
+               resume_keys = ("resume", "resume_backup")
+               maxval = len(resume_keys)
+               if onProgress:
+                       onProgress(maxval, 0)
+               for i, k in enumerate(resume_keys):
+                       try:
+                               d = mtimedb.get(k)
+                               if d is None:
+                                       continue
+                               if not isinstance(d, dict):
+                                       messages.append("unrecognized resume list: '%s'" % k)
+                                       continue
+                               mergelist = d.get("mergelist")
+                               if mergelist is None or not hasattr(mergelist, "__len__"):
+                                       messages.append("unrecognized resume list: '%s'" % k)
+                                       continue
+                               messages.append("resume list '%s' contains %d packages" % \
+                                       (k, len(mergelist)))
+                       finally:
+                               if onProgress:
+                                       onProgress(maxval, i+1)
+               return messages
+
+       def fix(self, onProgress=None):
+               delete_count = 0
+               mtimedb = portage.mtimedb
+               resume_keys = ("resume", "resume_backup")
+               maxval = len(resume_keys)
+               if onProgress:
+                       onProgress(maxval, 0)
+               for i, k in enumerate(resume_keys):
+                       try:
+                               if mtimedb.pop(k, None) is not None:
+                                       delete_count += 1
+                       finally:
+                               if onProgress:
+                                       onProgress(maxval, i+1)
+               if delete_count:
+                       mtimedb.commit()
+
 def emaint_main(myargv):
 
        # TODO: Create a system that allows external modules to be added without
@@ -351,7 +399,8 @@ def emaint_main(myargv):
                "world" : WorldHandler,
                "binhost":BinhostHandler,
                "moveinst":MoveInstalled,
-               "movebin":MoveBinary
+               "movebin":MoveBinary,
+               "cleanresume":CleanResume
        }
 
        module_names = modules.keys()