source: asadb/util/mailman.py @ 68c93e8

space-accessstablestage
Last change on this file since 68c93e8 was fb76571, checked in by Alex Dehnert <adehnert@…>, 14 years ago

Fix util/mailman.py's commas handling (Trac: #65)

Changes util/mailman.py and groups/diffs.py so that groups with names
including commas can be correctly added and removed from asa-official.

  • Property mode set to 100644
File size: 1.6 KB
Line 
1import subprocess
2
3MMBLANCHE_PATH="/mit/consult/bin/mmblanche"
4
5class MailmanList():
6    def __init__(self, name, ):
7        self.name = name
8
9    def list_members(self, ):
10        res = subprocess.Popen(
11            [MMBLANCHE_PATH, self.name, ],
12            stdout=subprocess.PIPE,
13            stderr=subprocess.PIPE,
14        )
15        stdout, stderr = res.communicate()
16        if res.returncode:
17            raise RuntimeError("Failed to list members: %s" % (stderr, ))
18        members = stdout.strip().split("\n")
19        return members
20
21    def change_members(self, add_members, delete_members, ):
22        """
23        Add and/or remove members from the list.
24        """
25
26        # Note that it passes all members on the commandline, so it shouldn't be
27        # used for large lists at the moment. OTOH, "large" appears to be
28        # 2M characters, so.
29        # If that becomes an issue, it should probably check the number of
30        # changes, and use -al / -dl with a tempfile as appropriate.
31
32        cmdline = [MMBLANCHE_PATH, self.name, ]
33        for member in add_members:
34            cmdline.append('-a')
35            if type(member) == type(()):
36                name, email = member
37                name = name.replace('"', "''")
38                member = '"%s" <%s>' % (name, email, )
39            cmdline.append(member)
40        for member in delete_members:
41            cmdline.append('-d')
42            cmdline.append(member)
43        res = subprocess.Popen(
44            cmdline,
45            stdout=subprocess.PIPE,
46            stderr=subprocess.PIPE,
47        )
48        stdout, stderr = res.communicate()
49        assert stderr==""
50        return stdout
Note: See TracBrowser for help on using the repository browser.