Backport EmailPolicy to Python 3.2

broken-hint-logging
Robert Bruce Park 8 years ago committed by Iain Lane
parent 1fe3e56cc7
commit 2405fcf8bc

@ -1,11 +1,11 @@
import os import os
import re import re
import json import json
import socket
import smtplib import smtplib
from urllib.parse import unquote from urllib.parse import unquote
from collections import defaultdict from collections import defaultdict
from email.mime.text import MIMEText
from britney2.policies.rest import Rest from britney2.policies.rest import Rest
from britney2.policies.policy import BasePolicy, PolicyVerdict from britney2.policies.policy import BasePolicy, PolicyVerdict
@ -22,7 +22,12 @@ BOTS = {
USER + 'katie', USER + 'katie',
} }
MESSAGE_BODY = """Hi, MESSAGE = """From: Ubuntu Release Team <noreply@canonical.com>
To: {recipients}
X-Proposed-Migration: notice
Subject: [proposed-migration] {source_name} {version} stuck in {series}-proposed
Hi,
{source_name} {version} needs attention. {source_name} {version} needs attention.
@ -165,20 +170,18 @@ class EmailPolicy(BasePolicy, Rest):
# don't update the cache file in dry run mode; we'll see all output each time # don't update the cache file in dry run mode; we'll see all output each time
return PolicyVerdict.PASS return PolicyVerdict.PASS
if stuck and not sent: if stuck and not sent:
msg = MIMEText(MESSAGE_BODY.format(**locals()))
msg['X-Proposed-Migration'] = 'notice'
msg['Subject'] = '[proposed-migration] {} {} stuck in {}-proposed'.format(source_name, version, series)
msg['From'] = 'Ubuntu Release Team <noreply@canonical.com>'
emails = self.lp_get_emails(source_name, version) emails = self.lp_get_emails(source_name, version)
if emails: if emails:
msg['To'] = ', '.join(emails) recipients = ', '.join(emails)
msg = MESSAGE.format(**locals())
try: try:
with smtplib.SMTP('localhost') as smtp: self.log("%s/%s stuck for %d days, emailing %s" %
self.log ("%s/%s stuck for %d days, emailing %s" % (source_name, version, age, recipients))
(source_name, version, age, ', '.join(emails))) server = smtplib.SMTP('localhost')
smtp.send_message(msg) server.sendmail('noreply@canonical.com', emails, msg)
sent = True server.quit()
except ConnectionRefusedError as err: sent = True
except socket.error as err:
self.log("Failed to send mail! Is SMTP server running?") self.log("Failed to send mail! Is SMTP server running?")
self.log(err) self.log(err)
self.emails_by_pkg[source_name][version] = sent self.emails_by_pkg[source_name][version] = sent

Loading…
Cancel
Save