Make elog finalize() handling safe for PORTAGE_CONFIGROOT.
authorZac Medico <zmedico@gentoo.org>
Fri, 22 Jun 2007 23:11:38 +0000 (23:11 -0000)
committerZac Medico <zmedico@gentoo.org>
Fri, 22 Jun 2007 23:11:38 +0000 (23:11 -0000)
svn path=/main/trunk/; revision=6955

pym/emerge/__init__.py
pym/portage/elog/__init__.py
pym/portage/elog/mod_echo.py
pym/portage/elog/mod_mail_summary.py

index 6d8da7c2db4ffdceac7e03f48f9078ab7f5b306b..17ff8d58dd324350a40627f310eb1950ed169ace 100644 (file)
@@ -3870,12 +3870,9 @@ def post_emerge(trees, mtimedb, retval):
                " *** exiting successfully.")
 
        # Dump the mod_echo output now so that our other notifications are shown
-       # last.  FIXME: handle finalize for multiple config instances
-       # (PORTAGE_CONFIGROOT support).
+       # last.
        from portage.elog import mod_echo
-       if mod_echo._items:
-               mod_echo.finalize(settings)
-               mod_echo._items.clear()
+       mod_echo.finalize()
 
        if "noinfo" not in settings.features:
                chk_updated_info_files(target_root, infodirs, info_mtimes, retval)
index 1cf4dd8b8c3628daa25109d85090fadff628f9f9..cbe9f47fa0a37a924e14f170a91c2b3eda593c2a 100644 (file)
@@ -95,14 +95,9 @@ def elog_process(cpv, mysettings):
                                        m.process(mysettings, str(key), mod_logentries, mod_fulllog)
                                finally:
                                        signal.alarm(0)
-                               # FIXME: when installing to more than one $ROOT, the finalizer
-                               # will only be registered with a config instance from one of
-                               # the roots (randomly).  With PORTAGE_CONFIGROOT, the config
-                               # instances can have completely different settings, so
-                               # logs can end up in the wrong PORT_LOGDIR for example.
                                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))
index 6dcc652338b4253193db3a1b871b53a2b10fcc4d..308c8efcc443c8ee63d9b5fe852ee5bc53cda7af 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 0a39b17b13770d1fe72deb022a361a82593669a4..884df40c839e83927067a61aba10ccb0df9474cd 100644 (file)
@@ -8,14 +8,23 @@ from email.MIMEText import MIMEText as TextMessage
 
 _items = {}
 def process(mysettings, key, logentries, fulltext):
+       global _items
        header = ">>> Messages generated for package %s by process %d on %s:\n\n" % \
                (key, os.getpid(), time.strftime("%Y%m%d-%H%M%S", time.gmtime(time.time())))
-       _items[key] = header + fulltext
+       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 key in _items:
+       for key in items:
                 mybody += "- %s\n" % key
 
-       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