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
|
#! @PYTHON@
#
# Copyright (C) 2002-2018 by the Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
"""List the owners of a mailing list, or all mailing lists.
Usage: %(PROGRAM)s [options] [listname ...]
Options:
-w / --with-listnames
Group the owners by list names and include the list names in the
output. Otherwise, the owners will be sorted and uniquified based on
the email address.
-m / --moderators
Include the list moderators in the output.
-h / --help
Print this help message and exit.
listname
Print the owners of the specified lists. More than one can appear
after the options. If there are no listnames provided, the owners of
all the lists will be displayed.
"""
import sys
import getopt
import paths
from Mailman import Utils
from Mailman.MailList import MailList
from Mailman.i18n import C_
PROGRAM = sys.argv[0]
try:
True, False
except NameError:
True = 1
False = 0
def usage(code, msg=''):
if code:
fd = sys.stderr
else:
fd = sys.stdout
print >> fd, C_(__doc__)
if msg:
print >> fd, msg
sys.exit(code)
def main():
try:
opts, args = getopt.getopt(sys.argv[1:], 'wmh',
['with-listnames', 'moderators', 'help'])
except getopt.error, msg:
usage(1, msg)
withnames = moderators = False
for opt, arg in opts:
if opt in ('-h', '--help'):
usage(0)
elif opt in ('-m', '--moderators'):
moderators = True
elif opt in ('-w', '--with-listnames'):
withnames = True
listnames = [x.lower() for x in args] or Utils.list_names()
bylist = {}
for listname in listnames:
mlist = MailList(listname, lock=0)
addrs = mlist.owner[:]
if moderators:
addrs.extend(mlist.moderator)
bylist[listname] = addrs
if withnames:
for listname in listnames:
unique = {}
for addr in bylist[listname]:
unique[addr] = 1
keys = unique.keys()
keys.sort()
print listname
for k in keys:
print '\t', k
else:
unique = {}
for listname in listnames:
for addr in bylist[listname]:
unique[addr] = 1
keys = unique.keys()
keys.sort()
for k in keys:
print k
if __name__ == '__main__':
main()
|