Add a "consumer" keyword parameter to the MetadataRegen constructor which
authorZac Medico <zmedico@gentoo.org>
Thu, 30 Apr 2009 06:50:07 +0000 (06:50 -0000)
committerZac Medico <zmedico@gentoo.org>
Thu, 30 Apr 2009 06:50:07 +0000 (06: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). (trunk r13256)

svn path=/main/branches/2.1.6/; revision=13435

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

index 15739d7388166d0cf75ba6f21a5c778c271139eb..de8b01cabea9c8d388df2a19d92a62e594abe5ef 100644 (file)
@@ -3005,7 +3005,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",)
@@ -3110,8 +3110,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):
 
@@ -11557,7 +11558,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
@@ -11567,6 +11569,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
@@ -11597,6 +11600,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)
@@ -11605,11 +11609,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):
 
@@ -11684,7 +11696,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):