Integrate the load_mtimedb() function into the MtimeDB class. This function is relat...
authorZac Medico <zmedico@gentoo.org>
Fri, 30 Jun 2006 18:12:54 +0000 (18:12 -0000)
committerZac Medico <zmedico@gentoo.org>
Fri, 30 Jun 2006 18:12:54 +0000 (18:12 -0000)
svn path=/main/trunk/; revision=3721

pym/portage.py

index 99a3591d1f745b3917036f165ef2a50cc81dd561..9fd03677e3b03be2055cfcdc19c8af0d86b56f7f 100644 (file)
@@ -7083,29 +7083,6 @@ class LazyBintreeItem(object):
                        self._bintree.populate()
                return self._bintree
 
-def load_mtimedb(f):
-       """Given an open file, unpickle an mtimedb and validate it."""
-       mypickle = cPickle.Unpickler(f)
-       mypickle.find_global = None
-       d = mypickle.load()
-       if "old" in d:
-               d["updates"] = d["old"]
-               del d["old"]
-       if "cur" in d:
-               del d["cur"]
-
-       for k in ("info", "ldpath", "updates"):
-               d.setdefault(k, {})
-
-       mtimedbkeys = set(("info", "ldpath", "resume", "resume_backup",
-               "starttime", "updates", "version"))
-
-       for k in d.keys():
-               if k not in mtimedbkeys:
-                       writemsg("Deleting invalid mtimedb key: %s\n" % str(k))
-                       del d[k]
-       return d
-
 class MtimeDB(dict):
        def __init__(self, filename):
                dict.__init__(self)
@@ -7115,11 +7092,32 @@ class MtimeDB(dict):
        def _load(self, filename):
                try:
                        f = open(filename)
-                       d = load_mtimedb(f)
+                       mypickle = cPickle.Unpickler(f)
+                       mypickle.find_global = None
+                       d = mypickle.load()
                        f.close()
                        del f
                except (IOError, OSError, EOFError):
-                       d = {"updates":{}, "ldpath":{}, "version":"", "starttime":0}
+                       d = {}
+
+               if "old" in d:
+                       d["updates"] = d["old"]
+                       del d["old"]
+               if "cur" in d:
+                       del d["cur"]
+
+               d.setdefault("starttime", 0)
+               d.setdefault("version", "")
+               for k in ("info", "ldpath", "updates"):
+                       d.setdefault(k, {})
+
+               mtimedbkeys = set(("info", "ldpath", "resume", "resume_backup",
+                       "starttime", "updates", "version"))
+
+               for k in d.keys():
+                       if k not in mtimedbkeys:
+                               writemsg("Deleting invalid mtimedb key: %s\n" % str(k))
+                               del d[k]
                self.update(d)
 
        def commit(self):