From 049e24a0b9ac5831e12173a44db670109f9033d1 Mon Sep 17 00:00:00 2001 From: Alex Iribarren Date: May 14 2019 15:35:05 +0000 Subject: Added basic email template --- diff --git a/koji.spec b/koji.spec index 5a6a757..bc7dcaf 100644 --- a/koji.spec +++ b/koji.spec @@ -589,6 +589,7 @@ rm -rf $RPM_BUILD_ROOT %{_sbindir}/koji-gc %dir /etc/koji-gc %config(noreplace) /etc/koji-gc/koji-gc.conf +%config(noreplace) /etc/koji-gc/email.tpl %{_sbindir}/koji-shadow %dir /etc/koji-shadow %config(noreplace) /etc/koji-shadow/koji-shadow.conf diff --git a/util/Makefile b/util/Makefile index 5ea8bde..b4c861b 100644 --- a/util/Makefile +++ b/util/Makefile @@ -22,6 +22,7 @@ _install: mkdir -p $(DESTDIR)/etc/koji-gc install -p -m 644 koji-gc.conf $(DESTDIR)/etc/koji-gc/koji-gc.conf + install -p -m 644 email.tpl $(DESTDIR)/etc/koji-gc/email.tpl mkdir -p $(DESTDIR)/etc/koji-shadow install -p -m 644 koji-shadow.conf $(DESTDIR)/etc/koji-shadow/koji-shadow.conf diff --git a/util/email.tpl b/util/email.tpl new file mode 100644 index 0000000..524ee10 --- /dev/null +++ b/util/email.tpl @@ -0,0 +1,12 @@ +The following build(s) are unreferenced and have been marked for +deletion. They will be held in the trashcan tag for a grace period. +At the end of that period they will be deleted permanently. This +garbage collection is a normal part of build system operation. +Please see the following url for more information: + + https://fedoraproject.org/wiki/Koji/GarbageCollection + +${builds} + +If you would like to protect any of these builds from deletion, please +refer to the document linked above for instructions. diff --git a/util/koji-gc b/util/koji-gc index a269074..02a29f1 100755 --- a/util/koji-gc +++ b/util/koji-gc @@ -26,6 +26,7 @@ import time import six.moves.xmlrpc_client # for ProtocolError and Fault import six.moves.configparser from six.moves import email_mime_text as MIMEText +from string import Template def _(args): @@ -75,6 +76,8 @@ def get_options(): help=_("Email domain appended to Koji username for notifications")) parser.add_option("--from-addr", default="Koji Build System ", help=_("From address for notifications")) + parser.add_option("--email-template", default="/etc/koji-gc/email.tpl", + help=_("notification template")) parser.add_option("--action", help=_("action(s) to take")) parser.add_option("--delay", metavar="INTERVAL", default = '5 days', help="time before eligible builds are placed in trashcan") @@ -139,6 +142,7 @@ def get_options(): ['weburl', None, 'string'], ['smtp_host', None, 'string'], ['from_addr', None, 'string'], + ['email_template', None, 'string'], ['email_domain', None, 'string'], ['mail', None, 'boolean'], ['delay', None, 'string'], @@ -215,6 +219,10 @@ def get_options(): if os.path.exists(fn): setattr(options, name, fn) + template = getattr(options, 'email_template', None) + if not template or not os.access(template, os.F_OK): + parser.error(_("No such file: %s") % template) + return options, args def check_tag(name): @@ -380,23 +388,20 @@ def send_warning_notice(owner_name, builds): if not builds: print("Warning: empty build list. No notice sent") return - head = """\ -The following build(s) are unreferenced and have been marked for -deletion. They will be held in the trashcan tag for a grace period. -At the end of that period they will be deleted permanently. This -garbage collection is a normal part of build system operation. -Please see the following url for more information: - - https://fedoraproject.org/wiki/Koji/GarbageCollection""" + + with open(options.email_template, 'r') as f: + tpl = Template(f.read()) + fmt="""\ Build: %%(name)s-%%(version)s-%%(release)s %s/buildinfo?buildID=%%(id)i""" % options.weburl middle = '\n\n'.join([fmt % b for b in builds]) - tail = """\ -If you would like to protect any of these builds from deletion, please -refer to the document linked above for instructions.""" - msg = MIMEText.MIMEText('\n\n'.join([head, middle, tail])) + msg = MIMEText.MIMEText(tpl.safe_substitute( + owner = owner_name, + builds = middle, + )) + if len(builds) == 1: msg['Subject'] = "1 build marked for deletion" else: