* Add a digraph.get() method, analogous to dict.get(), used to simplify
authorZac Medico <zmedico@gentoo.org>
Sat, 12 Jul 2008 01:58:23 +0000 (01:58 -0000)
committerZac Medico <zmedico@gentoo.org>
Sat, 12 Jul 2008 01:58:23 +0000 (01:58 -0000)
  Scheduler._pkg().

* Define digraph.__contains__ for containment tests via the "in" operator.

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

pym/_emerge/__init__.py
pym/portage/__init__.py

index 5dbb447952f2101cd1dd23f0f6dbec4338f433d2..38f485aae2e4711ca316799a16492e8e9b7c220c 100644 (file)
@@ -8732,12 +8732,9 @@ class Scheduler(PollLoop):
                        settings.setcpv(pkg)
                        pkg.metadata["USE"] = settings["PORTAGE_USE"]
 
-               if self._digraph and \
-                       self._digraph.contains(pkg):
-                       for existing_instance in self._digraph.order:
-                               if existing_instance == pkg:
-                                       pkg = existing_instance
-                                       break
+               if self._digraph is not None:
+                       # Reuse existing instance when available.
+                       pkg = self._digraph.get(pkg, pkg)
 
                return pkg
 
index 453096f6753e1e96446ce8787ac94c884997a5d4..535ea9ed753cc4c2eab45c166bc044e111a3c6ff 100644 (file)
@@ -437,6 +437,9 @@ class digraph(object):
                """Checks if the digraph contains mynode"""
                return node in self.nodes
 
+       def get(self, key, default=None):
+               return self.nodes.get(key, default)
+
        def all_nodes(self):
                """Return a list of all nodes in the graph"""
                return self.order[:]
@@ -506,6 +509,7 @@ class digraph(object):
        allnodes = all_nodes
        allzeros = leaf_nodes
        hasnode = contains
+       __contains__ = contains
        empty = is_empty
        copy = clone