summaryrefslogtreecommitdiffstats
path: root/pym/portage/elog/__init__.py
diff options
context:
space:
mode:
authorMarius Mauch <genone@gentoo.org>2007-05-18 17:16:55 +0000
committerMarius Mauch <genone@gentoo.org>2007-05-18 17:16:55 +0000
commit093cd82b06d587896c8e08bed309d052c73e41e6 (patch)
treea19acdebc283a7cd817a1245bdb1e2fe2339fa0f /pym/portage/elog/__init__.py
parent386b8e3c552a8c919d4d98f552f71c256dde9421 (diff)
downloadportage-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/__init__.py')
-rw-r--r--pym/portage/elog/__init__.py180
1 files changed, 84 insertions, 96 deletions
diff --git a/pym/portage/elog/__init__.py b/pym/portage/elog/__init__.py
index be7eb5b66..77bdd1b94 100644
--- a/pym/portage/elog/__init__.py
+++ b/pym/portage/elog/__init__.py
@@ -8,111 +8,99 @@ from portage.exception import PortageException
from portage.process import atexit_register
from portage.util import writemsg
-from portage import listdir
+from portage.elog.messages import collect_ebuild_messages, collect_messages
+from portage.elog.filtering import filter_loglevels
import os
+def _merge_logentries(a, b):
+ rValue = {}
+ phases = set(a.keys()+b.keys())
+ for p in phases:
+ rValue[p] = []
+ if a.has_key(p):
+ for x in a[p]:
+ rValue[p].append(x)
+ if b.has_key(p):
+ for x in b[p]:
+ rValue[p].append(x)
+ return rValue
+
+def _combine_logentries(logentries):
+ # generate a single string with all log messages
+ rValue = ""
+ for phase in EBUILD_PHASES:
+ if not phase in logentries:
+ continue
+ for msgtype, msgcontent in logentries[phase]:
+ rValue += "%s: %s\n" % (msgtype, phase)
+ for line in msgcontent:
+ rValue += line
+ rValue += "\n"
+ return rValue
+
_elog_atexit_handlers = []
def elog_process(cpv, mysettings):
- mylogfiles = listdir(mysettings["T"]+"/logging/")
- # 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()
- all_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 all_logentries:
- all_logentries[msgfunction] = []
- msgcontent = open(mysettings["T"]+"/logging/"+f, "r").readlines()
- all_logentries[msgfunction].append((msgtype, msgcontent))
+ ebuild_logentries = collect_ebuild_messages(os.path.join(mysettings["T"], "logging"))
+ all_logentries = collect_messages()
+ if all_logentries.has_key(cpv):
+ all_logentries[cpv] = _merge_logentries(ebuild_logentries, all_logentries[cpv])
+ else:
+ all_logentries[cpv] = ebuild_logentries
- def filter_loglevels(logentries, loglevels):
- # remove unwanted entries from all logentries
- rValue = {}
- loglevels = map(str.upper, loglevels)
- for phase in logentries.keys():
- for msgtype, msgcontent in logentries[phase]:
- if msgtype.upper() in loglevels or "*" in loglevels:
- if not rValue.has_key(phase):
- rValue[phase] = []
- rValue[phase].append((msgtype, msgcontent))
- return rValue
-
my_elog_classes = set(mysettings.get("PORTAGE_ELOG_CLASSES", "").split())
- default_logentries = filter_loglevels(all_logentries, my_elog_classes)
- # in case the filters matched all messages and no module overrides exist
- if len(default_logentries) == 0 and (not ":" in mysettings.get("PORTAGE_ELOG_SYSTEM", "")):
- return
- def combine_logentries(logentries):
- # generate a single string with all log messages
- rValue = ""
- for phase in EBUILD_PHASES:
- if not phase in logentries:
- continue
- for msgtype, msgcontent in logentries[phase]:
- rValue += "%s: %s\n" % (msgtype, phase)
- for line in msgcontent:
- rValue += line
- rValue += "\n"
- return rValue
-
- default_fulllog = combine_logentries(default_logentries)
+ for key in all_logentries.keys():
+ default_logentries = filter_loglevels(all_logentries[key], my_elog_classes)
- # pass the processing to the individual modules
- logsystems = mysettings["PORTAGE_ELOG_SYSTEM"].split()
- for s in logsystems:
- # allow per module overrides of PORTAGE_ELOG_CLASSES
- if ":" in s:
- s, levels = s.split(":", 1)
- levels = levels.split(",")
- mod_logentries = filter_loglevels(all_logentries, levels)
- mod_fulllog = combine_logentries(mod_logentries)
- else:
- mod_logentries = default_logentries
- mod_fulllog = default_fulllog
- if len(mod_logentries) == 0:
- continue
- # - is nicer than _ for module names, so allow people to use it.
- s = s.replace("-", "_")
- try:
- # FIXME: ugly ad.hoc import code
- # TODO: implement a common portage module loader
- name = "portage.elog.mod_" + s
- m = __import__(name)
- for comp in name.split(".")[1:]:
- m = getattr(m, comp)
- def timeout_handler(signum, frame):
- raise PortageException("Timeout in elog_process for system '%s'" % s)
- import signal
- signal.signal(signal.SIGALRM, timeout_handler)
- # Timeout after one minute (in case something like the mail
- # module gets hung).
- signal.alarm(60)
+ # in case the filters matched all messages and no module overrides exist
+ if len(default_logentries) == 0 and (not ":" in mysettings.get("PORTAGE_ELOG_SYSTEM", "")):
+ return
+
+ default_fulllog = _combine_logentries(default_logentries)
+
+ # pass the processing to the individual modules
+ logsystems = mysettings["PORTAGE_ELOG_SYSTEM"].split()
+ for s in logsystems:
+ # allow per module overrides of PORTAGE_ELOG_CLASSES
+ if ":" in s:
+ s, levels = s.split(":", 1)
+ levels = levels.split(",")
+ mod_logentries = filter_loglevels(all_logentries[key], levels)
+ mod_fulllog = combine_logentries(mod_logentries)
+ else:
+ mod_logentries = default_logentries
+ mod_fulllog = default_fulllog
+ if len(mod_logentries) == 0:
+ continue
+ # - is nicer than _ for module names, so allow people to use it.
+ s = s.replace("-", "_")
try:
- m.process(mysettings, cpv, mod_logentries, mod_fulllog)
- finally:
- signal.alarm(0)
- if hasattr(m, "finalize") and not m.finalize in _elog_atexit_handlers:
- _elog_atexit_handlers.append(m.finalize)
- atexit_register(m.finalize, mysettings)
- except (ImportError, AttributeError), e:
- writemsg("!!! Error while importing logging modules " + \
- "while loading \"mod_%s\":\n" % str(s))
- writemsg("%s\n" % str(e), noiselevel=-1)
- except PortageException, e:
- writemsg("%s\n" % str(e), noiselevel=-1)
+ # FIXME: ugly ad.hoc import code
+ # TODO: implement a common portage module loader
+ name = "portage.elog.mod_" + s
+ m = __import__(name)
+ for comp in name.split(".")[1:]:
+ m = getattr(m, comp)
+ def timeout_handler(signum, frame):
+ raise PortageException("Timeout in elog_process for system '%s'" % s)
+ import signal
+ signal.signal(signal.SIGALRM, timeout_handler)
+ # Timeout after one minute (in case something like the mail
+ # module gets hung).
+ signal.alarm(60)
+ try:
+ m.process(mysettings, str(key), mod_logentries, mod_fulllog)
+ finally:
+ signal.alarm(0)
+ if hasattr(m, "finalize") and not m.finalize in _elog_atexit_handlers:
+ _elog_atexit_handlers.append(m.finalize)
+ atexit_register(m.finalize, mysettings)
+ except (ImportError, AttributeError), e:
+ writemsg("!!! Error while importing logging modules " + \
+ "while loading \"mod_%s\":\n" % str(s))
+ writemsg("%s\n" % str(e), noiselevel=-1)
+ except PortageException, e:
+ writemsg("%s\n" % str(e), noiselevel=-1)
- # clean logfiles to avoid repetitions
- for f in mylogfiles:
- try:
- os.unlink(os.path.join(mysettings["T"], "logging", f))
- except OSError:
- pass