From 39d7a0741d5573a26cac3f91cc0e59cae97b755b Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Sat, 11 Sep 2010 10:53:43 -0700 Subject: [PATCH] Make the mail_summary elog module copy needed variables from the config instance, since we don't need to hold a reference for the whole thing. This also makes it possible to rely on per-package variable settings that may have come from /etc/portage/package.env, since we'll be isolated from any future mutations of mysettings. --- pym/portage/elog/mod_mail_summary.py | 22 +++++++++++++++++++--- pym/portage/mail.py | 4 ++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/pym/portage/elog/mod_mail_summary.py b/pym/portage/elog/mod_mail_summary.py index 1997ddd48..0bd67f22b 100644 --- a/pym/portage/elog/mod_mail_summary.py +++ b/pym/portage/elog/mod_mail_summary.py @@ -13,6 +13,8 @@ from portage import _unicode_decode import socket import time +_config_keys = ('PORTAGE_ELOG_MAILURI', 'PORTAGE_ELOG_MAILFROM', + 'PORTAGE_ELOG_MAILSUBJECT',) _items = {} def process(mysettings, key, logentries, fulltext): global _items @@ -22,7 +24,21 @@ def process(mysettings, key, logentries, fulltext): header = _(">>> Messages generated for package %(pkg)s by process %(pid)d on %(time)s:\n\n") % \ {"pkg": key, "pid": os.getpid(), "time": time_str} config_root = mysettings["PORTAGE_CONFIGROOT"] - mysettings, items = _items.setdefault(config_root, (mysettings, {})) + + # Copy needed variables from the config instance, + # since we don't need to hold a reference for the + # whole thing. This also makes it possible to + # rely on per-package variable settings that may + # have come from /etc/portage/package.env, since + # we'll be isolated from any future mutations of + # mysettings. + config_dict = {} + for k in _config_keys: + v = mysettings.get(k) + if v is not None: + config_dict[k] = v + + config_dict, items = _items.setdefault(config_root, (config_dict, {})) items[key] = header + fulltext def finalize(): @@ -43,9 +59,9 @@ def _finalize(mysettings, items): else: myrecipient = "root@localhost" - myfrom = mysettings["PORTAGE_ELOG_MAILFROM"] + myfrom = mysettings.get("PORTAGE_ELOG_MAILFROM", "") myfrom = myfrom.replace("${HOST}", socket.getfqdn()) - mysubject = mysettings["PORTAGE_ELOG_MAILSUBJECT"] + mysubject = mysettings.get("PORTAGE_ELOG_MAILSUBJECT", "") mysubject = mysubject.replace("${PACKAGE}", count) mysubject = mysubject.replace("${HOST}", socket.getfqdn()) diff --git a/pym/portage/mail.py b/pym/portage/mail.py index 362b00510..f87efe262 100644 --- a/pym/portage/mail.py +++ b/pym/portage/mail.py @@ -92,7 +92,7 @@ def send_mail(mysettings, message): # mailserver: smtp server that should be used to deliver the mail (defaults to localhost) # alternatively this can also be the absolute path to a sendmail binary if you don't want to use smtp # port: port to use on the given smtp server (defaults to 25, values > 100000 indicate that starttls should be used on (port-100000)) - if " " in mysettings["PORTAGE_ELOG_MAILURI"]: + if " " in mysettings.get("PORTAGE_ELOG_MAILURI", ""): myrecipient, mymailuri = mysettings["PORTAGE_ELOG_MAILURI"].split() if "@" in mymailuri: myauthdata, myconndata = mymailuri.rsplit("@", 1) @@ -107,7 +107,7 @@ def send_mail(mysettings, message): else: mymailhost = myconndata else: - myrecipient = mysettings["PORTAGE_ELOG_MAILURI"] + myrecipient = mysettings.get("PORTAGE_ELOG_MAILURI", "") myfrom = message.get("From") -- 2.26.2