Use a more efficient way of deleting rows from a table, which coincidentally
[mailman.git] / bin / reset_pw.py
blobaca79ba6d6894790a54ce041c7afc36c03456103
1 #! @PYTHON@
3 # Copyright (C) 2004-2007 by the Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 # Inspired by Florian Weimer.
21 """Reset the passwords for members of a mailing list.
23 This script resets all the passwords of a mailing list's members. It can also
24 be used to reset the lists of all members of all mailing lists, but it is your
25 responsibility to let the users know that their passwords have been changed.
27 This script is intended to be run as a bin/withlist script, i.e.
29 % bin/withlist -l -r reset_pw listname [options]
31 Options:
32 -v / --verbose
33 Print what the script is doing.
34 """
36 import sys
37 import getopt
39 import paths
40 from Mailman import Utils
41 from Mailman.i18n import _
45 def usage(code, msg=''):
46 if code:
47 fd = sys.stderr
48 else:
49 fd = sys.stdout
50 print >> fd, _(__doc__.replace('%', '%%'))
51 if msg:
52 print >> fd, msg
53 sys.exit(code)
57 def reset_pw(mlist, *args):
58 try:
59 opts, args = getopt.getopt(args, 'v', ['verbose'])
60 except getopt.error, msg:
61 usage(1, msg)
63 verbose = False
64 for opt, args in opts:
65 if opt in ('-v', '--verbose'):
66 verbose = True
68 listname = mlist.internal_name()
69 if verbose:
70 print _('Changing passwords for list: %(listname)s')
72 for member in mlist.getMembers():
73 randompw = Utils.MakeRandomPassword()
74 mlist.setMemberPassword(member, randompw)
75 if verbose:
76 print _('New password for member %(member)40s: %(randompw)s')
78 mlist.Save()
82 if __name__ == '__main__':
83 usage(0)