summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarius Mauch <genone@gentoo.org>2006-12-19 14:56:17 +0000
committerMarius Mauch <genone@gentoo.org>2006-12-19 14:56:17 +0000
commit72fecf93d17c0cd0f8790edfbe52cd90e2f4c427 (patch)
tree9763fd5e8c48e80d1c5f1e652aad7f0742c41a87
parentUse a separate digraph to store parent/child relationships (PDEPEND relations... (diff)
downloadportage-idfetch-72fecf93d17c0cd0f8790edfbe52cd90e2f4c427.tar.gz
portage-idfetch-72fecf93d17c0cd0f8790edfbe52cd90e2f4c427.tar.bz2
portage-idfetch-72fecf93d17c0cd0f8790edfbe52cd90e2f4c427.zip
New elog modules for dismerging messages into a single file/mail
svn path=/main/trunk/; revision=5325
-rw-r--r--NEWS5
-rw-r--r--cnf/make.conf6
-rw-r--r--pym/elog_modules/mod_mail_summary.py39
-rw-r--r--pym/elog_modules/mod_save_summary.py23
-rw-r--r--pym/portage.py5
5 files changed, 77 insertions, 1 deletions
diff --git a/NEWS b/NEWS
index 5ee0bf3f..d80c27c3 100644
--- a/NEWS
+++ b/NEWS
@@ -19,6 +19,11 @@ portage-2.1.2
* DEPEND atoms support SLOT dependencies of the form ${CATEGORY}/${PN}:${SLOT}.
* Development: Extend PYTHONPATH support to allow overriding the hardcoded
/usr/lib/portage/pym for development/testing purposes
+* New "finalize" hook for elog modules enabling modules to perform actions on
+ shutdown (like dispatching collected messages).
+* New elog modules mail_summary and save_summary that act like the mail/save
+ modules except that they merge messages from multiple packages in a single
+ file/mail.
portage-2.1.1
------------
diff --git a/cnf/make.conf b/cnf/make.conf
index 6c3f415f..a3e5b143 100644
--- a/cnf/make.conf
+++ b/cnf/make.conf
@@ -325,6 +325,12 @@ PORTAGE_ELOG_CLASSES="warn error log"
# syslog (sends all messages to syslog)
# mail (send all messages to the mailserver defined
# in $PORTAGE_ELOG_MAILURI)
+# save_summary (like "save" but merges all messages
+# in $PORT_LOGDIR/elog/summary.log,
+# /var/log/portage/elog/summary.log if
+# $PORT_LOGDIR is unset)
+# mail_summary (like "mail" but sends all messages in
+# a single mail when emerge exits)
# To use elog you should enable at least one module
#PORTAGE_ELOG_SYSTEM="save mail"
diff --git a/pym/elog_modules/mod_mail_summary.py b/pym/elog_modules/mod_mail_summary.py
new file mode 100644
index 00000000..53628b92
--- /dev/null
+++ b/pym/elog_modules/mod_mail_summary.py
@@ -0,0 +1,39 @@
+# portage.py -- core Portage functionality
+# Copyright 1998-2004 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id: mod_mail.py 3484 2006-06-10 22:38:44Z genone $
+
+import portage_mail, socket, os, time
+from email.MIMEText import MIMEText as TextMessage
+
+_items = {}
+def process(mysettings, cpv, logentries, fulltext):
+ header = ">>> Messages generated for package %s by process %d on %s:\n\n" % \
+ (cpv, os.getpid(), time.strftime("%Y%m%d-%H%M%S", time.gmtime(time.time())))
+ _items[cpv] = header + fulltext
+
+def finalize(mysettings):
+ if len(_items) == 0:
+ return
+ elif len(_items) == 1:
+ count = "one package"
+ else:
+ count = "multiple packages"
+ if mysettings.has_key("PORTAGE_ELOG_MAILURI"):
+ myrecipient = mysettings["PORTAGE_ELOG_MAILURI"].split()[0]
+ else:
+ myrecipient = "root@localhost"
+
+ myfrom = mysettings["PORTAGE_ELOG_MAILFROM"]
+ mysubject = mysettings["PORTAGE_ELOG_MAILSUBJECT"]
+ mysubject = mysubject.replace("${PACKAGE}", count)
+ mysubject = mysubject.replace("${HOST}", socket.getfqdn())
+
+ mybody = "elog messages for the following packages generated by process %d on host %s:\n" % (count, os.getpid(), socket.getfqdn())
+ for cpv in _items.keys():
+ mybody += "- %s\n" % cpv
+
+ mymessage = portage_mail.create_message(myfrom, myrecipient, mysubject, mybody, attachments=_items.values())
+ portage_mail.send_mail(mysettings, mymessage)
+
+ return
diff --git a/pym/elog_modules/mod_save_summary.py b/pym/elog_modules/mod_save_summary.py
new file mode 100644
index 00000000..ed250795
--- /dev/null
+++ b/pym/elog_modules/mod_save_summary.py
@@ -0,0 +1,23 @@
+import os. time
+from portage_data import portage_uid, portage_gid
+
+def process(mysettings, cpv, logentries, fulltext):
+ if mysettings["PORT_LOGDIR"] != "":
+ elogdir = os.path.join(mysettings["PORT_LOGDIR"], "elog")
+ else:
+ elogdir = os.path.join(os.sep, "var", "log", "portage", "elog")
+ if not os.path.exists(elogdir):
+ os.makedirs(elogdir)
+ os.chown(elogdir, portage_uid, portage_gid)
+ os.chmod(elogdir, 02770)
+
+ # TODO: Locking
+ elogfilename = elogdir+"/summary.log"
+ elogfile = open(elogfilename, "a")
+ elogfile.write(">>> Messages generated by process %d on %s:\n\n" % \
+ (os.getpid(), time.strftime("%Y%m%d-%H%M%S", time.gmtime(time.time()))))
+ elogfile.write(fulltext)
+ elogfile.write("\n")
+ elogfile.close()
+
+ return elogfilename
diff --git a/pym/portage.py b/pym/portage.py
index 984be527..af660772 100644
--- a/pym/portage.py
+++ b/pym/portage.py
@@ -467,7 +467,7 @@ class digraph:
print "(%s)" % self.nodes[node][0][child]
-
+_elog_atexit_handlers = []
def elog_process(cpv, mysettings):
mylogfiles = listdir(mysettings["T"]+"/logging/")
# shortcut for packages without any messages
@@ -513,6 +513,9 @@ def elog_process(cpv, mysettings):
logmodule = __import__("elog_modules.mod_"+s)
m = getattr(logmodule, "mod_"+s)
m.process(mysettings, cpv, mylogentries, fulllog)
+ 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:
print "!!! Error while importing logging modules while loading \"mod_%s\":" % s
print e