During the post src_install QA checks, log to a temporary file
authorZac Medico <zmedico@gentoo.org>
Sun, 22 Aug 2010 22:25:17 +0000 (15:25 -0700)
committerZac Medico <zmedico@gentoo.org>
Sun, 22 Aug 2010 22:25:17 +0000 (15:25 -0700)
since the code we are running reads PORTAGE_LOG_FILE, and we
want to avoid annoying "gzip: unexpected end of file" messages
when FEATURES=compress-build-logs is enabled.

pym/_emerge/EbuildPhase.py
pym/_emerge/MiscFunctionsProcess.py

index d2d4dce3a15878598bfcec6874b73d1ef7e0f15c..d0a218b179dfe2ecb6dd3e3c1b77f2cf643f7440 100644 (file)
@@ -1,11 +1,14 @@
 # Copyright 1999-2010 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
+import gzip
+import tempfile
+
 from _emerge.BinpkgEnvExtractor import BinpkgEnvExtractor
 from _emerge.MiscFunctionsProcess import MiscFunctionsProcess
 from _emerge.EbuildProcess import EbuildProcess
 from _emerge.CompositeTask import CompositeTask
-from portage.util import writemsg, writemsg_stdout
+from portage.util import writemsg
 import portage
 portage.proxy.lazyimport.lazyimport(globals(),
        'portage.package.ebuild.doebuild:_check_build_log,' + \
@@ -17,7 +20,6 @@ from portage import os
 from portage import _encodings
 from portage import _unicode_decode
 from portage import _unicode_encode
-import codecs
 
 class EbuildPhase(CompositeTask):
 
@@ -100,8 +102,16 @@ class EbuildPhase(CompositeTask):
 
                post_phase_cmds = _post_phase_cmds.get(self.phase)
                if post_phase_cmds is not None:
+                       logfile = settings.get("PORTAGE_LOG_FILE")
+                       if logfile is not None and self.phase in ("install",):
+                               # Log to a temporary file, since the code we are running
+                               # reads PORTAGE_LOG_FILE for QA checks, and we want to
+                               # avoid annoying "gzip: unexpected end of file" messages
+                               # when FEATURES=compress-build-logs is enabled.
+                               fd, logfile = tempfile.mkstemp()
+                               os.close(fd)
                        post_phase = MiscFunctionsProcess(background=self.background,
-                               commands=post_phase_cmds, phase=self.phase,
+                               commands=post_phase_cmds, logfile=logfile, phase=self.phase,
                                scheduler=self.scheduler, settings=settings)
                        self._start_task(post_phase, self._post_phase_exit)
                        return
@@ -111,6 +121,16 @@ class EbuildPhase(CompositeTask):
                self.wait()
 
        def _post_phase_exit(self, post_phase):
+
+               self._assert_current(post_phase)
+
+               log_path = self.settings.get("PORTAGE_LOG_FILE")
+               if post_phase.logfile is not None and \
+                       post_phase.logfile != log_path:
+                       # We were logging to a temp file (see above), so append
+                       # temp file to main log and remove temp file.
+                       self._append_temp_log(post_phase.logfile, log_path)
+
                if self._final_exit(post_phase) != os.EX_OK:
                        writemsg("!!! post %s failed; exiting.\n" % self.phase,
                                noiselevel=-1)
@@ -120,6 +140,31 @@ class EbuildPhase(CompositeTask):
                self.wait()
                return
 
+       def _append_temp_log(self, temp_log, log_path):
+
+               temp_file = open(_unicode_encode(temp_log,
+                       encoding=_encodings['fs'], errors='strict'), 'rb')
+
+               log_file = self._open_log(log_path)
+
+               for line in temp_file:
+                       log_file.write(line)
+
+               temp_file.close()
+               log_file.close()
+               os.unlink(temp_log)
+
+       def _open_log(self, log_path):
+
+               f = open(_unicode_encode(log_path,
+                       encoding=_encodings['fs'], errors='strict'),
+                       mode='ab')
+
+               if log_path.endswith('.gz'):
+                       f =  gzip.GzipFile(filename='', mode='ab', fileobj=f)
+
+               return f
+
        def _die_hooks(self):
                self.returncode = None
                phase = 'die_hooks'
index d7119037e949803688fb4f6c739765af8cc3f5a9..ad8cefcfd69b27102accb60ba7d585791405f257 100644 (file)
@@ -22,7 +22,8 @@ class MiscFunctionsProcess(AbstractEbuildProcess):
                        os.path.basename(portage.const.MISC_SH_BINARY))
 
                self.args = [portage._shell_quote(misc_sh_binary)] + self.commands
-               self.logfile = settings.get("PORTAGE_LOG_FILE")
+               if self.logfile is None:
+                       self.logfile = settings.get("PORTAGE_LOG_FILE")
 
                AbstractEbuildProcess._start(self)