Package: add new _gen_hash_key method
authorZac Medico <zmedico@gentoo.org>
Sun, 22 May 2011 18:53:41 +0000 (11:53 -0700)
committerZac Medico <zmedico@gentoo.org>
Thu, 26 May 2011 04:19:08 +0000 (21:19 -0700)
pym/_emerge/FakeVartree.py
pym/_emerge/Package.py
pym/_emerge/Scheduler.py
pym/_emerge/depgraph.py

index db31535a6f9fbd7b607910f50d67b84520c0e13a..61dd54061893eb261f77c4616a4e999150047d3e 100644 (file)
@@ -150,11 +150,13 @@ class FakeVartree(vartree):
 
                # Validate counters and timestamps.
                slot_counters = {}
-               root = self.root
+               root_config = self._pkg_root_config
                validation_keys = ["COUNTER", "_mtime_"]
                for cpv in current_cpv_set:
 
-                       pkg_hash_key = ("installed", root, cpv, "nomerge")
+                       pkg_hash_key = Package._gen_hash_key(cpv=cpv,
+                               installed=True, root_config=root_config,
+                               type_name="installed")
                        pkg = pkg_vardb.get(pkg_hash_key)
                        if pkg is not None:
                                counter, mtime = real_vardb.aux_get(cpv, validation_keys)
index a7d8e26f5f0795d915aaa40dfb50c37ab45be655..90425a718100ae4dcd6929691b8c34069bfd8a6e 100644 (file)
@@ -73,10 +73,32 @@ class Package(Task):
                        else:
                                self.operation = "merge"
 
-               self._hash_key = \
-                       (self.type_name, self.root, self.cpv, self.operation)
+               self._hash_key = Package._gen_hash_key(cpv=self.cpv,
+                       installed=self.installed, onlydeps=self.onlydeps,
+                       operation=self.operation,
+                       root_config=self.root_config,
+                       type_name=self.type_name)
                self._hash_value = hash(self._hash_key)
 
+       @classmethod
+       def _gen_hash_key(cls, cpv=None, installed=None, onlydeps=None,
+               operation=None, repo_name=None, root_config=None,
+               type_name=None, **kwargs):
+
+               if operation is None:
+                       if installed or onlydeps:
+                               operation = "nomerge"
+                       else:
+                               operation = "merge"
+
+               root = None
+               if root_config is not None:
+                       root = root_config.root
+               else:
+                       raise TypeError("root_config argument is required")
+
+               return (type_name, root, cpv, operation)
+
        def _validate_deps(self):
                """
                Validate deps. This does not trigger USE calculation since that
index 14b89a8527d053ee459fc1c2459986e1d22083f3..46aa11d9e6848ab0af49bcb08cc76ee54c7af6f9 100644 (file)
@@ -2002,15 +2002,12 @@ class Scheduler(PollScheduler):
                failures for some reason (package does not exist or is
                corrupt).
                """
-               if operation is None:
-                       if installed:
-                               operation = "nomerge"
-                       else:
-                               operation = "merge"
 
                # Reuse existing instance when available.
-               pkg = self._pkg_cache.get(
-                       (type_name, root_config.root, cpv, operation))
+               pkg = self._pkg_cache.get(Package._gen_hash_key(cpv=cpv,
+                       type_name=type_name, root_config=root_config,
+                       installed=installed, operation=operation))
+
                if pkg is not None:
                        return pkg
 
index d0409a4162eb26eeac99934992a1d189e0f2974b..6c126e1d68ec7e17a8ad25e73da8b024f973821b 100644 (file)
@@ -3744,18 +3744,20 @@ class depgraph(object):
                failures for some reason (package does not exist or is
                corrupt).
                """
-               operation = "merge"
-               if installed or onlydeps:
-                       operation = "nomerge"
+
                # Ensure that we use the specially optimized RootConfig instance
                # that refers to FakeVartree instead of the real vartree.
                root_config = self._frozen_config.roots[root_config.root]
                pkg = self._frozen_config._pkg_cache.get(
-                       (type_name, root_config.root, cpv, operation))
+                       Package._gen_hash_key(cpv=cpv, type_name=type_name,
+                       root_config=root_config,
+                       installed=installed, onlydeps=onlydeps))
                if pkg is None and onlydeps and not installed:
                        # Maybe it already got pulled in as a "merge" node.
                        pkg = self._dynamic_config.mydbapi[root_config.root].get(
-                               (type_name, root_config.root, cpv, 'merge'))
+                               Package._gen_hash_key(cpv=cpv, type_name=type_name,
+                               root_config=root_config,
+                               installed=installed, onlydeps=False))
 
                if pkg is None:
                        tree_type = self.pkg_tree_map[type_name]