[Mailman-Developers] update of my remove_members patch against CVS version

Marc MERLIN marc_news@vasoftware.com
Wed, 12 Dec 2001 09:13:54 -0800


Barry, this never made it into 2.0.x

Any chance it could make it into CVS?
(I've updated
https://sourceforge.net/tracker/index.php?func=detail&aid=413257&group_id=103&atid=300103
)

Marc

--- remove_members.mailman	Wed Dec 12 08:57:41 2001
+++ remove_members	Wed Dec 12 08:57:38 2001
@@ -37,6 +37,8 @@
         Print this help message and exit.
 
     listname is the name of the mailing list to use.
+	(_alllists_' is a special list name that checks all the lists for the
+	Emails to remove)
 
     addr1 ... are additional addresses to remove.
 
@@ -47,6 +49,7 @@
 
 import paths
 from Mailman import MailList
+from Mailman import Utils
 from Mailman import Errors
 from Mailman.i18n import _
 
@@ -84,7 +87,12 @@
     if len(args) < 1:
         usage(1)
 
-    listname = args[0].lower().strip()
+    rlistname = args[0].lower().strip()
+    if rlistname == "_alllists_":
+	listnames = Utils.list_names()
+    else:
+	listnames = []
+	listnames.append(rlistname)
     addresses = args[1:]
     filename = None
     all = 0
@@ -103,26 +111,32 @@
         except IOError:
             print _('Could not open file for reading: %(filename)s.')
 
-    try:
-        # open locked
-        mlist = MailList.MailList(listname)
-    except Errors.MMListError, e:
-        print _('No such list: %(listname)s')
-        sys.exit(1)
-
-    if all:
-        addresses = mlist.getMembers()
-
-    try:
-        for addr in addresses:
-            try:
-                mlist.ApprovedDeleteMember(addr)
-            except Errors.MMNoSuchUserError:
-                print _("User `%(addr)s' not found.")
-    finally:
-        # Hmm, should it be all or nothing?
-        mlist.Save()
-        mlist.Unlock()
+    for listname in listnames:
+	try:
+	    # open locked
+	    mlist = MailList.MailList(listname)
+	except Errors.MMListError, e:
+	    print 'Error opening list "%s": %s... skipping.' % (listname, e)
+            continue
+
+	if all:
+	    addresses = mlist.GetMembers() + mlist.GetDigestMembers()
+
+	try:
+	    for addr in addresses:
+		try:
+		    mlist.DeleteMember(addr)
+		except Errors.MMNoSuchUserError:
+		    if rlistname != "_alllists_":
+			print "User `%s' not found." % addr
+		else:
+		    if rlistname == "_alllists_":
+			print "User `%s' removed from list `%s'" % (addr, listname)
+		    
+	finally:
+	    # Hmm, should it be all or nothing?
+	    mlist.Save()
+	    mlist.Unlock()
 
 
 
-- 
Microsoft is to operating systems & security ....
                                      .... what McDonalds is to gourmet cooking
  
Home page: http://marc.merlins.org/   |   Finger marc_f@merlins.org for PGP key