diff options
author | Marius Mauch <genone@gentoo.org> | 2007-05-18 17:16:55 +0000 |
---|---|---|
committer | Marius Mauch <genone@gentoo.org> | 2007-05-18 17:16:55 +0000 |
commit | 093cd82b06d587896c8e08bed309d052c73e41e6 (patch) | |
tree | a19acdebc283a7cd817a1245bdb1e2fe2339fa0f /pym/portage/elog/messages.py | |
parent | 386b8e3c552a8c919d4d98f552f71c256dde9421 (diff) | |
download | portage-093cd82b06d587896c8e08bed309d052c73e41e6.tar.gz portage-093cd82b06d587896c8e08bed309d052c73e41e6.tar.bz2 portage-093cd82b06d587896c8e08bed309d052c73e41e6.zip |
Enable elog functionality for the python side of portage
svn path=/main/trunk/; revision=6548
Diffstat (limited to 'pym/portage/elog/messages.py')
-rw-r--r-- | pym/portage/elog/messages.py | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/pym/portage/elog/messages.py b/pym/portage/elog/messages.py new file mode 100644 index 000000000..bfe428030 --- /dev/null +++ b/pym/portage/elog/messages.py @@ -0,0 +1,89 @@ +# elog/messages.py - elog core functions +# Copyright 2006-2007 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Id: __init__.py 6458 2007-04-30 02:31:30Z genone $ + +from portage.output import colorize +from portage.const import EBUILD_PHASES +from portage.util import writemsg + +from portage import listdir + +import os + +def collect_ebuild_messages(path): + """ Collect elog messages generated by the bash logging function stored + at 'path'. + """ + mylogfiles = listdir(path) + # shortcut for packages without any messages + if len(mylogfiles) == 0: + return {} + # exploit listdir() file order so we process log entries in chronological order + mylogfiles.reverse() + logentries = {} + for f in mylogfiles: + msgfunction, msgtype = f.split(".") + if msgfunction not in EBUILD_PHASES: + writemsg("!!! can't process invalid log file: %s\n" % f, + noiselevel=-1) + continue + if not msgfunction in logentries: + logentries[msgfunction] = [] + msgcontent = open(os.path.join(path, f), "r").readlines() + logentries[msgfunction].append((msgtype, msgcontent)) + # clean logfiles to avoid repetitions + for f in mylogfiles: + try: + os.unlink(os.path.join(path, f)) + except OSError: + pass + return logentries + +_msgbuffer = {} +def _elog_base(level, msg, phase="other", key=None, color=None): + """ Backend for the other messaging functions, should not be called + directly. + """ + if color == None: + color = "GOOD" + print colorize(color, " * ")+msg + if not _msgbuffer.has_key(key): + _msgbuffer[key] = {} + if not _msgbuffer[key].has_key(phase): + _msgbuffer[key][phase] = [] + _msgbuffer[key][phase].append((level, msg)) + + #raise NotImplementedError() + +def collect_messages(): + rValue = _msgbuffer + _reset_buffer() + return rValue + +def _reset_buffer(): + """ Reset the internal message buffer when it has been processed, + should not be called directly. + """ + _msgbuffer = {} + +# creating and exporting the actual messaging functions +_functions = { "einfo": ("INFO", "GOOD"), + "elog": ("LOG", "GOOD"), + "ewarn": ("WARN", "WARN"), + "eqawarn": ("QA", "WARN"), + "eerror": ("ERROR", "ERROR"), +} + +def _make_msgfunction(level, color): + def _elog(msg, phase="other", key=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) + return _elog + +import sys +for f in _functions.keys(): + setattr(sys.modules[__name__], f, _make_msgfunction(_functions[f][0], _functions[f][1])) +del f, _functions |