summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2008-07-17 10:11:26 +0000
committerZac Medico <zmedico@gentoo.org>2008-07-17 10:11:26 +0000
commite71866de7ddcf66fcc28dcd3c518d9ec022a0406 (patch)
treeaa4fc53e98a902b9448bd05f6a0580d1b35696e8
parentbce4066ade962cedd1fc5f2090a71da0ad2f7408 (diff)
downloadportage-e71866de7ddcf66fcc28dcd3c518d9ec022a0406.tar.gz
portage-e71866de7ddcf66fcc28dcd3c518d9ec022a0406.tar.bz2
portage-e71866de7ddcf66fcc28dcd3c518d9ec022a0406.zip
* Add a new portage.util.writemsg_level() function which uses a "level"
parameter to control whether the message is sent to stdout or stderr. When level >= logging.WARNING then the message is sent to stderr, otherwise it is sent to stdout. The noiselevel is passed directly to writemsg(). * Use writemsg_level() for handling merge messages from dblink and add appropriate noiselevel values to each call. * Add a writemsg_level parameter to portage.env_update() so that dblink can pass in dblink._display_merge() as a means to redirect output back to the scheduler for appropriate handling when running in the background. svn path=/main/trunk/; revision=11098
-rw-r--r--pym/_emerge/__init__.py15
-rw-r--r--pym/portage/__init__.py8
-rw-r--r--pym/portage/dbapi/vartree.py51
-rw-r--r--pym/portage/util.py20
4 files changed, 59 insertions, 35 deletions
diff --git a/pym/_emerge/__init__.py b/pym/_emerge/__init__.py
index 8e4dd5e19..df4de0b7c 100644
--- a/pym/_emerge/__init__.py
+++ b/pym/_emerge/__init__.py
@@ -8625,22 +8625,17 @@ class Scheduler(PollScheduler):
finally:
f.close()
- def _dblink_display_merge(self, pkg_dblink, msg, level=0):
+ 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
- if level >= logging.WARNING:
- noiselevel = -1
- msg_func = writemsg
- else:
- noiselevel = 0
- msg_func = portage.writemsg_stdout
-
if log_path is None:
- msg_func(msg, noiselevel=noiselevel)
+ portage.util.writemsg_level(msg,
+ level=level, noiselevel=noiselevel)
else:
if not background:
- msg_func(msg, noiselevel=noiselevel)
+ portage.util.writemsg_level(msg,
+ level=level, noiselevel=noiselevel)
self._append_to_log_path(log_path, msg)
def _dblink_ebuild_phase(self,
diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py
index cb21435fd..3081d9ea6 100644
--- a/pym/portage/__init__.py
+++ b/pym/portage/__init__.py
@@ -540,11 +540,10 @@ class digraph(object):
print " ",child,
print "(%s)" % self.nodes[node][0][child]
-
#parse /etc/env.d and generate /etc/profile.env
def env_update(makelinks=1, target_root=None, prev_mtimes=None, contents=None,
- env=None):
+ env=None, writemsg_level=portage.util.writemsg_level):
if target_root is None:
global settings
target_root = settings["ROOT"]
@@ -751,13 +750,14 @@ def env_update(makelinks=1, target_root=None, prev_mtimes=None, contents=None,
# an older package installed ON TOP of a newer version will cause ldconfig
# to overwrite the symlinks we just made. -X means no links. After 'clean'
# we can safely create links.
- writemsg(">>> Regenerating %setc/ld.so.cache...\n" % target_root)
+ writemsg_level(">>> Regenerating %setc/ld.so.cache...\n" % \
+ (target_root,))
if makelinks:
os.system("cd / ; %s -r '%s'" % (ldconfig, target_root))
else:
os.system("cd / ; %s -X -r '%s'" % (ldconfig, target_root))
elif ostype in ("FreeBSD","DragonFly"):
- writemsg(">>> Regenerating %svar/run/ld-elf.so.hints...\n" % \
+ writemsg_level(">>> Regenerating %svar/run/ld-elf.so.hints...\n" % \
target_root)
os.system(("cd / ; %s -elf -i " + \
"-f '%svar/run/ld-elf.so.hints' '%setc/ld.so.conf'") % \
diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py
index d7cc85027..deea8539b 100644
--- a/pym/portage/dbapi/vartree.py
+++ b/pym/portage/dbapi/vartree.py
@@ -15,7 +15,8 @@ from portage.locks import lockdir, unlockdir
from portage.output import bold, red, green
from portage.update import fixdbentries
from portage.util import apply_secpass_permissions, ConfigProtect, ensure_dirs, \
- writemsg, writemsg_stdout, write_atomic, atomic_ofstream, writedict, \
+ writemsg, writemsg_stdout, writemsg_level, \
+ write_atomic, atomic_ofstream, writedict, \
grabfile, grabdict, normalize_path, new_protect_filename, getlibpaths
from portage.versions import pkgsplit, catpkgsplit, catsplit, best, pkgcmp
@@ -1536,6 +1537,7 @@ class dblink(object):
# name of the dir; the package may have been moved.
myebuildpath = None
ebuild_phase = "prerm"
+ log_path = None
mystuff = os.listdir(self.dbdir)
for x in mystuff:
if x.endswith(".ebuild"):
@@ -1579,6 +1581,7 @@ class dblink(object):
catdir_lock = None
prepare_build_dirs(self.myroot, self.settings, 1)
+ log_path = self.settings.get("PORTAGE_LOG_FILE")
if scheduler is None:
retval = doebuild(myebuildpath, ebuild_phase, self.myroot,
@@ -1735,22 +1738,23 @@ class dblink(object):
raise
del e
unlockdir(catdir_lock)
+
+ if log_path is not None:
+ # Restore this since it gets lost somewhere above and it
+ # needs to be set for _display_merge() to be able to log.
+ self.settings["PORTAGE_LOG_FILE"] = log_path
+
env_update(target_root=self.myroot, prev_mtimes=ldpath_mtimes,
- contents=contents, env=self.settings.environ())
+ contents=contents, env=self.settings.environ(),
+ writemsg_level=self._display_merge)
return os.EX_OK
- def _display_merge(self, msg, level=0):
+ def _display_merge(self, msg, level=0, noiselevel=0):
if self._scheduler is not None:
- self._scheduler.dblinkDisplayMerge(self, msg, level=level)
+ self._scheduler.dblinkDisplayMerge(self, msg,
+ level=level, noiselevel=noiselevel)
return
-
- if level >= logging.WARNING:
- noiselevel = -1
- msg_func = writemsg
- else:
- noiselevel = 0
- msg_func = writemsg_stdout
- msg_func(msg, noiselevel=noiselevel)
+ writemsg_level(msg, level=level, noiselevel=noiselevel)
def _unmerge_pkgfiles(self, pkgfiles, others_in_slot):
"""
@@ -2314,12 +2318,15 @@ class dblink(object):
from portage.output import colorize
prefix = colorize("SECURITY_WARN", "*") + " WARNING: "
showMessage(prefix + "suid/sgid file(s) " + \
- "with suspicious hardlink(s):\n", level=logging.ERROR)
+ "with suspicious hardlink(s):\n",
+ level=logging.ERROR, noiselevel=-1)
for path_list in suspicious_hardlinks:
for path, s in path_list:
- showMessage(prefix + " '%s'\n" % path, level=logging.ERROR)
+ showMessage(prefix + " '%s'\n" % path,
+ level=logging.ERROR, noiselevel=-1)
showMessage(prefix + "See the Gentoo Security Handbook " + \
- "guide for advice on how to proceed.\n", level=logging.ERROR)
+ "guide for advice on how to proceed.\n",
+ level=logging.ERROR, noiselevel=-1)
return 1
def treewalk(self, srcroot, destroot, inforoot, myebuild, cleanup=0,
@@ -2365,7 +2372,7 @@ class dblink(object):
if not os.path.isdir(srcroot):
showMessage("!!! Directory Not Found: D='%s'\n" % srcroot,
- level=logging.ERROR)
+ level=logging.ERROR, noiselevel=-1)
return 1
inforoot_slot_file = os.path.join(inforoot, "SLOT")
@@ -2619,7 +2626,7 @@ class dblink(object):
# XXX: Decide how to handle failures here.
if a != os.EX_OK:
showMessage("!!! FAILED preinst: "+str(a)+"\n",
- level=logging.ERROR)
+ level=logging.ERROR, noiselevel=-1)
return a
# copy "info" files (like SLOT, CFLAGS, etc.) into the database
@@ -2742,7 +2749,7 @@ class dblink(object):
showMessage(colorize("WARN", "WARNING:")
+ " AUTOCLEAN is disabled. This can cause serious"
+ " problems due to overlapping packages.\n",
- level=logging.WARN)
+ level=logging.WARN, noiselevel=-1)
# We hold both directory locks.
self.dbdir = self.dbpkgdir
@@ -2785,7 +2792,7 @@ class dblink(object):
# XXX: Decide how to handle failures here.
if a != os.EX_OK:
showMessage("!!! FAILED postinst: "+str(a)+"\n",
- level=logging.ERROR)
+ level=logging.ERROR, noiselevel=-1)
return a
downgrade = False
@@ -2796,7 +2803,8 @@ class dblink(object):
#update environment settings, library paths. DO NOT change symlinks.
env_update(makelinks=(not downgrade),
target_root=self.settings["ROOT"], prev_mtimes=prev_mtimes,
- contents=contents, env=self.settings.environ())
+ contents=contents, env=self.settings.environ(),
+ writemsg_level=self._display_merge)
return os.EX_OK
@@ -3007,7 +3015,8 @@ class dblink(object):
if stat.S_ISDIR(mydmode):
# install of destination is blocked by an existing directory with the same name
moveme = 0
- showMessage("!!! %s\n" % mydest, level=logging.ERROR)
+ showMessage("!!! %s\n" % mydest,
+ level=logging.ERROR, noiselevel=-1)
elif stat.S_ISREG(mydmode) or (stat.S_ISLNK(mydmode) and os.path.exists(mydest) and stat.S_ISREG(os.stat(mydest)[stat.ST_MODE])):
cfgprot = 0
# install of destination is blocked by an existing regular file,
diff --git a/pym/portage/util.py b/pym/portage/util.py
index f6cd68457..9ad93b5c3 100644
--- a/pym/portage/util.py
+++ b/pym/portage/util.py
@@ -50,6 +50,26 @@ def writemsg_stdout(mystr,noiselevel=0):
"""Prints messages stdout based on the noiselimit setting"""
writemsg(mystr, noiselevel=noiselevel, fd=sys.stdout)
+def writemsg_level(msg, level=0, noiselevel=0):
+ """
+ Show a message for the given level as defined by the logging module
+ (default is 0). When level >= logging.WARNING then the message is
+ sent to stderr, otherwise it is sent to stdout. The noiselevel is
+ passed directly to writemsg().
+
+ @type msg: str
+ @param msg: a message string, including newline if appropriate
+ @type level: int
+ @param level: a numeric logging level (see the logging module)
+ @type noiselevel: int
+ @param noiselevel: passed directly to writemsg
+ """
+ if level >= logging.WARNING:
+ fd = sys.stderr
+ else:
+ fd = sys.stdout
+ writemsg(msg, noiselevel=noiselevel, fd=fd)
+
def normalize_path(mypath):
"""
os.path.normpath("//foo") returns "//foo" instead of "/foo"