- Make elog finalize() handling safe for PORTAGE_CONFIGROOT. (trunk r6955)
authorZac Medico <zmedico@gentoo.org>
Fri, 22 Jun 2007 23:35:43 +0000 (23:35 -0000)
committerZac Medico <zmedico@gentoo.org>
Fri, 22 Jun 2007 23:35:43 +0000 (23:35 -0000)
- 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

bin/emerge
pym/elog_modules/mod_echo.py
pym/elog_modules/mod_mail_summary.py
pym/portage.py

index c2053c0a9e0ce0072251a61ed0522bcbb10c13a0..3d6e9e245ebf30c0e8ce040fa90a008b4420d2b0 100755 (executable)
@@ -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)
 
index 55d33bb1f479b883a6f13f16df422a10ddee0f1c..b798fb94be1b6fb29b42f3a5884350f735c36dd6 100644 (file)
@@ -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,
index 783d7319652c142dabe20dc58675f8a9cb957e16..22ec0ff0ce16b54c9a0a38c0f76bb4100df7264d 100644 (file)
@@ -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
index 1e3923dd783cf1116dbab42f06879042f9d144e7..d2f2cb027f0769a84ed594f33ec5016039d8a60b 100644 (file)
@@ -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))