Skip to content

Commit 9f44b9a

Browse files
committed
Additional tweaks to the mailman listinfo importer.
- Legacy-Id: 13710
1 parent ce1b655 commit 9f44b9a

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

ietf/mailinglists/management/commands/import_mailman_listinfo.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from django.conf import settings
99
from django.core.management.base import BaseCommand
10+
from django.core.exceptions import MultipleObjectsReturned
1011

1112
sys.path.append(settings.MAILMAN_LIB_DIR)
1213

@@ -31,12 +32,14 @@ def note(msg):
3132
note("Could not import mailman modules -- skipping import of mailman list info")
3233
return
3334

34-
for name in Utils.list_names():
35+
names = list(Utils.list_names())
36+
names.sort()
37+
for name in names:
3538
mlist = MailList.MailList(name, lock=False)
3639
note("List: %s" % mlist.internal_name())
3740
if mlist.advertised:
3841
description = mlist.description.decode('latin1')[:256]
39-
list, created = List.objects.get_or_create(name=mlist.real_name, description=description, advertised=mlist.advertised)
42+
mmlist, created = List.objects.get_or_create(name=mlist.real_name, description=description, advertised=mlist.advertised)
4043
# The following calls return lowercased addresses
4144
members = mlist.getRegularMemberKeys() + mlist.getDigestMemberKeys()
4245
members = [ m for m in members if mlist.getDeliveryStatus(m) == MemberAdaptor.ENABLED ]
@@ -45,18 +48,22 @@ def note(msg):
4548
if not addr in members:
4649
note(" Removing subscription: %s" % (addr))
4750
old = Subscribed.objects.get(email=addr)
48-
old.lists.remove(list)
51+
old.lists.remove(mmlist)
4952
if old.lists.count() == 0:
5053
note(" Removing address with no subscriptions: %s" % (addr))
5154
old.delete()
5255
for addr in members:
5356
if len(addr) > 64:
54-
sys.stderr.write("Email address subscribed to '%s' too long for table: <%s>" % (name, addr))
57+
sys.stderr.write(" ** Email address subscribed to '%s' too long for table: <%s>\n" % (name, addr))
5558
continue
5659
if not addr in known:
5760
note(" Adding subscription: %s" % (addr))
58-
new, created = Subscribed.objects.get_or_create(email=addr)
59-
new.lists.add(list)
61+
try:
62+
new, created = Subscribed.objects.get_or_create(email=addr)
63+
except MultipleObjectsReturned as e:
64+
sys.stderr.write(" ** Error handling %s in %s: %s\n" % (addr, name, e))
65+
continue
66+
new.lists.add(mmlist)
6067

6168

6269
class Command(BaseCommand):

0 commit comments

Comments
 (0)