MergeProcess: separate unmerge output from merge
authorZac Medico <zmedico@gentoo.org>
Fri, 25 Mar 2011 09:29:06 +0000 (02:29 -0700)
committerZac Medico <zmedico@gentoo.org>
Fri, 25 Mar 2011 09:29:06 +0000 (02:29 -0700)
The unmerge output has been mixed together with the merge output since
commit 7535cabdf2fab76fc55df83643157613dfd66be9 because
dblink._scheduler was set to None. Now it's fixed to produce separate
logs like it used to.

pym/portage/dbapi/_MergeProcess.py
pym/portage/dbapi/vartree.py
pym/portage/package/ebuild/_config/special_env_vars.py

index 8f61a2fde0a6d7bc0604efee4953e203462c5f54..5caeef372c544e207aee2411bdcd746dd9efd02b 100644 (file)
@@ -92,6 +92,10 @@ class MergeProcess(SpawnProcess):
                # already be opened by the parent process, so we set the
                # "subprocess" value for use in conditional logging code
                # involving PORTAGE_LOG_FILE.
+               if self.settings.get("PORTAGE_BACKGROUND") == "1":
+                       # unmerge phases have separate logs
+                       self.settings["PORTAGE_BACKGROUND_UNMERGE"] = "1"
+                       self.settings.backup_changes("PORTAGE_BACKGROUND_UNMERGE")
                self.settings["PORTAGE_BACKGROUND"] = "subprocess"
                self.settings.backup_changes("PORTAGE_BACKGROUND")
 
index a58521a367b6ac87621f9c2eea486eae9c2b49c0..8203de85e9df9beb27bde5499051913b23acd35f 100644 (file)
@@ -56,6 +56,7 @@ from portage import _unicode_encode
 
 from _emerge.AsynchronousLock import AsynchronousLock
 from _emerge.EbuildBuildDir import EbuildBuildDir
+from _emerge.EbuildPhase import EbuildPhase
 from _emerge.PollScheduler import PollScheduler
 from _emerge.MiscFunctionsProcess import MiscFunctionsProcess
 
@@ -1487,6 +1488,18 @@ class dblink(object):
                                " method is now unused.",
                                DeprecationWarning, stacklevel=2)
 
+               background = False
+               if self._scheduler is None:
+                       # We create a scheduler instance and use it to
+                       # log unmerge output separately from merge output.
+                       self._scheduler = PollScheduler().sched_iface
+               if self.settings.get("PORTAGE_BACKGROUND_UNMERGE") == "1":
+                       self.settings["PORTAGE_BACKGROUND"] = "1"
+                       self.settings.backup_changes("PORTAGE_BACKGROUND")
+                       background = True
+               else:
+                       self.settings.pop("PORTAGE_BACKGROUND", None)
+
                self.vartree.dbapi._bump_mtime(self.mycpv)
                showMessage = self._display_merge
                if self.vartree.dbapi._categories is not None:
@@ -1549,18 +1562,17 @@ class dblink(object):
                try:
                        if myebuildpath:
                                builddir_lock = EbuildBuildDir(
-                                       scheduler=(scheduler or PollScheduler().sched_iface),
+                                       scheduler=scheduler,
                                        settings=self.settings)
                                builddir_lock.lock()
 
                                prepare_build_dirs(settings=self.settings, cleanup=True)
                                log_path = self.settings.get("PORTAGE_LOG_FILE")
-
-                               if scheduler is None:
-                                       retval = _spawn_phase('prerm', self.settings)
-                               else:
-                                       retval = scheduler.dblinkEbuildPhase(
-                                               self, self.vartree.dbapi, myebuildpath, ebuild_phase)
+                               phase = EbuildPhase(background=background,
+                                       phase=ebuild_phase, scheduler=scheduler,
+                                       settings=self.settings)
+                               phase.start()
+                               retval = phase.wait()
 
                                # XXX: Decide how to handle failures here.
                                if retval != os.EX_OK:
@@ -1582,11 +1594,11 @@ class dblink(object):
 
                        if myebuildpath:
                                ebuild_phase = "postrm"
-                               if scheduler is None:
-                                       retval = _spawn_phase(ebuild_phase, self.settings)
-                               else:
-                                       retval = scheduler.dblinkEbuildPhase(
-                                               self, self.vartree.dbapi, myebuildpath, ebuild_phase)
+                               phase = EbuildPhase(background=background,
+                                       phase=ebuild_phase, scheduler=scheduler,
+                                       settings=self.settings)
+                               phase.start()
+                               retval = phase.wait()
 
                                # XXX: Decide how to handle failures here.
                                if retval != os.EX_OK:
@@ -1678,12 +1690,11 @@ class dblink(object):
                                                        self.pkg + ".ebuild")
                                                doebuild_environment(myebuildpath, "cleanrm",
                                                        settings=self.settings, db=self.vartree.dbapi)
-                                               if scheduler is None:
-                                                       _spawn_phase("cleanrm", self.settings)
-                                               else:
-                                                       scheduler.dblinkEbuildPhase(
-                                                               self, self.vartree.dbapi,
-                                                               myebuildpath, "cleanrm")
+                                               phase = EbuildPhase(background=background,
+                                                       phase="cleanrm", scheduler=scheduler,
+                                                       settings=self.settings)
+                                               phase.start()
+                                               retval = phase.wait()
                                finally:
                                        if builddir_lock is not None:
                                                builddir_lock.unlock()
@@ -1726,11 +1737,18 @@ class dblink(object):
        def _display_merge(self, msg, level=0, noiselevel=0):
                if not self._verbose and noiselevel >= 0 and level < logging.WARN:
                        return
-               if self._scheduler is not None:
-                       self._scheduler.dblinkDisplayMerge(self, msg,
-                               level=level, noiselevel=noiselevel)
-                       return
-               writemsg_level(msg, level=level, noiselevel=noiselevel)
+               if self._scheduler is None:
+                       writemsg_level(msg, level=level, noiselevel=noiselevel)
+               else:
+                       log_path = self.settings.get("PORTAGE_LOG_FILE")
+                       background = self.settings.get("PORTAGE_BACKGROUND") == "1"
+
+                       if log_path is None:
+                               if not (background and level < logging.WARN):
+                                       writemsg_level(msg, level=level, noiselevel=noiselevel)
+                       else:
+                               self._scheduler.output(msg,
+                                       background=background, log_path=log_path)
 
        def _unmerge_pkgfiles(self, pkgfiles, others_in_slot):
                """
@@ -1748,7 +1766,6 @@ class dblink(object):
                os = _os_merge
                perf_md5 = perform_md5
                showMessage = self._display_merge
-               scheduler = self._scheduler
 
                if not pkgfiles:
                        showMessage(_("No package files given... Grabbing a set.\n"))
@@ -1849,10 +1866,6 @@ class dblink(object):
 
                        for i, objkey in enumerate(mykeys):
 
-                               if scheduler is not None and \
-                                       0 == i % self._file_merge_yield_interval:
-                                       scheduler.scheduleYield()
-
                                obj = normalize_path(objkey)
                                if os is _os_merge:
                                        try:
index 561de9cf46a013dab8d7745505074465d0bdfd70..6a196cfca2c4eada9ae1ccddfc061ce3a72d0182 100644 (file)
@@ -137,7 +137,7 @@ environ_filter += [
        "FETCHCOMMAND_HTTP", "FETCHCOMMAND_HTTPS",
        "FETCHCOMMAND_RSYNC", "FETCHCOMMAND_SFTP",
        "GENTOO_MIRRORS", "NOCONFMEM", "O",
-       "PORTAGE_BACKGROUND",
+       "PORTAGE_BACKGROUND", "PORTAGE_BACKGROUND_UNMERGE",
        "PORTAGE_BINHOST_CHUNKSIZE", "PORTAGE_BUILDIR_LOCKED", "PORTAGE_CALLER",
        "PORTAGE_ELOG_CLASSES",
        "PORTAGE_ELOG_MAILFROM", "PORTAGE_ELOG_MAILSUBJECT",