mirror of
https://git.launchpad.net/~ubuntu-release/britney/+git/britney2-ubuntu
synced 2025-03-23 17:01:11 +00:00
email: Ignore suspended LP people
We were looking at ~python-modules-team, which is suspended and raises a HTTPError that wasn't being caught.
This commit is contained in:
parent
c2de27c3b3
commit
272f41c4a5
@ -5,6 +5,7 @@ import math
|
|||||||
import socket
|
import socket
|
||||||
import smtplib
|
import smtplib
|
||||||
|
|
||||||
|
from urllib.error import HTTPError
|
||||||
from urllib.parse import unquote
|
from urllib.parse import unquote
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
@ -117,33 +118,40 @@ class EmailPolicy(BasePolicy, Rest):
|
|||||||
if person in self.addresses:
|
if person in self.addresses:
|
||||||
return self.addresses[person]
|
return self.addresses[person]
|
||||||
addresses = []
|
addresses = []
|
||||||
gpg = self.query_lp_rest_api(person + '/gpg_keys', {})
|
try:
|
||||||
for key in gpg['entries']:
|
gpg = self.query_lp_rest_api(person + '/gpg_keys', {})
|
||||||
details = self.query_rest_api('http://keyserver.ubuntu.com/pks/lookup', {
|
for key in gpg['entries']:
|
||||||
'op': 'index',
|
details = self.query_rest_api('http://keyserver.ubuntu.com/pks/lookup', {
|
||||||
'search': '0x' + key['fingerprint'],
|
'op': 'index',
|
||||||
'exact': 'on',
|
'search': '0x' + key['fingerprint'],
|
||||||
'options': 'mr',
|
'exact': 'on',
|
||||||
})
|
'options': 'mr',
|
||||||
for line in details.splitlines():
|
})
|
||||||
parts = line.split(':')
|
for line in details.splitlines():
|
||||||
if parts[0] == 'info':
|
parts = line.split(':')
|
||||||
if int(parts[1]) != 1 or int(parts[2]) > 1:
|
if parts[0] == 'info':
|
||||||
break
|
if int(parts[1]) != 1 or int(parts[2]) > 1:
|
||||||
if parts[0] == 'uid':
|
break
|
||||||
flags = parts[4]
|
if parts[0] == 'uid':
|
||||||
if 'e' in flags or 'r' in flags:
|
flags = parts[4]
|
||||||
continue
|
if 'e' in flags or 'r' in flags:
|
||||||
uid = unquote(parts[1])
|
continue
|
||||||
match = re.match(r'^.*<(.+@.+)>$', uid)
|
uid = unquote(parts[1])
|
||||||
if match:
|
match = re.match(r'^.*<(.+@.+)>$', uid)
|
||||||
addresses.append(match.group(1))
|
if match:
|
||||||
address = self.addresses[person] = address_chooser(addresses)
|
addresses.append(match.group(1))
|
||||||
return address
|
address = self.addresses[person] = address_chooser(addresses)
|
||||||
|
return address
|
||||||
|
except HTTPError as e:
|
||||||
|
if e.code != 410: # suspended user
|
||||||
|
raise
|
||||||
|
self.log('Ignoring person %s as suspended in Launchpad' % person)
|
||||||
|
return None
|
||||||
|
|
||||||
def scrape_gpg_emails(self, people):
|
def scrape_gpg_emails(self, people):
|
||||||
"""Find email addresses from GPG keys."""
|
"""Find email addresses from GPG keys."""
|
||||||
return [self._scrape_gpg_emails(person) for person in (people or [])]
|
emails = [self._scrape_gpg_emails(person) for person in (people or [])]
|
||||||
|
return [email for email in emails if email is not None]
|
||||||
|
|
||||||
def lp_get_emails(self, pkg, version):
|
def lp_get_emails(self, pkg, version):
|
||||||
"""Ask LP who uploaded this package."""
|
"""Ask LP who uploaded this package."""
|
||||||
@ -225,7 +233,7 @@ class EmailPolicy(BasePolicy, Rest):
|
|||||||
msg = MESSAGE.format(**locals())
|
msg = MESSAGE.format(**locals())
|
||||||
try:
|
try:
|
||||||
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, recipients))
|
||||||
server = smtplib.SMTP(self.email_host)
|
server = smtplib.SMTP(self.email_host)
|
||||||
server.sendmail('noreply@canonical.com', emails, msg)
|
server.sendmail('noreply@canonical.com', emails, msg)
|
||||||
server.quit()
|
server.quit()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user