~ubuntu-branches/ubuntu/hardy/mailman/hardy-updates

« back to all changes in this revision

Viewing changes to bin/withlist

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2006-07-03 16:59:25 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20060703165925-175ubna955u796c0
Tags: 0:2.1.8-1ubuntu1
* Merge to Debian; remaining Ubuntu changes:
  - debian/mailman.init: Create /var/{run,lock}/mailman.
  - debian/control: exim4 -> postfix.
* debian/control: Dependency fix: apache -> apache2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#! @PYTHON@
2
2
#
3
 
# Copyright (C) 1998-2003 by the Free Software Foundation, Inc.
 
3
# Copyright (C) 1998-2004 by the Free Software Foundation, Inc.
4
4
#
5
5
# This program is free software; you can redistribute it and/or
6
6
# modify it under the terms of the GNU General Public License
14
14
#
15
15
# You should have received a copy of the GNU General Public License
16
16
# along with this program; if not, write to the Free Software
17
 
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
17
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
18
 
19
19
"""General framework for interacting with a mailing list object.
20
20
 
49
49
    --run [module.]callable
50
50
    -r [module.]callable
51
51
        This can be used to run a script with the opened MailList object.
52
 
        This works by attempting to import `module' (which must already be
53
 
        accessible on your sys.path), and then calling `callable' from the
54
 
        module.  callable can be a class or function; it is called with the
55
 
        MailList object as the first argument.  If additional args are given
56
 
        on the command line, they are passed as subsequent positional args to
57
 
        the callable.
 
52
        This works by attempting to import `module' (which must be in the
 
53
        directory containing withlist, or already be accessible on your
 
54
        sys.path), and then calling `callable' from the module.  callable can
 
55
        be a class or function; it is called with the MailList object as the
 
56
        first argument.  If additional args are given on the command line,
 
57
        they are passed as subsequent positional args to the callable.
58
58
 
59
59
        Note that `module.' is optional; if it is omitted then a module with
60
60
        the name `callable' will be imported.
115
115
        print 'No address matched:', addr
116
116
 
117
117
and run this from the command line:
118
 
%% bin/withlist -l -r changepw mylist somebody@somewhere.org foobar
 
118
 %% bin/withlist -l -r changepw mylist somebody@somewhere.org foobar
119
119
"""
120
120
 
 
121
import os
121
122
import sys
 
123
import code
122
124
import getopt
123
 
import code
124
125
 
125
126
import paths
 
127
from Mailman import Errors
 
128
from Mailman import MailList
126
129
from Mailman import Utils
127
 
from Mailman import MailList
128
 
from Mailman import Errors
129
130
from Mailman.i18n import _
130
131
 
 
132
try:
 
133
    True, False
 
134
except NameError:
 
135
    True = 1
 
136
    False = 0
 
137
 
 
138
 
131
139
# `m' will be the MailList object and `r' will be the results of the callable
132
140
m = None
133
141
r = None
134
 
VERBOSE = 1
135
 
LOCK = 0
 
142
VERBOSE = True
 
143
LOCK = False
 
144
 
 
145
 
 
146
# Put the bin directory on sys.path -- last
 
147
sys.path.append(os.path.dirname(sys.argv[0]))
136
148
 
137
149
 
138
150
 
204
216
 
205
217
    run = None
206
218
    interact = None
207
 
    all = 0
 
219
    all = False
 
220
    dolist = True
208
221
    for opt, arg in opts:
209
222
        if opt in ('-h', '--help'):
210
223
            usage(0)
211
224
        elif opt in ('-l', '--lock'):
212
 
            LOCK = 1
 
225
            LOCK = True
213
226
        elif opt in ('-r', '--run'):
214
227
            run = arg
215
228
        elif opt in ('-q', '--quiet'):
216
 
            VERBOSE = 0
 
229
            VERBOSE = False
217
230
        elif opt in ('-i', '--interactive'):
218
 
            interact = 1
 
231
            interact = True
219
232
        elif opt in ('-a', '--all'):
220
 
            all = 1
 
233
            all = True
221
234
 
222
235
    if len(args) < 1 and not all:
223
 
        usage(1, _('No list name supplied.'))
 
236
        warning = _('No list name supplied.')
 
237
        if interact:
 
238
            # Let them keep going
 
239
            print warning
 
240
            dolist = False
 
241
        else:
 
242
            usage(1, warning)
224
243
 
225
244
    if all and not run:
226
245
        usage(1, _('--all requires --run'))
228
247
    # The default for interact is 1 unless -r was given
229
248
    if interact is None:
230
249
        if run is None:
231
 
            interact = 1
 
250
            interact = True
232
251
        else:
233
 
            interact = 0
 
252
            interact = False
234
253
 
235
254
    # try to import the module for the callable
236
255
    func = None
251
270
 
252
271
    if all:
253
272
        r = [do_list(listname, args, func) for listname in Utils.list_names()]
254
 
    else:
 
273
    elif dolist:
255
274
        listname = args.pop(0).lower().strip()
256
275
        r = do_list(listname, args, func)
257
276
 
266
285
            pass
267
286
        namespace = globals().copy()
268
287
        namespace.update(locals())
269
 
        code.InteractiveConsole(namespace).interact(
270
 
            _("The variable `m' is the %(listname)s MailList instance"))
 
288
        if dolist:
 
289
            ban = _("The variable `m' is the %(listname)s MailList instance")
 
290
        else:
 
291
            ban = None
 
292
        code.InteractiveConsole(namespace).interact(ban)
271
293
 
272
294
 
273
295