Update of /cvsroot/mailman/mailman/bin
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12222/bin
Modified Files:
Tag: Release_2_1-maint
Makefile.in withlist
Added Files:
Tag: Release_2_1-maint
reset_pw.py
Removed Files:
Tag: Release_2_1-maint
reset_pw
Log Message:
Renamed reset_pw to reset_pw.py so that the file looks like a Python module.
This goes hand-in-hand with one of two changes to withlist. Now, withlist
puts the directory it's found in on the end of sys.path. This way it's much
easier to run withlist scripts that live in bin.
The other change allows running withlist w/o a list name, but only if -i is
given. Makes it easier to debug various non-list related parts of Mailman.
--- NEW FILE: reset_pw.py ---
#! @PYTHON@
#
# Copyright (C) 2004 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# Inspired by Florian Weimer.
"""Reset the passwords for members of a mailing list.
This script resets all the passwords of a mailing list's members. It can also
be used to reset the lists of all members of all mailing lists, but it is your
responsibility to let the users know that their passwords have been changed.
This script is intended to be run as a bin/withlist script, i.e.
% bin/withlist -l -r reset_pw listname [options]
Options:
-v / --verbose
Print what the script is doing.
"""
import sys
import getopt
import paths
from Mailman import Utils
from Mailman.i18n import _
try:
True, False
except NameError:
True = 1
False = 0
def usage(code, msg=''):
if code:
fd = sys.stderr
else:
fd = sys.stdout
print >> fd, _(__doc__.replace('%', '%%'))
if msg:
print >> fd, msg
sys.exit(code)
def reset_pw(mlist, *args):
try:
opts, args = getopt.getopt(args, 'v', ['verbose'])
except getopt.error, msg:
usage(1, msg)
verbose = False
for opt, args in opts:
if opt in ('-v', '--verbose'):
verbose = True
listname = mlist.internal_name()
if verbose:
print _('Changing passwords for list: %(listname)s')
for member in mlist.getMembers():
randompw = Utils.MakeRandomPassword()
mlist.setMemberPassword(member, randompw)
if verbose:
print _('New password for member %(member)40s: %(randompw)s')
mlist.Save()
if __name__ == '__main__':
usage(0)
Index: Makefile.in
===================================================================
RCS file: /cvsroot/mailman/mailman/bin/Makefile.in,v
retrieving revision 2.19.2.5
retrieving revision 2.19.2.6
diff -u -d -r2.19.2.5 -r2.19.2.6
--- Makefile.in 30 Dec 2004 20:49:31 -0000 2.19.2.5
+++ Makefile.in 30 Dec 2004 23:41:09 -0000 2.19.2.6
@@ -49,7 +49,7 @@
list_admins genaliases change_pw mailmanctl qrunner inject \
unshunt fix_url.py convert.py transcheck b4b5-archfix \
list_owners msgfmt.py show_qfiles discard rb-archfix \
- reset_pw
+ reset_pw.py
BUILDDIR= ../build/bin
Index: withlist
===================================================================
RCS file: /cvsroot/mailman/mailman/bin/withlist,v
retrieving revision 2.10.2.1
retrieving revision 2.10.2.2
diff -u -d -r2.10.2.1 -r2.10.2.2
--- withlist 19 Apr 2003 04:57:15 -0000 2.10.2.1
+++ withlist 30 Dec 2004 23:41:09 -0000 2.10.2.2
@@ -1,6 +1,6 @@
#! @PYTHON@
#
-# Copyright (C) 1998-2003 by the Free Software Foundation, Inc.
+# Copyright (C) 1998-2004 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
@@ -49,12 +49,12 @@
--run [module.]callable
-r [module.]callable
This can be used to run a script with the opened MailList object.
- This works by attempting to import `module' (which must already be
- accessible on your sys.path), and then calling `callable' from the
- module. callable can be a class or function; it is called with the
- MailList object as the first argument. If additional args are given
- on the command line, they are passed as subsequent positional args to
- the callable.
+ This works by attempting to import `module' (which must be in the
+ directory containing withlist, or already be accessible on your
+ sys.path), and then calling `callable' from the module. callable can
+ be a class or function; it is called with the MailList object as the
+ first argument. If additional args are given on the command line,
+ they are passed as subsequent positional args to the callable.
Note that `module.' is optional; if it is omitted then a module with
the name `callable' will be imported.
@@ -115,24 +115,36 @@
print 'No address matched:', addr
and run this from the command line:
-%% bin/withlist -l -r changepw mylist [EMAIL PROTECTED] foobar
+ %% bin/withlist -l -r changepw mylist [EMAIL PROTECTED] foobar
"""
+import os
import sys
-import getopt
import code
+import getopt
import paths
-from Mailman import Utils
-from Mailman import MailList
from Mailman import Errors
+from Mailman import MailList
+from Mailman import Utils
from Mailman.i18n import _
+try:
+ True, False
+except NameError:
+ True = 1
+ False = 0
+
+
# `m' will be the MailList object and `r' will be the results of the callable
m = None
r = None
-VERBOSE = 1
-LOCK = 0
+VERBOSE = True
+LOCK = False
+
+
+# Put the bin directory on sys.path -- last
+sys.path.append(os.path.dirname(sys.argv[0]))
@@ -204,23 +216,30 @@
run = None
interact = None
- all = 0
+ all = False
+ dolist = True
for opt, arg in opts:
if opt in ('-h', '--help'):
usage(0)
elif opt in ('-l', '--lock'):
- LOCK = 1
+ LOCK = True
elif opt in ('-r', '--run'):
run = arg
elif opt in ('-q', '--quiet'):
- VERBOSE = 0
+ VERBOSE = False
elif opt in ('-i', '--interactive'):
- interact = 1
+ interact = True
elif opt in ('-a', '--all'):
- all = 1
+ all = True
if len(args) < 1 and not all:
- usage(1, _('No list name supplied.'))
+ warning = _('No list name supplied.')
+ if interact:
+ # Let them keep going
+ print warning
+ dolist = False
+ else:
+ usage(1, warning)
if all and not run:
usage(1, _('--all requires --run'))
@@ -228,9 +247,9 @@
# The default for interact is 1 unless -r was given
if interact is None:
if run is None:
- interact = 1
+ interact = True
else:
- interact = 0
+ interact = False
# try to import the module for the callable
func = None
@@ -251,7 +270,7 @@
if all:
r = [do_list(listname, args, func) for listname in Utils.list_names()]
- else:
+ elif dolist:
listname = args.pop(0).lower().strip()
r = do_list(listname, args, func)
@@ -266,8 +285,11 @@
pass
namespace = globals().copy()
namespace.update(locals())
- code.InteractiveConsole(namespace).interact(
- _("The variable `m' is the %(listname)s MailList instance"))
+ if dolist:
+ ban = _("The variable `m' is the %(listname)s MailList instance")
+ else:
+ ban = None
+ code.InteractiveConsole(namespace).interact(ban)
--- reset_pw DELETED ---
_______________________________________________
Mailman-checkins mailing list
[email protected]
Unsubscribe:
http://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org