summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2011-05-22 11:53:41 -0700
committerZac Medico <zmedico@gentoo.org>2011-05-22 11:53:41 -0700
commitd0a8b0bdfeeb406f459ee460f0df3b1b3360ddf1 (patch)
tree428301ec445b9116dffb8fa6f9880225b394fd45
parent9f4e7fa99017888ffed7414a6238961165b6d4e6 (diff)
downloadportage-d0a8b0bdfeeb406f459ee460f0df3b1b3360ddf1.tar.gz
portage-d0a8b0bdfeeb406f459ee460f0df3b1b3360ddf1.tar.bz2
portage-d0a8b0bdfeeb406f459ee460f0df3b1b3360ddf1.zip
Package: add new _gen_hash_key method
-rw-r--r--pym/_emerge/FakeVartree.py6
-rw-r--r--pym/_emerge/Package.py45
-rw-r--r--pym/_emerge/Scheduler.py24
-rw-r--r--pym/_emerge/depgraph.py22
4 files changed, 53 insertions, 44 deletions
diff --git a/pym/_emerge/FakeVartree.py b/pym/_emerge/FakeVartree.py
index ff092adfe..3e8113078 100644
--- a/pym/_emerge/FakeVartree.py
+++ b/pym/_emerge/FakeVartree.py
@@ -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)
diff --git a/pym/_emerge/Package.py b/pym/_emerge/Package.py
index 6847a3240..cb476d68e 100644
--- a/pym/_emerge/Package.py
+++ b/pym/_emerge/Package.py
@@ -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):
"""
diff --git a/pym/_emerge/Scheduler.py b/pym/_emerge/Scheduler.py
index 74d888a2e..b10439a00 100644
--- a/pym/_emerge/Scheduler.py
+++ b/pym/_emerge/Scheduler.py
@@ -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
diff --git a/pym/_emerge/depgraph.py b/pym/_emerge/depgraph.py
index d09ee87ba..0bd351278 100644
--- a/pym/_emerge/depgraph.py
+++ b/pym/_emerge/depgraph.py
@@ -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]