From e6402e44036af0529a35ff6e81cfc3108c1a96e1 Mon Sep 17 00:00:00 2001 From: bwarsaw <> Date: Thu, 30 Dec 2004 23:41:09 +0000 Subject: 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. --- bin/Makefile.in | 2 +- bin/reset_pw | 86 ------------------------------------------------------ bin/reset_pw.py | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ bin/withlist | 70 +++++++++++++++++++++++++++++--------------- 4 files changed, 137 insertions(+), 111 deletions(-) delete mode 100644 bin/reset_pw create mode 100644 bin/reset_pw.py (limited to 'bin') diff --git a/bin/Makefile.in b/bin/Makefile.in index daf4faff..518b6088 100644 --- a/bin/Makefile.in +++ b/bin/Makefile.in @@ -49,7 +49,7 @@ SCRIPTS= mmsitepass newlist rmlist add_members \ 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 diff --git a/bin/reset_pw b/bin/reset_pw deleted file mode 100644 index d7e5527a..00000000 --- a/bin/reset_pw +++ /dev/null @@ -1,86 +0,0 @@ -#! @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 [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.listname() - if verbose: - print _('Changing passwords for list: %(listname)s') - - for member in mlist.getMembers(): - randompw = Utils.MakeRandomPassword() - mlist.setMemberPassword(member, randompw) - - - -if __name__ == '__main__': - usage(0) diff --git a/bin/reset_pw.py b/bin/reset_pw.py new file mode 100644 index 00000000..bddc1ace --- /dev/null +++ b/bin/reset_pw.py @@ -0,0 +1,90 @@ +#! @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) diff --git a/bin/withlist b/bin/withlist index 345ff39d..02ce3e50 100644 --- a/bin/withlist +++ b/bin/withlist @@ -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 @@ Options: --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 @@ def changepw(mlist, addr, newpasswd): print 'No address matched:', addr and run this from the command line: -%% bin/withlist -l -r changepw mylist somebody@somewhere.org foobar + %% bin/withlist -l -r changepw mylist somebody@somewhere.org 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 @@ def main(): 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 @@ def main(): # 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 @@ def main(): 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 @@ def main(): 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) -- cgit v1.2.3