From: Zac Medico Date: Fri, 22 Jun 2007 23:35:43 +0000 (-0000) Subject: - Make elog finalize() handling safe for PORTAGE_CONFIGROOT. (trunk r6955) X-Git-Tag: v2.1.3~169 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=a1dd09f64ccefbff495d0607aeec5422f32b93fb;p=portage.git - Make elog finalize() handling safe for PORTAGE_CONFIGROOT. (trunk r6955) - Dump mod_echo elog output inside post_emerge(), just before the other notifications that happen at exit. (trunk r6953) svn path=/main/branches/2.1.2/; revision=6958 --- diff --git a/bin/emerge b/bin/emerge index c2053c0a9..3d6e9e245 100755 --- a/bin/emerge +++ b/bin/emerge @@ -3760,6 +3760,11 @@ def post_emerge(settings, mtimedb, retval): emergelog("notitles" not in settings.features, " *** exiting successfully.") + # Dump the mod_echo output now so that our other notifications are shown + # last. + from elog_modules import mod_echo + mod_echo.finalize() + if "noinfo" not in settings.features: chk_updated_info_files(target_root, infodirs, info_mtimes, retval) diff --git a/pym/elog_modules/mod_echo.py b/pym/elog_modules/mod_echo.py index 55d33bb1f..b798fb94b 100644 --- a/pym/elog_modules/mod_echo.py +++ b/pym/elog_modules/mod_echo.py @@ -8,18 +8,27 @@ from portage_const import EBUILD_PHASES _items = {} def process(mysettings, key, logentries, fulltext): - _items[key] = logentries + global _items + config_root = mysettings["PORTAGE_CONFIGROOT"] + mysettings, items = _items.setdefault(config_root, (mysettings, {})) + items[key] = logentries -def finalize(mysettings): +def finalize(): + global _items + for mysettings, items in _items.itervalues(): + _finalize(mysettings, items) + _items.clear() + +def _finalize(mysettings, items): printer = EOutput() - for key in _items: + for key, logentries in items.iteritems(): print printer.einfo("Messages for package %s:" % key) print for phase in EBUILD_PHASES: - if not phase in _items[key]: + if phase not in logentries: continue - for msgtype, msgcontent in _items[key][phase]: + for msgtype, msgcontent in logentries[phase]: fmap = {"INFO": printer.einfo, "WARN": printer.ewarn, "ERROR": printer.eerror, diff --git a/pym/elog_modules/mod_mail_summary.py b/pym/elog_modules/mod_mail_summary.py index 783d73196..22ec0ff0c 100644 --- a/pym/elog_modules/mod_mail_summary.py +++ b/pym/elog_modules/mod_mail_summary.py @@ -7,15 +7,24 @@ import portage_mail, socket, os, time from email.MIMEText import MIMEText as TextMessage _items = {} -def process(mysettings, cpv, logentries, fulltext): +def process(mysettings, key, logentries, fulltext): + global _items 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 + (key, os.getpid(), time.strftime("%Y%m%d-%H%M%S", time.gmtime(time.time()))) + config_root = mysettings["PORTAGE_CONFIGROOT"] + mysettings, items = _items.setdefault(config_root, (mysettings, {})) + items[key] = header + fulltext -def finalize(mysettings): - if len(_items) == 0: +def finalize(): + global _items + for mysettings, items in _items.itervalues(): + _finalize(mysettings, items) + _items.clear() + +def _finalize(mysettings, items): + if len(items) == 0: return - elif len(_items) == 1: + elif len(items) == 1: count = "one package" else: count = "multiple packages" @@ -31,10 +40,11 @@ def finalize(mysettings): mybody = "elog messages for the following packages generated by " + \ "process %d on host %s:\n" % (os.getpid(), socket.getfqdn()) - for cpv in _items: + for cpv in items: mybody += "- %s\n" % cpv - mymessage = portage_mail.create_message(myfrom, myrecipient, mysubject, mybody, attachments=_items.values()) + mymessage = portage_mail.create_message(myfrom, myrecipient, mysubject, + mybody, attachments=items.values()) portage_mail.send_mail(mysettings, mymessage) return diff --git a/pym/portage.py b/pym/portage.py index 1e3923dd7..d2f2cb027 100644 --- a/pym/portage.py +++ b/pym/portage.py @@ -560,7 +560,7 @@ def elog_process(cpv, mysettings): 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) + atexit_register(m.finalize) except (ImportError, AttributeError), e: writemsg("!!! Error while importing logging modules " + \ "while loading \"mod_%s\":\n" % str(s))