summaryrefslogtreecommitdiff
path: root/Mailman/bin/find_member.py
diff options
context:
space:
mode:
authorBarry Warsaw2008-02-27 01:26:18 -0500
committerBarry Warsaw2008-02-27 01:26:18 -0500
commita1c73f6c305c7f74987d99855ba59d8fa823c253 (patch)
tree65696889450862357c9e05c8e9a589f1bdc074ac /Mailman/bin/find_member.py
parent3f31f8cce369529d177cfb5a7c66346ec1e12130 (diff)
downloadmailman-a1c73f6c305c7f74987d99855ba59d8fa823c253.tar.gz
mailman-a1c73f6c305c7f74987d99855ba59d8fa823c253.tar.zst
mailman-a1c73f6c305c7f74987d99855ba59d8fa823c253.zip
Diffstat (limited to 'Mailman/bin/find_member.py')
-rw-r--r--Mailman/bin/find_member.py135
1 files changed, 0 insertions, 135 deletions
diff --git a/Mailman/bin/find_member.py b/Mailman/bin/find_member.py
deleted file mode 100644
index a0c198214..000000000
--- a/Mailman/bin/find_member.py
+++ /dev/null
@@ -1,135 +0,0 @@
-# Copyright (C) 1998-2008 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.
-
-import re
-import sys
-import optparse
-
-from Mailman import Errors
-from Mailman import MailList
-from Mailman import Version
-from Mailman.configuration import config
-from Mailman.i18n import _
-
-
-AS_MEMBER = 0x01
-AS_OWNER = 0x02
-
-
-
-def parseargs():
- parser = optparse.OptionParser(version=Version.MAILMAN_VERSION,
- usage=_("""\
-%prog [options] regex [regex ...]
-
-Find all lists that a member's address is on.
-
-The interaction between -l and -x (see below) is as follows. If any -l option
-is given then only the named list will be included in the search. If any -x
-option is given but no -l option is given, then all lists will be search
-except those specifically excluded.
-
-Regular expression syntax uses the Python 're' module. Complete
-specifications are at:
-
-http://www.python.org/doc/current/lib/module-re.html
-
-Address matches are case-insensitive, but case-preserved addresses are
-displayed."""))
- parser.add_option('-l', '--listname',
- type='string', default=[], action='append',
- dest='listnames',
- help=_('Include only the named list in the search'))
- parser.add_option('-x', '--exclude',
- type='string', default=[], action='append',
- dest='excludes',
- help=_('Exclude the named list from the search'))
- parser.add_option('-w', '--owners',
- default=False, action='store_true',
- help=_('Search list owners as well as members'))
- parser.add_option('-C', '--config',
- help=_('Alternative configuration file to use'))
- opts, args = parser.parse_args()
- if not args:
- parser.print_help()
- print >> sys.stderr, _('Search regular expression required')
- sys.exit(1)
- return parser, opts, args
-
-
-
-def main():
- parser, opts, args = parseargs()
- config.load(opts.config)
-
- listnames = opts.listnames or config.list_manager.names
- includes = set(listname.lower() for listname in listnames)
- excludes = set(listname.lower() for listname in opts.excludes)
- listnames = includes - excludes
-
- if not listnames:
- print _('No lists to search')
- return
-
- cres = []
- for r in args:
- cres.append(re.compile(r, re.IGNORECASE))
- # dictionary of {address, (listname, ownerp)}
- matches = {}
- for listname in listnames:
- try:
- mlist = MailList.MailList(listname, lock=False)
- except Errors.MMListError:
- print _('No such list: $listname')
- continue
- if opts.owners:
- owners = mlist.owner
- else:
- owners = []
- for cre in cres:
- for member in mlist.getMembers():
- if cre.search(member):
- addr = mlist.getMemberCPAddress(member)
- entries = matches.get(addr, {})
- aswhat = entries.get(listname, 0)
- aswhat |= AS_MEMBER
- entries[listname] = aswhat
- matches[addr] = entries
- for owner in owners:
- if cre.search(owner):
- entries = matches.get(owner, {})
- aswhat = entries.get(listname, 0)
- aswhat |= AS_OWNER
- entries[listname] = aswhat
- matches[owner] = entries
- addrs = matches.keys()
- addrs.sort()
- for k in addrs:
- hits = matches[k]
- lists = hits.keys()
- print k, _('found in:')
- for name in lists:
- aswhat = hits[name]
- if aswhat & AS_MEMBER:
- print ' ', name
- if aswhat & AS_OWNER:
- print ' ', name, _('(as owner)')
-
-
-
-if __name__ == '__main__':
- main()