-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathaddmembers.py
More file actions
executable file
·90 lines (69 loc) · 2.38 KB
/
addmembers.py
File metadata and controls
executable file
·90 lines (69 loc) · 2.38 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
#!/usr/bin/python3
"""Add members to a list from the command line.
(SRCF wrapper around Mailman's add_members, but note different options.)
Usage: srcf-mailman-add [options] listname
Options:
--digest
-d
New members will be added as digest members, rather than the
non-digest members as is the default.
--welcome-msg=<y|n>
-w <y|n>
Set whether or not to send the list members a welcome message,
overriding whatever the list's `send_welcome_msg' setting is.
--admin-notify=<y|n>
-a <y|n>
Set whether or not to send the list administrators a notification on
the success/failure of these subscriptions, overriding whatever the
list's `admin_notify_mchanges' setting is.
--help
-h
Print this help message and exit.
listname
The name of the Mailman list you are adding members to. It must
already exist.
The list of addresses to add is read from stdin.
"""
import sys
import getopt
import os
from srcfmailmanwrapper import util
def main():
targetscript = "/usr/lib/mailman/bin/add_members"
shortopts = "dw:a:h"
longopts = ["digest", "welcome-msg=", "admin-notify=", "help"]
try:
opts, args = getopt.gnu_getopt(sys.argv[1:], shortopts, longopts)
except getopt.error as e:
raise util.GetoptError(e)
mailmanargs = [targetscript]
type = "-r"
for opt, arg in opts:
if opt in ("-h", "--help"):
print(__doc__)
sys.exit(0)
elif opt in ("-d", "--digest"):
type = "-d"
elif opt in ("-w", "--welcome-msg"):
if arg not in ("y", "n"):
raise util.InvalidArgumentValueError(opt, arg)
mailmanargs += ["-w", arg]
elif opt in ("-a", "--admin-notify"):
if arg not in ("y", "n"):
raise util.InvalidArgumentValueError(opt, arg)
mailmanargs += ["-a", arg]
else:
# only reached if we missed something above
raise util.UnhandledArgumentError(opt)
mailmanargs += [type, "-", util.getlistname(args)]
if (len(args) > 0):
raise util.TooManyArgsError()
os.execv(targetscript, mailmanargs)
if __name__ == "__main__":
try:
main()
except util.Error as e:
print(e)
if e.printusage:
print("-----\n%s" % __doc__, file=sys.stderr)
sys.exit(1)