Rewrote the draft-alias and group-alias generation scripts to generate matching aliases and virtual files for postfix.
- Legacy-Id: 8055
This commit is contained in:
parent
5f03888065
commit
a73163993a
|
@ -33,6 +33,7 @@ basedir = os.path.abspath(os.path.join(os.path.dirname(__file__), "../.."))
|
|||
sys.path = [ basedir ] + sys.path
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ietf.settings")
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
from ietf.doc.models import Document
|
||||
from ietf.group.utils import get_group_chairs_emails, get_group_ads_emails
|
||||
|
@ -65,7 +66,7 @@ def get_draft_notify_emails(draft):
|
|||
" Get list of email addresses to notify for the given draft."
|
||||
n = draft.notify
|
||||
if not n:
|
||||
return
|
||||
return []
|
||||
l = []
|
||||
draft_email = draft.name + DRAFT_EMAIL_SUFFIX
|
||||
for e in n.split(','):
|
||||
|
@ -92,7 +93,13 @@ if __name__ == '__main__':
|
|||
|
||||
modname = 'ietf.generate_draft_aliases'
|
||||
date = time.strftime("%Y-%m-%d_%H:%M:%S")
|
||||
print '# Generated by python -m %s at %s' % (modname, date)
|
||||
signature = '# Generated by python -m %s at %s\n' % (modname, date)
|
||||
|
||||
afile = open(settings.DRAFT_ALIASES_PATH, "w")
|
||||
vfile = open(settings.DRAFT_VIRTUAL_PATH, "w")
|
||||
|
||||
afile.write(signature)
|
||||
vfile.write(signature)
|
||||
|
||||
drafts = Document.objects.all()
|
||||
|
||||
|
@ -104,42 +111,44 @@ if __name__ == '__main__':
|
|||
|
||||
interesting_drafts = active_drafts | inactive_recent_drafts
|
||||
|
||||
count = 0
|
||||
for draft in interesting_drafts.distinct().iterator():
|
||||
# Omit RFCs, we care only about drafts
|
||||
if draft.docalias_set.filter(name__startswith='rfc'):
|
||||
continue
|
||||
name = draft.name
|
||||
done = []
|
||||
|
||||
count += 1
|
||||
if (count % 100) == 0:
|
||||
sys.stderr.write('.')
|
||||
alias = draft.name
|
||||
all = []
|
||||
def handle_sublist(name, f, o, is_ad=False):
|
||||
r = dump_sublist(name, f, o, is_ad)
|
||||
if r:
|
||||
done.append(name)
|
||||
all.extend(r)
|
||||
return r
|
||||
def handle_sublist(afile, vfile, alias, emails):
|
||||
try:
|
||||
all.extend( dump_sublist(afile, vfile, alias, emails) )
|
||||
except TypeError:
|
||||
import debug
|
||||
debug.show('alias')
|
||||
debug.show('emails')
|
||||
raise
|
||||
#.authors (/and no suffix) = authors
|
||||
|
||||
# First, do no suffix case
|
||||
# If no authors, don't generate list either
|
||||
r = dump_sublist(name, get_draft_authors_emails, draft)
|
||||
if not r:
|
||||
continue
|
||||
handle_sublist('%s%s' % (name, '.authors'), get_draft_authors_emails, draft)
|
||||
wg = draft.group
|
||||
handle_sublist(afile, vfile, alias, get_draft_authors_emails(draft))
|
||||
handle_sublist(afile, vfile, alias+'.authors', get_draft_authors_emails(draft))
|
||||
|
||||
if wg:
|
||||
# .chairs = WG chairs
|
||||
handle_sublist('%s%s' % (name, '.chairs'), get_group_chairs_emails, wg)
|
||||
# .chairs = group chairs
|
||||
if draft.group:
|
||||
handle_sublist(afile, vfile, alias+'.chairs', get_group_chairs_emails(draft.group))
|
||||
|
||||
# .ad = sponsoring AD / WG AD (WG document)
|
||||
handle_sublist('%s%s' % (name, '.ad'), get_draft_ad_emails, draft, True)
|
||||
handle_sublist(afile, vfile, alias+'.ad', get_draft_ad_emails(draft))
|
||||
|
||||
# .notify = notify email list from the Document
|
||||
handle_sublist('%s%s' % (name, '.notify'), get_draft_notify_emails, draft)
|
||||
handle_sublist(afile, vfile, alias+'.notify', get_draft_notify_emails(draft))
|
||||
|
||||
# .all = everything on 'done' (recursive aliases)
|
||||
#dump_sublist('%s%s' % (name, '.all'), None, done)
|
||||
# .all = everything on 'all' (expanded aliases)
|
||||
dump_sublist('%s%s' % (name, '.all'), None, all)
|
||||
handle_sublist(afile, vfile, alias+'.all', all)
|
||||
|
||||
|
||||
afile.close()
|
||||
vfile.close()
|
||||
|
|
@ -19,6 +19,7 @@ basedir = os.path.abspath(os.path.join(os.path.dirname(__file__), "../.."))
|
|||
sys.path = [ basedir ] + sys.path
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ietf.settings")
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
from ietf.group.models import Group
|
||||
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__':
|
|||
|
||||
modname = 'ietf.generate_wg_aliases'
|
||||
date = time.strftime("%Y-%m-%d_%H:%M:%S")
|
||||
print '# Generated by python -m %s at %s' % (modname, date)
|
||||
signature = '# Generated by python -m %s at %s\n' % (modname, date)
|
||||
|
||||
afile = open(settings.GROUP_ALIASES_PATH, "w")
|
||||
vfile = open(settings.GROUP_VIRTUAL_PATH, "w")
|
||||
|
||||
afile.write(signature)
|
||||
vfile.write(signature)
|
||||
|
||||
wgs = Group.objects.filter(type='wg').all()
|
||||
|
||||
print '# WGs'
|
||||
|
@ -59,8 +67,8 @@ if __name__ == '__main__':
|
|||
|
||||
for wg in interesting_wgs.distinct().iterator():
|
||||
name = wg.acronym
|
||||
dump_sublist('%s%s' % (name, '-ads'), get_group_ads_emails, wg, True)
|
||||
dump_sublist('%s%s' % (name, '-chairs'), get_group_chairs_emails, wg)
|
||||
dump_sublist(afile, vfile, name+'-ads' , get_group_ads_emails(wg))
|
||||
dump_sublist(afile, vfile, name+'-chairs', get_group_chairs_emails(wg))
|
||||
|
||||
print '# RGs'
|
||||
# - status = Active
|
||||
|
@ -74,7 +82,7 @@ if __name__ == '__main__':
|
|||
for rg in interesting_rgs.distinct().iterator():
|
||||
name = rg.acronym
|
||||
#dump_sublist('%s%s' % (name, '-ads'), get_group_ads_emails, rg, True)
|
||||
dump_sublist('%s%s' % (name, '-chairs'), get_group_chairs_emails, rg)
|
||||
dump_sublist(afile, vfile, name+'-chairs', get_group_chairs_emails(rg))
|
||||
|
||||
# Additionally, for areaz, we should list -ads and -chairs
|
||||
# (for every chair in active groups within the area).
|
||||
|
@ -83,7 +91,6 @@ if __name__ == '__main__':
|
|||
active_areas = areas.filter(state__in=ACTIVE_STATES)
|
||||
for area in active_areas:
|
||||
name = area.acronym
|
||||
dump_sublist('%s%s' % (name, '-ads'), get_area_ads_emails, area, True)
|
||||
dump_sublist('%s%s' % (name, '-chairs'), get_area_chairs_emails, area)
|
||||
|
||||
dump_sublist(afile, vfile, name+'-ads' , get_area_ads_emails(area))
|
||||
dump_sublist(afile, vfile, name+'-chairs', get_area_chairs_emails(area))
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ def get_group_chairs_emails(wg):
|
|||
emails = Email.objects.filter(role__group=wg,
|
||||
role__name='chair')
|
||||
if not emails:
|
||||
return
|
||||
return []
|
||||
emails = [e.email_address() for e in emails]
|
||||
emails = filter(None, emails)
|
||||
return emails
|
||||
|
|
|
@ -439,6 +439,15 @@ BADNESS_MUCHTOOBIG = 500
|
|||
SELENIUM_TESTS = False
|
||||
SELENIUM_TESTS_ONLY = False
|
||||
|
||||
# Path to the email alias lists. Used by ietf.utils.aliases
|
||||
DRAFT_ALIASES_PATH = "/a/postfix/draft-aliases"
|
||||
DRAFT_VIRTUAL_PATH = "/a/postfix/draft-virtual"
|
||||
|
||||
GROUP_ALIASES_PATH = "/a/postfix/group-aliases"
|
||||
GROUP_VIRTUAL_PATH = "/a/postfix/group-virtual"
|
||||
|
||||
POSTCONFIRM_PATH = "/a/postconfirm/test-wrapper"
|
||||
|
||||
# Put the production SECRET_KEY in settings_local.py, and also any other
|
||||
# sensitive or site-specific changes. DO NOT commit settings_local.py to svn.
|
||||
from settings_local import * # pyflakes:ignore
|
||||
|
|
|
@ -12,7 +12,9 @@ Mailing list alias dumping utilities
|
|||
|
||||
"""
|
||||
|
||||
def rewrite_email_address(email, is_ad):
|
||||
from django.conf import settings
|
||||
|
||||
def rewrite_email_address(email):
|
||||
""" Prettify the email address (and if it's empty, skip it by
|
||||
returning None). """
|
||||
if not email:
|
||||
|
@ -38,32 +40,35 @@ def rewrite_address_list(l):
|
|||
h[address] = True
|
||||
yield address
|
||||
|
||||
def dump_sublist(alias, f, wg, is_adlist=False):
|
||||
if f:
|
||||
l = f(wg)
|
||||
else:
|
||||
l = wg
|
||||
if not l:
|
||||
return
|
||||
def dump_sublist(afile, vfile, alias, emails):
|
||||
if not emails:
|
||||
return emails
|
||||
# Nones in the list should be skipped
|
||||
l = filter(None, l)
|
||||
emails = filter(None, emails)
|
||||
|
||||
# Make sure emails are sane and eliminate the Nones again for
|
||||
# non-sane ones
|
||||
l = [rewrite_email_address(e, is_adlist) for e in l]
|
||||
l = filter(None, l)
|
||||
emails = [rewrite_email_address(e) for e in emails]
|
||||
emails = filter(None, emails)
|
||||
|
||||
# And we'll eliminate the duplicates too but preserve order
|
||||
l = list(rewrite_address_list(l))
|
||||
if not l:
|
||||
return
|
||||
emails = list(rewrite_address_list(emails))
|
||||
if not emails:
|
||||
return emails
|
||||
try:
|
||||
print '%s: %s' % (alias, ', '.join(l))
|
||||
virtualname = 'xalias-%s' % (alias, )
|
||||
expandname = 'expand-%s' % (alias)
|
||||
aliasaddr = '%s@ietf.org' % (alias, )
|
||||
|
||||
vfile.write('%-64s %s\n' % (aliasaddr, virtualname))
|
||||
afile.write('%-64s "|%s filter %s"\n' % (virtualname+':', settings.POSTCONFIRM_PATH, expandname))
|
||||
afile.write('%-64s %s\n' % (expandname+':', ', '.join(emails)))
|
||||
|
||||
except UnicodeEncodeError:
|
||||
# If there's unicode in email address, something is badly
|
||||
# wrong and we just silently punt
|
||||
# XXX - is there better approach?
|
||||
print '# Error encoding', alias, repr(l)
|
||||
return
|
||||
return l
|
||||
print '# Error encoding', alias, repr(emails)
|
||||
return []
|
||||
return emails
|
||||
|
||||
|
|
Loading…
Reference in a new issue