134 lines
5.3 KiB
Python
Executable file
134 lines
5.3 KiB
Python
Executable file
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
# -*- Python -*-
|
|
#
|
|
# $Id: generate-wg-aliases $
|
|
#
|
|
# Author: Markus Stenberg <markus.stenberg@iki.fi>
|
|
#
|
|
"""
|
|
This script requires that the proper virtual python environment has been
|
|
invoked before start.
|
|
|
|
|
|
This code dumps Django model IETFWG's contents as two sets of postfix
|
|
mail lists: -ads, and -chairs
|
|
|
|
"""
|
|
|
|
# boilerplate (from various other ietf/bin scripts)
|
|
import io, os, sys
|
|
|
|
filename = os.path.abspath(__file__)
|
|
basedir = os.path.abspath(os.path.join(os.path.dirname(__file__), "../.."))
|
|
sys.path = [ basedir ] + sys.path
|
|
os.environ["DJANGO_SETTINGS_MODULE"] = "ietf.settings"
|
|
|
|
import django
|
|
django.setup()
|
|
|
|
from django.conf import settings
|
|
|
|
import debug # pyflakes:ignore
|
|
|
|
from ietf.group.models import Group
|
|
from ietf.group.utils import get_group_ad_emails, get_group_role_emails, get_child_group_role_emails
|
|
from ietf.name.models import GroupTypeName
|
|
from ietf.utils.aliases import dump_sublist
|
|
|
|
# from secr/utils/group.py..
|
|
ACTIVE_STATES=['active', 'bof', 'proposed']
|
|
|
|
if __name__ == '__main__':
|
|
import datetime
|
|
import time
|
|
|
|
# Year ago?
|
|
#show_since = datetime.datetime.now() - datetime.timedelta(365)
|
|
|
|
# 2 years ago?
|
|
#show_since = datetime.datetime.now() - datetime.timedelta(2 * 365)
|
|
|
|
# 3 years ago?
|
|
#show_since = datetime.datetime.now() - datetime.timedelta(3 * 365)
|
|
|
|
# 5 years ago?
|
|
show_since = datetime.datetime.now() - datetime.timedelta(5 * 365)
|
|
|
|
date = time.strftime("%Y-%m-%d_%H:%M:%S")
|
|
signature = '# Generated by %s at %s\n' % (filename, date)
|
|
|
|
afile = io.open(settings.GROUP_ALIASES_PATH, "w")
|
|
vfile = io.open(settings.GROUP_VIRTUAL_PATH, "w")
|
|
|
|
afile.write(signature)
|
|
vfile.write(signature)
|
|
vfile.write("%s anything\n" % settings.GROUP_VIRTUAL_DOMAIN)
|
|
|
|
# - Working groups -----------------------------------------
|
|
wgs = Group.objects.filter(type='wg').all()
|
|
|
|
# - status = Active
|
|
active_wgs = wgs.filter(state__in=ACTIVE_STATES)
|
|
|
|
# - activity within last year? (use concluded_date)
|
|
inactive_recent_wgs = wgs.exclude(state__in=ACTIVE_STATES).filter(time__gte=show_since)
|
|
interesting_wgs = active_wgs | inactive_recent_wgs
|
|
|
|
for wg in interesting_wgs.distinct().iterator():
|
|
name = wg.acronym
|
|
dump_sublist(afile, vfile, name+'-ads', ['ietf.org', ], settings.GROUP_VIRTUAL_DOMAIN, get_group_ad_emails(wg))
|
|
dump_sublist(afile, vfile, name+'-chairs', ['ietf.org', ], settings.GROUP_VIRTUAL_DOMAIN, get_group_role_emails(wg, ['chair', 'secr']))
|
|
|
|
# - Research groups -----------------------------------------
|
|
rgs = Group.objects.filter(type='rg').all()
|
|
|
|
# - status = Active
|
|
active_rgs = rgs.filter(state__in=ACTIVE_STATES)
|
|
|
|
# - activity within last year? (use concluded_date)
|
|
inactive_recent_rgs = rgs.exclude(state__in=ACTIVE_STATES).filter(time__gte=show_since)
|
|
interesting_rgs = active_rgs | inactive_recent_rgs
|
|
|
|
for rg in interesting_rgs.distinct().iterator():
|
|
name = rg.acronym
|
|
#dump_sublist('%s%s' % (name, '-ads'), get_group_ad_emails, rg, True)
|
|
dump_sublist(afile, vfile, name+'-chairs', ['ietf.org', 'irtf.org', ], settings.GROUP_VIRTUAL_DOMAIN, get_group_role_emails(rg, ['chair', 'secr']))
|
|
|
|
# - Directorates -----------------------------------------
|
|
directorates = Group.objects.filter(type='dir').all()
|
|
|
|
# - status = Active
|
|
active_directorates = directorates.filter(state__in=ACTIVE_STATES)
|
|
|
|
# - activity within last year? (use concluded_date)
|
|
inactive_recent_directorates = directorates.exclude(state__in=ACTIVE_STATES).filter(time__gte=show_since)
|
|
interesting_directorates = active_directorates | inactive_recent_directorates
|
|
|
|
for directorate in interesting_directorates.distinct().iterator():
|
|
name = directorate.acronym
|
|
dump_sublist(afile, vfile, name+'-ads', ['ietf.org', ], settings.GROUP_VIRTUAL_DOMAIN, get_group_ad_emails(directorate))
|
|
dump_sublist(afile, vfile, name+'-chairs', ['ietf.org', ], settings.GROUP_VIRTUAL_DOMAIN, get_group_role_emails(directorate, ['chair', 'secr']))
|
|
|
|
# - Areas --------------------------------------------------
|
|
# Additionally, for areas, we should list -ads and -chairs
|
|
# (for every chair in active groups within the area).
|
|
areas = Group.objects.filter(type='area').all()
|
|
active_areas = areas.filter(state__in=ACTIVE_STATES)
|
|
for area in active_areas:
|
|
name = area.acronym
|
|
area_ad_emails = get_group_role_emails(area, ['pre-ad', 'ad', 'chair'])
|
|
dump_sublist(afile, vfile, name+'-ads' , ['ietf.org', ], settings.GROUP_VIRTUAL_DOMAIN, area_ad_emails)
|
|
dump_sublist(afile, vfile, name+'-chairs', ['ietf.org', ], settings.GROUP_VIRTUAL_DOMAIN, (get_child_group_role_emails(area, ['chair', 'secr']) | area_ad_emails))
|
|
|
|
|
|
# - Special groups --------------------------------------------------
|
|
# We need to be able to send mail to chairs of groups that require
|
|
# group draft submission approval and don't otherwise have aliases
|
|
gtypes = GroupTypeName.objects.values_list('slug', flat=True)
|
|
special_groups = Group.objects.filter(type__features__req_subm_approval=True, acronym__in=gtypes, state='active')
|
|
for group in special_groups:
|
|
dump_sublist(afile, vfile, group.acronym+'-chairs', ['ietf.org', ], settings.GROUP_VIRTUAL_DOMAIN, get_group_role_emails(group, ['chair', 'delegate']))
|
|
|
|
|