Skip to content

Commit a731639

Browse files
committed
Rewrote the draft-alias and group-alias generation scripts to generate matching aliases and virtual files for postfix.
- Legacy-Id: 8055
1 parent 5f03888 commit a731639

5 files changed

Lines changed: 81 additions & 51 deletions

File tree

ietf/bin/generate-draft-aliases

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ basedir = os.path.abspath(os.path.join(os.path.dirname(__file__), "../.."))
3333
sys.path = [ basedir ] + sys.path
3434
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ietf.settings")
3535

36+
from django.conf import settings
3637

3738
from ietf.doc.models import Document
3839
from ietf.group.utils import get_group_chairs_emails, get_group_ads_emails
@@ -65,7 +66,7 @@ def get_draft_notify_emails(draft):
6566
" Get list of email addresses to notify for the given draft."
6667
n = draft.notify
6768
if not n:
68-
return
69+
return []
6970
l = []
7071
draft_email = draft.name + DRAFT_EMAIL_SUFFIX
7172
for e in n.split(','):
@@ -92,7 +93,13 @@ if __name__ == '__main__':
9293

9394
modname = 'ietf.generate_draft_aliases'
9495
date = time.strftime("%Y-%m-%d_%H:%M:%S")
95-
print '# Generated by python -m %s at %s' % (modname, date)
96+
signature = '# Generated by python -m %s at %s\n' % (modname, date)
97+
98+
afile = open(settings.DRAFT_ALIASES_PATH, "w")
99+
vfile = open(settings.DRAFT_VIRTUAL_PATH, "w")
100+
101+
afile.write(signature)
102+
vfile.write(signature)
96103

97104
drafts = Document.objects.all()
98105

@@ -104,42 +111,44 @@ if __name__ == '__main__':
104111

105112
interesting_drafts = active_drafts | inactive_recent_drafts
106113

114+
count = 0
107115
for draft in interesting_drafts.distinct().iterator():
108116
# Omit RFCs, we care only about drafts
109117
if draft.docalias_set.filter(name__startswith='rfc'):
110118
continue
111-
name = draft.name
112-
done = []
119+
120+
count += 1
121+
if (count % 100) == 0:
122+
sys.stderr.write('.')
123+
alias = draft.name
113124
all = []
114-
def handle_sublist(name, f, o, is_ad=False):
115-
r = dump_sublist(name, f, o, is_ad)
116-
if r:
117-
done.append(name)
118-
all.extend(r)
119-
return r
125+
def handle_sublist(afile, vfile, alias, emails):
126+
try:
127+
all.extend( dump_sublist(afile, vfile, alias, emails) )
128+
except TypeError:
129+
import debug
130+
debug.show('alias')
131+
debug.show('emails')
132+
raise
120133
#.authors (/and no suffix) = authors
121-
122134
# First, do no suffix case
123-
# If no authors, don't generate list either
124-
r = dump_sublist(name, get_draft_authors_emails, draft)
125-
if not r:
126-
continue
127-
handle_sublist('%s%s' % (name, '.authors'), get_draft_authors_emails, draft)
128-
wg = draft.group
135+
handle_sublist(afile, vfile, alias, get_draft_authors_emails(draft))
136+
handle_sublist(afile, vfile, alias+'.authors', get_draft_authors_emails(draft))
129137

130-
if wg:
131-
# .chairs = WG chairs
132-
handle_sublist('%s%s' % (name, '.chairs'), get_group_chairs_emails, wg)
138+
# .chairs = group chairs
139+
if draft.group:
140+
handle_sublist(afile, vfile, alias+'.chairs', get_group_chairs_emails(draft.group))
133141

134142
# .ad = sponsoring AD / WG AD (WG document)
135-
handle_sublist('%s%s' % (name, '.ad'), get_draft_ad_emails, draft, True)
143+
handle_sublist(afile, vfile, alias+'.ad', get_draft_ad_emails(draft))
136144

137145
# .notify = notify email list from the Document
138-
handle_sublist('%s%s' % (name, '.notify'), get_draft_notify_emails, draft)
146+
handle_sublist(afile, vfile, alias+'.notify', get_draft_notify_emails(draft))
139147

140-
# .all = everything on 'done' (recursive aliases)
141-
#dump_sublist('%s%s' % (name, '.all'), None, done)
142148
# .all = everything on 'all' (expanded aliases)
143-
dump_sublist('%s%s' % (name, '.all'), None, all)
149+
handle_sublist(afile, vfile, alias+'.all', all)
144150

145151

152+
afile.close()
153+
vfile.close()
154+

ietf/bin/generate-wg-aliases

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ basedir = os.path.abspath(os.path.join(os.path.dirname(__file__), "../.."))
1919
sys.path = [ basedir ] + sys.path
2020
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ietf.settings")
2121

22+
from django.conf import settings
2223

2324
from ietf.group.models import Group
2425
from ietf.group.utils import get_group_ads_emails, get_group_chairs_emails, get_area_ads_emails, get_area_chairs_emails
@@ -46,7 +47,14 @@ if __name__ == '__main__':
4647

4748
modname = 'ietf.generate_wg_aliases'
4849
date = time.strftime("%Y-%m-%d_%H:%M:%S")
49-
print '# Generated by python -m %s at %s' % (modname, date)
50+
signature = '# Generated by python -m %s at %s\n' % (modname, date)
51+
52+
afile = open(settings.GROUP_ALIASES_PATH, "w")
53+
vfile = open(settings.GROUP_VIRTUAL_PATH, "w")
54+
55+
afile.write(signature)
56+
vfile.write(signature)
57+
5058
wgs = Group.objects.filter(type='wg').all()
5159

5260
print '# WGs'
@@ -59,8 +67,8 @@ if __name__ == '__main__':
5967

6068
for wg in interesting_wgs.distinct().iterator():
6169
name = wg.acronym
62-
dump_sublist('%s%s' % (name, '-ads'), get_group_ads_emails, wg, True)
63-
dump_sublist('%s%s' % (name, '-chairs'), get_group_chairs_emails, wg)
70+
dump_sublist(afile, vfile, name+'-ads' , get_group_ads_emails(wg))
71+
dump_sublist(afile, vfile, name+'-chairs', get_group_chairs_emails(wg))
6472

6573
print '# RGs'
6674
# - status = Active
@@ -74,7 +82,7 @@ if __name__ == '__main__':
7482
for rg in interesting_rgs.distinct().iterator():
7583
name = rg.acronym
7684
#dump_sublist('%s%s' % (name, '-ads'), get_group_ads_emails, rg, True)
77-
dump_sublist('%s%s' % (name, '-chairs'), get_group_chairs_emails, rg)
85+
dump_sublist(afile, vfile, name+'-chairs', get_group_chairs_emails(rg))
7886

7987
# Additionally, for areaz, we should list -ads and -chairs
8088
# (for every chair in active groups within the area).
@@ -83,7 +91,6 @@ if __name__ == '__main__':
8391
active_areas = areas.filter(state__in=ACTIVE_STATES)
8492
for area in active_areas:
8593
name = area.acronym
86-
dump_sublist('%s%s' % (name, '-ads'), get_area_ads_emails, area, True)
87-
dump_sublist('%s%s' % (name, '-chairs'), get_area_chairs_emails, area)
88-
94+
dump_sublist(afile, vfile, name+'-ads' , get_area_ads_emails(area))
95+
dump_sublist(afile, vfile, name+'-chairs', get_area_chairs_emails(area))
8996

ietf/group/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def get_group_chairs_emails(wg):
7070
emails = Email.objects.filter(role__group=wg,
7171
role__name='chair')
7272
if not emails:
73-
return
73+
return []
7474
emails = [e.email_address() for e in emails]
7575
emails = filter(None, emails)
7676
return emails

ietf/settings.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,15 @@ def skip_suspicious_operations(record):
439439
SELENIUM_TESTS = False
440440
SELENIUM_TESTS_ONLY = False
441441

442+
# Path to the email alias lists. Used by ietf.utils.aliases
443+
DRAFT_ALIASES_PATH = "/a/postfix/draft-aliases"
444+
DRAFT_VIRTUAL_PATH = "/a/postfix/draft-virtual"
445+
446+
GROUP_ALIASES_PATH = "/a/postfix/group-aliases"
447+
GROUP_VIRTUAL_PATH = "/a/postfix/group-virtual"
448+
449+
POSTCONFIRM_PATH = "/a/postconfirm/test-wrapper"
450+
442451
# Put the production SECRET_KEY in settings_local.py, and also any other
443452
# sensitive or site-specific changes. DO NOT commit settings_local.py to svn.
444453
from settings_local import * # pyflakes:ignore

ietf/utils/aliases.py

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
1313
"""
1414

15-
def rewrite_email_address(email, is_ad):
15+
from django.conf import settings
16+
17+
def rewrite_email_address(email):
1618
""" Prettify the email address (and if it's empty, skip it by
1719
returning None). """
1820
if not email:
@@ -38,32 +40,35 @@ def rewrite_address_list(l):
3840
h[address] = True
3941
yield address
4042

41-
def dump_sublist(alias, f, wg, is_adlist=False):
42-
if f:
43-
l = f(wg)
44-
else:
45-
l = wg
46-
if not l:
47-
return
43+
def dump_sublist(afile, vfile, alias, emails):
44+
if not emails:
45+
return emails
4846
# Nones in the list should be skipped
49-
l = filter(None, l)
47+
emails = filter(None, emails)
5048

5149
# Make sure emails are sane and eliminate the Nones again for
5250
# non-sane ones
53-
l = [rewrite_email_address(e, is_adlist) for e in l]
54-
l = filter(None, l)
51+
emails = [rewrite_email_address(e) for e in emails]
52+
emails = filter(None, emails)
5553

5654
# And we'll eliminate the duplicates too but preserve order
57-
l = list(rewrite_address_list(l))
58-
if not l:
59-
return
55+
emails = list(rewrite_address_list(emails))
56+
if not emails:
57+
return emails
6058
try:
61-
print '%s: %s' % (alias, ', '.join(l))
59+
virtualname = 'xalias-%s' % (alias, )
60+
expandname = 'expand-%s' % (alias)
61+
aliasaddr = '%s@ietf.org' % (alias, )
62+
63+
vfile.write('%-64s %s\n' % (aliasaddr, virtualname))
64+
afile.write('%-64s "|%s filter %s"\n' % (virtualname+':', settings.POSTCONFIRM_PATH, expandname))
65+
afile.write('%-64s %s\n' % (expandname+':', ', '.join(emails)))
66+
6267
except UnicodeEncodeError:
6368
# If there's unicode in email address, something is badly
6469
# wrong and we just silently punt
6570
# XXX - is there better approach?
66-
print '# Error encoding', alias, repr(l)
67-
return
68-
return l
71+
print '# Error encoding', alias, repr(emails)
72+
return []
73+
return emails
6974

0 commit comments

Comments
 (0)