Add a "consumer" keyword parameter to the MetadataRegen constructor which
authorZac Medico <zmedico@gentoo.org>
Tue, 31 Mar 2009 05:50:15 +0000 (05:50 -0000)
committerZac Medico <zmedico@gentoo.org>
Tue, 31 Mar 2009 05:50:15 +0000 (05:50 -0000)
can be used to pass in a callback that is called for each ebuild that is
processed (allowing access to the ebuild metadata).

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

pym/_emerge/__init__.py
pym/portage/dbapi/porttree.py

index 611ac064ca1398aa974690d1ed0f2dddc1d47828..e325f1f25ee1b9408c80bb757452ffbd923fde26 100644 (file)
@@ -3024,7 +3024,7 @@ class EbuildMetadataPhase(SubProcess):
        """
 
        __slots__ = ("cpv", "ebuild_path", "fd_pipes", "metadata_callback",
-               "ebuild_mtime", "portdb", "repo_path", "settings") + \
+               "ebuild_mtime", "metadata", "portdb", "repo_path", "settings") + \
                ("_raw_metadata",)
 
        _file_names = ("ebuild",)
@@ -3129,8 +3129,9 @@ class EbuildMetadataPhase(SubProcess):
                                self.returncode = 1
                        else:
                                metadata = izip(portage.auxdbkeys, metadata_lines)
-                               self.metadata_callback(self.cpv, self.ebuild_path,
-                                       self.repo_path, metadata, self.ebuild_mtime)
+                               self.metadata = self.metadata_callback(self.cpv,
+                                       self.ebuild_path, self.repo_path, metadata,
+                                       self.ebuild_mtime)
 
 class EbuildProcess(SpawnProcess):
 
@@ -11573,7 +11574,8 @@ class Scheduler(PollScheduler):
 
 class MetadataRegen(PollScheduler):
 
-       def __init__(self, portdb, cp_iter=None, max_jobs=None, max_load=None):
+       def __init__(self, portdb, cp_iter=None, consumer=None,
+               max_jobs=None, max_load=None):
                PollScheduler.__init__(self)
                self._portdb = portdb
                self._global_cleanse = False
@@ -11583,6 +11585,7 @@ class MetadataRegen(PollScheduler):
                        # iterate over every single cp.
                        self._global_cleanse = True
                self._cp_iter = cp_iter
+               self._consumer = consumer
 
                if max_jobs is None:
                        max_jobs = 1
@@ -11613,6 +11616,7 @@ class MetadataRegen(PollScheduler):
                portdb = self._portdb
                valid_pkgs = self._valid_pkgs
                cp_set = self._cp_set
+               consumer = self._consumer
 
                for cp in self._cp_iter:
                        cp_set.add(cp)
@@ -11621,11 +11625,19 @@ class MetadataRegen(PollScheduler):
                        for cpv in cpv_list:
                                valid_pkgs.add(cpv)
                                ebuild_path, repo_path = portdb.findname2(cpv)
-                               metadata_process = portdb._metadata_process(
+                               metadata, st, emtime = portdb._pull_valid_cache(
                                        cpv, ebuild_path, repo_path)
-                               if metadata_process is None:
+                               if metadata is not None:
+                                       if consumer is not None:
+                                               consumer(cpv, ebuild_path,
+                                                       repo_path, metadata)
                                        continue
-                               yield metadata_process
+
+                               yield EbuildMetadataPhase(cpv=cpv, ebuild_path=ebuild_path,
+                                       ebuild_mtime=emtime,
+                                       metadata_callback=portdb._metadata_callback,
+                                       portdb=portdb, repo_path=repo_path,
+                                       settings=portdb.doebuild_settings)
 
        def run(self):
 
@@ -11700,7 +11712,13 @@ class MetadataRegen(PollScheduler):
 
        def _metadata_exit(self, metadata_process):
                self._jobs -= 1
-               if metadata_process.returncode != os.EX_OK:
+               if metadata_process.returncode == os.EX_OK:
+                       if self._consumer is not None:
+                               self._consumer(metadata_process.cpv,
+                                       metadata_process.ebuild_path,
+                                       metadata_process.repo_path,
+                                       metadata_process.metadata)
+               else:
                        self.returncode = 1
                        self._error_count += 1
                        self._valid_pkgs.discard(metadata_process.cpv)
index c94a2965d0fe87e4d249496225203a9582eec8b1..9d4b1523d482f5e52ab16fedf44783728eab260f 100644 (file)
@@ -349,6 +349,7 @@ class portdbapi(dbapi):
                        metadata["EAPI"] = "-" + eapi.lstrip("-")
 
                self.auxdb[repo_path][cpv] = metadata
+               return metadata
 
        def _pull_valid_cache(self, cpv, ebuild_path, repo_path):