import socket
import time
+_config_keys = ('PORTAGE_ELOG_MAILURI', 'PORTAGE_ELOG_MAILFROM',
+ 'PORTAGE_ELOG_MAILSUBJECT',)
_items = {}
def process(mysettings, key, logentries, fulltext):
global _items
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():
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())
# 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)
else:
mymailhost = myconndata
else:
- myrecipient = mysettings["PORTAGE_ELOG_MAILURI"]
+ myrecipient = mysettings.get("PORTAGE_ELOG_MAILURI", "")
myfrom = message.get("From")