summaryrefslogtreecommitdiff
path: root/modules/mm_utils.py
diff options
context:
space:
mode:
authormailman1998-03-20 18:26:49 +0000
committermailman1998-03-20 18:26:49 +0000
commit8847481c1098ee3019c56f8423049f4fc4efe3f1 (patch)
tree5d430770d305407b08af1af14ae6ed7a7a29efa5 /modules/mm_utils.py
parent4423b73dd8b9d00a868d8e525f65177727325909 (diff)
downloadmailman-8847481c1098ee3019c56f8423049f4fc4efe3f1.tar.gz
mailman-8847481c1098ee3019c56f8423049f4fc4efe3f1.tar.zst
mailman-8847481c1098ee3019c56f8423049f4fc4efe3f1.zip
map_maillists() - New convenience routine for interactive python
sessions with lists, applies user specified routine to all of the lists, or optionally, those lists with user-specified names. Optional arg unlock says to unlocked immediately after instantiation, for non-invasive actions. Optional arg verbose says to print list name and result incrementally as they're handled.
Diffstat (limited to 'modules/mm_utils.py')
-rw-r--r--modules/mm_utils.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/modules/mm_utils.py b/modules/mm_utils.py
index ca6c6f429..b29a9f8bf 100644
--- a/modules/mm_utils.py
+++ b/modules/mm_utils.py
@@ -188,3 +188,29 @@ def UnobscureEmail(addr):
# Contrived to act as an identity operation on already-unobscured
# emails, so routines expecting obscured ones will accept both.
return re.sub("__at__", "@", addr)
+
+def map_maillists(func, names=None, unlock=None, verbose=0):
+ """Apply function (of one argument) to all list objs in turn.
+
+ Returns a list of the results.
+
+ Optional arg 'names' specifies which lists, default all.
+ Optional arg unlock says to unlock immediately after instantiation.
+ Optional arg verbose says to print list name as it's about to be
+ instantiated, CR when instantiation is complete, and result of
+ application as it shows."""
+ from maillist import MailList
+ if names == None: names = list_names()
+ got = []
+ for i in names:
+ if verbose: print i,
+ l = MailList(i)
+ if verbose: print
+ if unlock:
+ l.Unlock()
+ got.append(apply(func, (l,)))
+ if verbose: print got[-1]
+ if not unlock:
+ l.Unlock()
+ del l
+ return got