split admin_emails option in koji.add_mail_logger

If there are multiple e-mailes separated by comma of space, they should
be split for correct usage of smtplib.sendmail.

Fixes: https://pagure.io/koji/issue/1240
This commit is contained in:
Tomas Kopecek 2019-02-13 09:20:00 +01:00
parent b6074963e9
commit 0e5042832d
3 changed files with 14 additions and 3 deletions

View file

@ -6120,7 +6120,8 @@ def get_options():
parser.add_option("--maxjobs", type='int', help="Specify maxjobs")
parser.add_option("--minspace", type='int', help="Specify minspace")
parser.add_option("--sleeptime", type='int', help="Specify the polling interval")
parser.add_option("--admin-emails", help="Address(es) to send error notices to")
parser.add_option("--admin-emails", type='str', action="store", metavar="EMAILS",
help="Comma-separated addresses to send error notices to.")
parser.add_option("--topdir", help="Specify topdir")
parser.add_option("--topurl", help="Specify topurl")
parser.add_option("--workdir", help="Specify workdir")

View file

@ -3446,11 +3446,20 @@ def add_sys_logger(logger):
logging.getLogger(logger).addHandler(handler)
def add_mail_logger(logger, addr):
"""Adding e-mail logger
:param addr: comma-separated addresses
:type addr: str
:return: -
:rtype: None
"""
if not addr:
return
addresses = addr.split(',')
handler = logging.handlers.SMTPHandler("localhost",
"%s@%s" % (pwd.getpwuid(os.getuid())[0], socket.getfqdn()),
addr,
addresses,
"%s: error notice" % socket.getfqdn())
handler.setFormatter(logging.Formatter('%(pathname)s:%(lineno)d [%(levelname)s] %(message)s'))
handler.setLevel(logging.ERROR)

View file

@ -91,7 +91,8 @@ def get_options():
help="don't actually run main")
parser.add_option("--maxjobs", type='int', help="Specify maxjobs")
parser.add_option("--sleeptime", type='int', help="Specify the polling interval")
parser.add_option("--admin-emails", help="Address(es) to send error notices to")
parser.add_option("--admin-emails", type='str', action="store", metavar="EMAILS",
help="Comma-separated addresses to send error notices to.")
parser.add_option("--workdir", help="Specify workdir")
parser.add_option("--pluginpath", help="Specify plugin search path")
parser.add_option("--plugin", action="append", help="Load specified plugin")