forked from adamlaska/datatracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-wg-aliases
More file actions
executable file
·147 lines (108 loc) · 5.94 KB
/
Copy pathgenerate-wg-aliases
File metadata and controls
executable file
·147 lines (108 loc) · 5.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/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']))
# - Teams -----------------------------------------
teams = Group.objects.filter(type='team').all()
# - status = Active
active_teams = teams.filter(state__in=ACTIVE_STATES)
# - activity within last year? (use concluded_date)
inactive_recent_teams = teams.exclude(state__in=ACTIVE_STATES).filter(time__gte=show_since)
interesting_teams = active_teams | inactive_recent_teams
for team in interesting_teams.distinct().iterator():
name = team.acronym
dump_sublist(afile, vfile, name+'-chairs', ['ietf.org', ], settings.GROUP_VIRTUAL_DOMAIN, get_group_role_emails(team, ['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']))