import sys import getopt from Mailman import mm_cfg 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 set_mod(mlist, *args): try: opts, args = getopt.getopt(args, 'su', ['set', 'unset']) except getopt.error, msg: usage(1, msg) action = None for opt, arg in opts: if opt in ('-s', '--set'): if action in (0, 1): usage(1, 'Exactly one of -s, --set, -u, --unset required') action = 1 if opt in ('-u', '--unset'): if action in (0, 1): usage(1, 'Exactly one of -s, --set, -u, --unset required') action = 0 if action == None: usage(1, 'Exactly one of -s, --set, -u, --unset required') if not args: usage(1, 'Member address is required') if not mlist.Locked(): mlist.Lock() for member in args: mlist.setMemberOption(member, mm_cfg.Moderate, action) mlist.Save() mlist.Unlock()