# Copyright (C) 2009 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. """Set, add and/or remove owners and/or moderators of lists. Save as bin/change_admins.py Run via bin/withlist -r change_admins ... to perform one or more actions on , or bin/withlist -a -r change_admins -- ... to do all lists. In either command is of the form
where target is one of 'o', 'owner', 'm' or 'moderator'; is '+', '-' or '=' and
is an email address. For example, an action of owner+a1@example.com will add a1@example.com to the list's owner attribute; m-a2@example.com will remove a2@example.com from the list's moderator attribute, and o=a3@example.com will set the list's owner attribute to a3@example.com. The argument may be repeated as many times as desired to add/remove multiple addresses. Requests to remove a non-existent address or add an address already present will be silently ignored. Addresses are case sensitive. Actions are processed in the order given on the command line. """ import re import sys are = re.compile('^(?P(o(wner)?|m(oderator)?))(?P[+-=])(?P\S+@\S+)$', re.IGNORECASE) def usage(code, msg=''): if code: fd = sys.stderr else: fd = sys.stdout print >> fd, __doc__ if msg: print >> fd, msg sys.exit(code) def change_admins(mlist, *args): if not mlist.Locked(): mlist.Lock() for arg in args: mo = are.search(arg) if not mo: usage(1, 'invalid argument: %s' % arg) if mo.group('target').lower().startswith('o'): target = mlist.owner else: target = mlist.moderator if mo.group('op') == '=': target[:] = [mo.group('addr')] else: if mo.group('op') == '-' and (mo.group('addr')) in target: target.remove(mo.group('addr')) elif mo.group('op') == '+' and (mo.group('addr')) not in target: target.append(mo.group('addr')) mlist.Save() mlist.Unlock()