Factor duplicate code out of depgraph._add_pkg and _pop_disjunction.
authorZac Medico <zmedico@gentoo.org>
Sat, 20 Jun 2009 19:16:51 +0000 (19:16 -0000)
committerZac Medico <zmedico@gentoo.org>
Sat, 20 Jun 2009 19:16:51 +0000 (19:16 -0000)
svn path=/main/trunk/; revision=13657

pym/_emerge/__init__.py

index acf5e46c1fd491636b8c49ee12150c2c40e7f31f..189396deea8d57f0458ee5125854512e31386be3 100644 (file)
@@ -5394,41 +5394,11 @@ class depgraph(object):
 
                                dep_string = portage.dep.paren_enclose(dep_string)
 
-                               vardb = self.roots[dep_root].trees["vartree"].dbapi
-                               try:
-                                       selected_atoms = self._select_atoms(dep_root,
-                                               dep_string, myuse=myuse, parent=pkg, strict=strict,
-                                               priority=dep_priority)
-                               except portage.exception.InvalidDependString, e:
-                                       show_invalid_depstring_notice(jbigkey, dep_string, str(e))
+                               if not self._add_pkg_dep_string(
+                                       pkg, dep_root, dep_priority, dep_string,
+                                       allow_unsatisfied):
                                        return 0
-                               if debug:
-                                       print "Candidates:", selected_atoms
-
-                               for atom in selected_atoms:
-                                       try:
-
-                                               atom = portage.dep.Atom(atom)
-
-                                               mypriority = dep_priority.copy()
-                                               if not atom.blocker and vardb.match(atom):
-                                                       mypriority.satisfied = True
 
-                                               if not self._add_dep(Dependency(atom=atom,
-                                                       blocker=atom.blocker, depth=depth, parent=pkg,
-                                                       priority=mypriority, root=dep_root),
-                                                       allow_unsatisfied=allow_unsatisfied):
-                                                       return 0
-
-                                       except portage.exception.InvalidAtom, e:
-                                               show_invalid_depstring_notice(
-                                                       pkg, dep_string, str(e))
-                                               del e
-                                               if not pkg.installed:
-                                                       return 0
-
-                               if debug:
-                                       print "Exiting...", jbigkey
                except portage.exception.AmbiguousPackageName, e:
                        pkgs = e.args[0]
                        portage.writemsg("\n\n!!! An atom in the dependencies " + \
@@ -5452,56 +5422,11 @@ class depgraph(object):
                        portage.dep._dep_check_strict = True
                return 1
 
-       def _queue_disjunctive_deps(self, pkg, dep_root, dep_priority, dep_struct):
-               """
-               Queue disjunctive (virtual and ||) deps in self._dep_disjunctive_stack.
-               Yields non-disjunctive deps. Raises InvalidDependString when 
-               necessary.
-               """
-               i = 0
-               while i < len(dep_struct):
-                       x = dep_struct[i]
-                       if isinstance(x, list):
-                               for y in self._queue_disjunctive_deps(
-                                       pkg, dep_root, dep_priority, x):
-                                       yield y
-                       elif x == "||":
-                               self._queue_disjunction(pkg, dep_root, dep_priority,
-                                       [ x, dep_struct[ i + 1 ] ] )
-                               i += 1
-                       else:
-                               try:
-                                       x = portage.dep.Atom(x)
-                               except portage.exception.InvalidAtom:
-                                       if not pkg.installed:
-                                               raise portage.exception.InvalidDependString(
-                                                       "invalid atom: '%s'" % x)
-                               else:
-                                       # Note: Eventually this will check for PROPERTIES=virtual
-                                       # or whatever other metadata gets implemented for this
-                                       # purpose.
-                                       if x.cp.startswith('virtual/'):
-                                               self._queue_disjunction( pkg, dep_root,
-                                                       dep_priority, [ str(x) ] )
-                                       else:
-                                               yield str(x)
-                       i += 1
-
-       def _queue_disjunction(self, pkg, dep_root, dep_priority, dep_struct):
-               self._dep_disjunctive_stack.append(
-                       (pkg, dep_root, dep_priority, dep_struct))
-
-       def _pop_disjunction(self, allow_unsatisfied):
-               """
-               Pop one disjunctive dep from self._dep_disjunctive_stack, and use it to
-               populate self._dep_stack.
-               """
-               pkg, dep_root, dep_priority, dep_struct = \
-                       self._dep_disjunctive_stack.pop()
+       def _add_pkg_dep_string(self, pkg, dep_root, dep_priority, dep_string,
+               allow_unsatisfied):
                depth = pkg.depth + 1
                debug = "--debug" in self.myopts
                strict = pkg.type_name != "installed"
-               dep_string = portage.dep.paren_enclose(dep_struct)
 
                if debug:
                        print
@@ -5552,6 +5477,58 @@ class depgraph(object):
 
                return 1
 
+       def _queue_disjunctive_deps(self, pkg, dep_root, dep_priority, dep_struct):
+               """
+               Queue disjunctive (virtual and ||) deps in self._dep_disjunctive_stack.
+               Yields non-disjunctive deps. Raises InvalidDependString when 
+               necessary.
+               """
+               i = 0
+               while i < len(dep_struct):
+                       x = dep_struct[i]
+                       if isinstance(x, list):
+                               for y in self._queue_disjunctive_deps(
+                                       pkg, dep_root, dep_priority, x):
+                                       yield y
+                       elif x == "||":
+                               self._queue_disjunction(pkg, dep_root, dep_priority,
+                                       [ x, dep_struct[ i + 1 ] ] )
+                               i += 1
+                       else:
+                               try:
+                                       x = portage.dep.Atom(x)
+                               except portage.exception.InvalidAtom:
+                                       if not pkg.installed:
+                                               raise portage.exception.InvalidDependString(
+                                                       "invalid atom: '%s'" % x)
+                               else:
+                                       # Note: Eventually this will check for PROPERTIES=virtual
+                                       # or whatever other metadata gets implemented for this
+                                       # purpose.
+                                       if x.cp.startswith('virtual/'):
+                                               self._queue_disjunction( pkg, dep_root,
+                                                       dep_priority, [ str(x) ] )
+                                       else:
+                                               yield str(x)
+                       i += 1
+
+       def _queue_disjunction(self, pkg, dep_root, dep_priority, dep_struct):
+               self._dep_disjunctive_stack.append(
+                       (pkg, dep_root, dep_priority, dep_struct))
+
+       def _pop_disjunction(self, allow_unsatisfied):
+               """
+               Pop one disjunctive dep from self._dep_disjunctive_stack, and use it to
+               populate self._dep_stack.
+               """
+               pkg, dep_root, dep_priority, dep_struct = \
+                       self._dep_disjunctive_stack.pop()
+               dep_string = portage.dep.paren_enclose(dep_struct)
+               if not self._add_pkg_dep_string(
+                       pkg, dep_root, dep_priority, dep_string, allow_unsatisfied):
+                       return 0
+               return 1
+
        def _priority(self, **kwargs):
                if "remove" in self.myparams:
                        priority_constructor = UnmergeDepPriority