Replace depgraph._slot_node_map with _slot_pkg_map so
authorZac Medico <zmedico@gentoo.org>
Sat, 27 Oct 2007 20:43:49 +0000 (20:43 -0000)
committerZac Medico <zmedico@gentoo.org>
Sat, 27 Oct 2007 20:43:49 +0000 (20:43 -0000)
that it's easier to get existing Package instances.

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

pym/_emerge/__init__.py

index 5cac1f5285cc81f83f6eb455b531816e60723cb2..e5ac45cd5b189ce81ed44ba0b09356e309d75142 100644 (file)
@@ -883,8 +883,9 @@ def iter_atoms(deps):
                                yield x
 
 class Package(object):
-       __slots__ = ("__weakref__", "built", "cpv", "_digraph_node",
-               "installed", "metadata", "root", "onlydeps", "type_name")
+       __slots__ = ("__weakref__", "built", "cpv",
+               "installed", "metadata", "root", "onlydeps", "type_name",
+               "_digraph_node", "_slot_atom")
        def __init__(self, **kwargs):
                for myattr in self.__slots__:
                        if myattr == "__weakref__":
@@ -892,6 +893,13 @@ class Package(object):
                        myvalue = kwargs.get(myattr, None)
                        setattr(self, myattr, myvalue)
 
+       @property
+       def slot_atom(self):
+               if self._slot_atom is None:
+                       self._slot_atom = "%s:%s" % \
+                               (portage.cpv_getkey(self.cpv), self.metadata["SLOT"])
+               return self._slot_atom
+
        @property
        def digraph_node(self):
                if self._digraph_node is None:
@@ -1079,8 +1087,8 @@ class depgraph(object):
                self.pkgsettings = {}
                # Maps cpv to digraph node for all nodes added to the graph.
                self.pkg_node_map = {}
-               # Maps slot atom to digraph node for all nodes added to the graph.
-               self._slot_node_map = {}
+               # Maps slot atom to package for each Package added to the graph.
+               self._slot_pkg_map = {}
                # Maps nodes to the reasons they were selected for reinstallation.
                self._reinstall_nodes = {}
                self.mydbapi = {}
@@ -1100,7 +1108,7 @@ class depgraph(object):
                        self.pkgsettings[myroot] = portage.config(
                                clone=self.trees[myroot]["vartree"].settings)
                        self.pkg_node_map[myroot] = {}
-                       self._slot_node_map[myroot] = {}
+                       self._slot_pkg_map[myroot] = {}
                        vardb = self.trees[myroot]["vartree"].dbapi
                        self.roots[myroot] = RootConfig(self.trees[myroot])
                        # This fakedbapi instance will model the state that the vdb will
@@ -1366,8 +1374,9 @@ class depgraph(object):
                                # are being merged in that case.
                                priority.rebuild = True
 
-                       existing_node = self._slot_node_map[myroot].get(
-                               slot_atom, None)
+                       existing_node = self._slot_pkg_map[myroot].get(slot_atom)
+                       if existing_node:
+                               existing_node = existing_node.digraph_node
                        slot_collision = False
                        if existing_node:
                                e_type, myroot, e_cpv, e_status = existing_node
@@ -1413,8 +1422,8 @@ class depgraph(object):
                                # function despite collisions.
                        else:
                                self.mydbapi[myroot].cpv_inject(mykey, metadata=metadata)
-                               self._slot_node_map[myroot][slot_atom] = jbigkey
-                               self.pkg_node_map[myroot][mykey] = jbigkey
+                               self._slot_pkg_map[pkg.root][pkg.slot_atom] = pkg
+                               self.pkg_node_map[pkg.root][pkg.cpv] = pkg.digraph_node
 
                        if rev_dep and myparent:
                                self.digraph.addnode(myparent, jbigkey,
@@ -2050,26 +2059,6 @@ class depgraph(object):
                        print xfrom
                print
 
-       def _get_existing_pkg(self, root, slot_atom):
-               """
-               @rtype: Package
-               @returns: An existing Package instance added to the graph for the
-                       given SLOT, or None if no matching package has been added yet.
-               """
-               existing_node = self._slot_node_map[root].get(slot_atom)
-               if not existing_node:
-                       return None
-               e_type, root, e_cpv, e_status = existing_node
-               metadata = dict(izip(self._mydbapi_keys,
-                       self.mydbapi[root].aux_get(e_cpv, self._mydbapi_keys)))
-               e_installed = e_type == "installed"
-               e_built = e_type != "ebuild"
-               e_onlydeps = not e_installed and \
-                       e_status == "nomerge"
-               return Package(cpv=e_cpv, built=e_built,
-                       installed=e_installed, type_name=e_type,
-                       metadata=metadata, onlydeps=e_onlydeps, root=root)
-
        def _select_package(self, root, atom, onlydeps=False):
                pkgsettings = self.pkgsettings[root]
                dbs = self._filtered_trees[root]["dbs"]
@@ -2150,7 +2139,7 @@ class depgraph(object):
                                        if find_existing_node:
                                                slot_atom = "%s:%s" % (
                                                        portage.cpv_getkey(cpv), metadata["SLOT"])
-                                               e_pkg = self._get_existing_pkg(root, slot_atom)
+                                               e_pkg = self._slot_pkg_map[root].get(slot_atom)
                                                if not e_pkg:
                                                        break
                                                cpv_slot = "%s:%s" % \
@@ -2273,11 +2262,9 @@ class depgraph(object):
                        myslots = {}
                        modified_slots[myroot] = myslots
                        final_db = self.mydbapi[myroot]
-                       slot_node_map = self._slot_node_map[myroot]
-                       for slot_atom, mynode in slot_node_map.iteritems():
-                               mytype, myroot, mycpv, mystatus = mynode
-                               if mystatus == "merge":
-                                       myslots[slot_atom] = mycpv
+                       for pkg in self._slot_pkg_map[myroot].itervalues():
+                               if not (pkg.installed or pkg.onlydeps):
+                                       myslots[pkg.slot_atom] = pkg.cpv
 
                #if "deep" in self.myparams:
                if True: