FakeVartree: split _apply_dynamic_deps method
authorZac Medico <zmedico@gentoo.org>
Wed, 2 Jan 2013 02:42:18 +0000 (18:42 -0800)
committerZac Medico <zmedico@gentoo.org>
Wed, 2 Jan 2013 02:52:13 +0000 (18:52 -0800)
This will eventually be used for parallelization of aux_get/regen
processes.

pym/_emerge/FakeVartree.py

index a0a506e36f3a48948ccf88333b92b952146741ba..31ff65c2b04f0ba689213aee5ef2415d951bb48e 100644 (file)
@@ -33,6 +33,9 @@ class FakeVardbapi(PackageVirtualDbapi):
                        path =os.path.join(path, filename)
                return path
 
+class _DynamicDepsNotApplicable(Exception):
+       pass
+
 class FakeVartree(vartree):
        """This is implements an in-memory copy of a vartree instance that provides
        all the interfaces required for use by the depgraph.  The vardb is locked
@@ -102,28 +105,30 @@ class FakeVartree(vartree):
                        self._aux_get_wrapper(cpv, [])
                return matches
 
-       def _aux_get_wrapper(self, pkg, wants, myrepo=None):
-               if pkg in self._aux_get_history:
-                       return self._aux_get(pkg, wants)
-               self._aux_get_history.add(pkg)
-               # We need to check the EAPI, and this also raises
-               # a KeyError to the caller if appropriate.
-               pkg_obj = self.dbapi._cpv_map[pkg]
-               installed_eapi = pkg_obj.eapi
-               eapi_attrs = _get_eapi_attrs(installed_eapi)
-               built_slot_operator_atoms = None
-
-               if eapi_attrs.slot_operator and not self._ignore_built_slot_operator_deps:
-                       try:
-                               built_slot_operator_atoms = find_built_slot_operator_atoms(pkg_obj)
-                       except InvalidDependString:
-                               pass
+       def _aux_get_wrapper(self, cpv, wants, myrepo=None):
+               if cpv in self._aux_get_history:
+                       return self._aux_get(cpv, wants)
+               self._aux_get_history.add(cpv)
+
+               # This raises a KeyError to the caller if appropriate.
+               pkg = self.dbapi._cpv_map[cpv]
 
                try:
-                       # Use the live ebuild metadata if possible.
                        live_metadata = dict(zip(self._portdb_keys,
-                               self._portdb.aux_get(pkg, self._portdb_keys,
-                               myrepo=pkg_obj.repo)))
+                               self._portdb.aux_get(cpv, self._portdb_keys,
+                               myrepo=pkg.repo)))
+               except (KeyError, portage.exception.PortageException):
+                       live_metadata = None
+
+               self._apply_dynamic_deps(pkg, live_metadata)
+
+               return self._aux_get(cpv, wants)
+
+       def _apply_dynamic_deps(self, pkg, live_metadata):
+
+               try:
+                       if live_metadata is None:
+                               raise _DynamicDepsNotApplicable()
                        # Use the metadata from the installed instance if the EAPI
                        # of either instance is unsupported, since if the installed
                        # instance has an unsupported or corrupt EAPI then we don't
@@ -133,26 +138,34 @@ class FakeVartree(vartree):
                        # order to respect dep updates without revision bump or EAPI
                        # bump, as in bug #368725.
                        if not (portage.eapi_is_supported(live_metadata["EAPI"]) and \
-                               portage.eapi_is_supported(installed_eapi)):
-                               raise KeyError(pkg)
+                               portage.eapi_is_supported(pkg.eapi)):
+                               raise _DynamicDepsNotApplicable()
 
                        # preserve built slot/sub-slot := operator deps
+                       built_slot_operator_atoms = None
+                       if not self._ignore_built_slot_operator_deps and \
+                               _get_eapi_attrs(pkg.eapi).slot_operator:
+                               try:
+                                       built_slot_operator_atoms = \
+                                               find_built_slot_operator_atoms(pkg)
+                               except InvalidDependString:
+                                       pass
+
                        if built_slot_operator_atoms:
                                live_eapi_attrs = _get_eapi_attrs(live_metadata["EAPI"])
                                if not live_eapi_attrs.slot_operator:
-                                       raise KeyError(pkg)
+                                       raise _DynamicDepsNotApplicable()
                                for k, v in built_slot_operator_atoms.items():
                                        live_metadata[k] += (" " +
                                                " ".join(_unicode(atom) for atom in v))
 
-                       self.dbapi.aux_update(pkg, live_metadata)
-               except (KeyError, portage.exception.PortageException):
+                       self.dbapi.aux_update(pkg.cpv, live_metadata)
+               except _DynamicDepsNotApplicable:
                        if self._global_updates is None:
                                self._global_updates = \
                                        grab_global_updates(self._portdb)
                        perform_global_updates(
-                               pkg, self.dbapi, self._global_updates)
-               return self._aux_get(pkg, wants)
+                               pkg.cpv, self.dbapi, self._global_updates)
 
        def cpv_discard(self, pkg):
                """