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>
Sun, 22 May 2011 18:53:41 +0000 (11:53 -0700)
pym/_emerge/FakeVartree.py
pym/_emerge/Package.py
pym/_emerge/Scheduler.py
pym/_emerge/depgraph.py

index ff092adfe8687987c594b7c1b7a94abeeee7c643..3e8113078e6e3d7849bb65274cc447d21254698f 100644 (file)
@@ -153,11 +153,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", "installed")
+                       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 6847a32408fd212b459235feffcf4007c77d67e7..cb476d68e25ce70263e0ade27649a8db5910c3ec 100644 (file)
@@ -81,15 +81,48 @@ class Package(Task):
                        else:
                                self.operation = "merge"
 
+               self._hash_key = Package._gen_hash_key(cpv=self.cpv,
+                       installed=self.installed, onlydeps=self.onlydeps,
+                       operation=self.operation, repo_name=repo,
+                       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")
+
                # For installed (and binary) packages we don't care for the repo
                # when it comes to hashing, because there can only be one cpv.
                # So overwrite the repo_key with type_name.
-               repo_key = self.metadata.get('repository')
-               if self.type_name != 'ebuild':
-                       repo_key = self.type_name
-               self._hash_key = \
-                       (self.type_name, self.root, self.cpv, self.operation, repo_key)
-               self._hash_value = hash(self._hash_key)
+               if type_name is None:
+                       raise TypeError("type_name argument is required")
+               elif type_name == "ebuild":
+                       if repo_name is None:
+                               raise AssertionError(
+                                       "Package._gen_hash_key() " + \
+                                       "called without 'repo_name' argument")
+                       repo_key = repo_name
+               else:
+                       # For installed (and binary) packages we don't care for the repo
+                       # when it comes to hashing, because there can only be one cpv.
+                       # So overwrite the repo_key with type_name.
+                       repo_key = type_name
+
+               return (type_name, root, cpv, operation, repo_key)
 
        def _validate_deps(self):
                """
index 74d888a2e50cfee22d2d5d2612e40b9522c3e398..b10439a004b06af25489906504aab167046f0ca7 100644 (file)
@@ -2016,27 +2016,11 @@ class Scheduler(PollScheduler):
                corrupt).
                """
 
-               if type_name != "ebuild":
-                       # For installed (and binary) packages we don't care for the repo
-                       # when it comes to hashing, because there can only be one cpv.
-                       # So overwrite the repo_key with type_name.
-                       repo_key = type_name
-                       myrepo = None
-               elif myrepo is None:
-                       raise AssertionError(
-                               "Scheduler._pkg() called without 'myrepo' argument")
-               else:
-                       repo_key = myrepo
-
-               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, repo_key))
+               pkg = self._pkg_cache.get(Package._gen_hash_key(cpv=cpv,
+                       type_name=type_name, repo_name=myrepo, root_config=root_config,
+                       installed=installed, operation=operation))
+
                if pkg is not None:
                        return pkg
 
index d09ee87ba19c80fd511c346121d997b17b6b730c..0bd35127876783a0014e94202cf796372aef29bd 100644 (file)
@@ -4130,30 +4130,20 @@ class depgraph(object):
                failures for some reason (package does not exist or is
                corrupt).
                """
-               if type_name != "ebuild":
-                       # For installed (and binary) packages we don't care for the repo
-                       # when it comes to hashing, because there can only be one cpv.
-                       # So overwrite the repo_key with type_name.
-                       repo_key = type_name
-                       myrepo = None
-               elif myrepo is None:
-                       raise AssertionError(
-                               "depgraph._pkg() called without 'myrepo' argument")
-               else:
-                       repo_key = myrepo
 
-               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, repo_key))
+                       Package._gen_hash_key(cpv=cpv, type_name=type_name,
+                       repo_name=myrepo, 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', repo_key))
+                               Package._gen_hash_key(cpv=cpv, type_name=type_name,
+                               repo_name=myrepo, root_config=root_config,
+                               installed=installed, onlydeps=False))
 
                if pkg is None:
                        tree_type = self.pkg_tree_map[type_name]