Make _dep_check_composite_db match() return multiple slots so that
authorZac Medico <zmedico@gentoo.org>
Sun, 13 Apr 2008 18:01:35 +0000 (18:01 -0000)
committerZac Medico <zmedico@gentoo.org>
Sun, 13 Apr 2008 18:01:35 +0000 (18:01 -0000)
it behaves more like other dbapi instances would, and also make it
inherit from dbapi.

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

pym/_emerge/__init__.py

index 74bdecac5edda6c06576e02ca520a389f0b38f26..dcc0461bd8a5c0134b80a1e270d5a89fc38bfcd2 100644 (file)
@@ -4328,7 +4328,7 @@ class depgraph(object):
                        fakedb[myroot].cpv_inject(pkg)
                        self.spinner.update()
 
-       class _dep_check_composite_db(object):
+       class _dep_check_composite_db(portage.dbapi):
                """
                A dbapi-like interface that is optimized for use in dep_check() calls.
                This is built on top of the existing depgraph package selection logic.
@@ -4337,6 +4337,7 @@ class depgraph(object):
                via dep_check().
                """
                def __init__(self, depgraph, root):
+                       portage.dbapi.__init__(self)
                        self._depgraph = depgraph
                        self._root = root
                        self._match_cache = {}
@@ -4353,21 +4354,41 @@ class depgraph(object):
                        if not pkg:
                                ret = []
                        else:
-                               if pkg.installed and "selective" not in self._depgraph.myparams:
-                                       try:
-                                               arg = self._depgraph._iter_atoms_for_pkg(pkg).next()
-                                       except (StopIteration, portage.exception.InvalidDependString):
-                                               arg = None
-                                       if arg:
-                                               ret = []
-                               if ret is None and pkg.installed and \
-                                       not visible(self._depgraph.pkgsettings[pkg.root], pkg):
-                                       # For disjunctive || deps, this will cause alternative
-                                       # atoms or packages to be selected if available.
-                                       ret = []
-                               if ret is None:
+                               # Return the highest available from select_package() as well as
+                               # any matching slots in the graph db.
+                               slots = set()
+                               slots.add(pkg.metadata["SLOT"])
+                               atom_cp = portage.dep_getkey(atom)
+                               if atom_cp == pkg.cp:
+                                       graph_db = self._depgraph.mydbapi[self._root]
+                                       for cpv in graph_db.match(atom):
+                                               if portage.cpv_getkey(cpv) != pkg.cp:
+                                                       continue
+                                               slots.add(graph_db.aux_get(cpv, ["SLOT"])[0])
+                               ret = []
+                               slots.remove(pkg.metadata["SLOT"])
+                               self._cpv_pkg_map[pkg.cpv] = pkg
+                               ret.append(pkg.cpv)
+                               while slots:
+                                       slot_atom = "%s:%s" % (atom_cp, slots.pop())
+                                       pkg, existing = self._depgraph._select_package(
+                                               self._root, slot_atom)
+                                       if not pkg:
+                                               continue
+                                       if pkg.installed and "selective" not in self._depgraph.myparams:
+                                               try:
+                                                       arg = self._depgraph._iter_atoms_for_pkg(pkg).next()
+                                               except (StopIteration, portage.exception.InvalidDependString):
+                                                       arg = None
+                                               if arg:
+                                                       continue
+                                       if pkg.installed and \
+                                               not visible(self._depgraph.pkgsettings[pkg.root], pkg):
+                                               continue
                                        self._cpv_pkg_map[pkg.cpv] = pkg
-                                       ret = [pkg.cpv]
+                                       ret.append(pkg.cpv)
+                               if ret:
+                                       self._cpv_sort_ascending(ret)
                        self._match_cache[orig_atom] = ret
                        return ret[:]