summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2008-07-17 23:53:49 +0000
committerZac Medico <zmedico@gentoo.org>2008-07-17 23:53:49 +0000
commitf88ccbcd7f42c880e6f2c741d114ba049064f904 (patch)
tree15000ccfaf86246e7b9e9d82b5f860a63ca4481f
parentf202826c41db708712a1847c11f2298b1314b2d9 (diff)
downloadportage-f88ccbcd7f42c880e6f2c741d114ba049064f904.tar.gz
portage-f88ccbcd7f42c880e6f2c741d114ba049064f904.tar.bz2
portage-f88ccbcd7f42c880e6f2c741d114ba049064f904.zip
Redirect dblink elog messages from stdout to the log file when in background
mode. This is implemented by adding a new "out" parameter to the portage.elog.e* functions, which can be used to send output to an arbitary file instead of stdout. svn path=/main/trunk/; revision=11117
-rw-r--r--pym/_emerge/__init__.py24
-rw-r--r--pym/portage/dbapi/vartree.py21
-rw-r--r--pym/portage/elog/messages.py16
3 files changed, 48 insertions, 13 deletions
diff --git a/pym/_emerge/__init__.py b/pym/_emerge/__init__.py
index b6e942963..cb760e172 100644
--- a/pym/_emerge/__init__.py
+++ b/pym/_emerge/__init__.py
@@ -8465,8 +8465,9 @@ class Scheduler(PollScheduler):
_fetch_log = "/var/log/emerge-fetch.log"
class _iface_class(SlotObject):
- __slots__ = ("dblinkEbuildPhase", "dblinkDisplayMerge", "fetch",
- "register", "schedule", "scheduleYield", "unregister")
+ __slots__ = ("dblinkEbuildPhase", "dblinkDisplayMerge",
+ "dblinkElog", "fetch", "register", "schedule",
+ "scheduleYield", "unregister")
class _fetch_iface_class(SlotObject):
__slots__ = ("log_file", "schedule")
@@ -8534,6 +8535,7 @@ class Scheduler(PollScheduler):
self._sched_iface = self._iface_class(
dblinkEbuildPhase=self._dblink_ebuild_phase,
dblinkDisplayMerge=self._dblink_display_merge,
+ dblinkElog=self._dblink_elog,
fetch=fetch_iface, register=self._register,
schedule=self._schedule_wait, scheduleYield=self._schedule_yield,
unregister=self._unregister)
@@ -8728,6 +8730,24 @@ class Scheduler(PollScheduler):
finally:
f.close()
+ def _dblink_elog(self, pkg_dblink, phase, func, msgs):
+
+ log_path = pkg_dblink.settings.get("PORTAGE_LOG_FILE")
+ log_file = None
+ out = sys.stdout
+ background = self._max_jobs > 1
+
+ if background and log_path is not None:
+ log_file = open(log_path, 'a')
+ out = log_file
+
+ try:
+ for msg in msgs:
+ func(msg, phase=phase, key=pkg_dblink.mycpv, out=out)
+ finally:
+ if log_file is not None:
+ log_file.close()
+
def _dblink_display_merge(self, pkg_dblink, msg, level=0, noiselevel=0):
log_path = pkg_dblink.settings.get("PORTAGE_LOG_FILE")
background = self._max_jobs > 1
diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py
index a6cebaab4..0d6ae32eb 100644
--- a/pym/portage/dbapi/vartree.py
+++ b/pym/portage/dbapi/vartree.py
@@ -25,7 +25,6 @@ from portage import listdir, dep_expand, flatten, key_expand, \
abssymlink, movefile, _movefile, bsd_chflags, cpv_getkey
from portage.elog import elog_process
-from portage.elog.messages import ewarn
from portage.elog.filtering import filter_mergephases, filter_unmergephases
import os, re, sys, stat, errno, commands, copy, time, subprocess
@@ -1715,9 +1714,14 @@ class dblink(object):
"pkg_prerm() and pkg_postrm() removal " + \
"phases to be skipped entirely."
msg_lines.extend(wrap(msg, 72))
+
from portage.elog.messages import eerror
- for l in msg_lines:
- eerror(l, phase=ebuild_phase, key=self.mycpv)
+ if scheduler is None:
+ for l in msg_lines:
+ eerror(l, phase=ebuild_phase, key=self.mycpv)
+ else:
+ scheduler.dblinkElog(self,
+ ebuild_phase, eerror, msg_lines)
# process logs created during pre/postrm
elog_process(self.mycpv, self.settings, phasefilter=filter_unmergephases)
@@ -2391,6 +2395,7 @@ class dblink(object):
"""
showMessage = self._display_merge
+ scheduler = self._scheduler
srcroot = normalize_path(srcroot).rstrip(os.path.sep) + os.path.sep
destroot = normalize_path(destroot).rstrip(os.path.sep) + os.path.sep
@@ -2418,8 +2423,12 @@ class dblink(object):
from portage.elog.messages import eerror as _eerror
def eerror(lines):
- for l in lines:
- _eerror(l, phase="preinst", key=self.settings.mycpv)
+ if scheduler is None:
+ for l in lines:
+ _eerror(l, phase="preinst", key=self.settings.mycpv)
+ else:
+ scheduler.dblinkElog(self,
+ "preinst", _eerror, lines)
if slot != self.settings["SLOT"]:
showMessage("!!! WARNING: Expected SLOT='%s', got '%s'\n" % \
@@ -2636,8 +2645,6 @@ class dblink(object):
self.delete()
ensure_dirs(self.dbtmpdir)
- scheduler = self._scheduler
-
# run preinst script
if scheduler is None:
showMessage(">>> Merging %s to %s\n" % (self.mycpv, destroot))
diff --git a/pym/portage/elog/messages.py b/pym/portage/elog/messages.py
index 36116cc82..de736664c 100644
--- a/pym/portage/elog/messages.py
+++ b/pym/portage/elog/messages.py
@@ -8,6 +8,7 @@ from portage.const import EBUILD_PHASES
from portage.util import writemsg
import os
+import sys
def collect_ebuild_messages(path):
""" Collect elog messages generated by the bash logging function stored
@@ -66,7 +67,7 @@ def collect_ebuild_messages(path):
return logentries
_msgbuffer = {}
-def _elog_base(level, msg, phase="other", key=None, color=None):
+def _elog_base(level, msg, phase="other", key=None, color=None, out=None):
""" Backend for the other messaging functions, should not be called
directly.
"""
@@ -75,7 +76,14 @@ def _elog_base(level, msg, phase="other", key=None, color=None):
if color == None:
color = "GOOD"
- print colorize(color, " * ")+msg
+
+ formatted_msg = colorize(color, " * ") + msg + "\n"
+
+ if out is None:
+ sys.stdout.write(formatted_msg)
+ else:
+ out.write(formatted_msg)
+
if key not in _msgbuffer:
_msgbuffer[key] = {}
if phase not in _msgbuffer[key]:
@@ -108,11 +116,11 @@ _functions = { "einfo": ("INFO", "GOOD"),
}
def _make_msgfunction(level, color):
- def _elog(msg, phase="other", key=None):
+ def _elog(msg, phase="other", key=None, out=None):
""" Display and log a message assigned to the given key/cpv
(or unassigned if no key is given).
"""
- _elog_base(level, msg, phase=phase, key=key, color=color)
+ _elog_base(level, msg, phase=phase, key=key, color=color, out=out)
return _elog
import sys