~futatuki/mailman/2.1-forbid-subscription

« back to all changes in this revision

Viewing changes to Mailman/Commands/cmd_help.py

  • Committer:
  • Date: 2003-01-02 05:25:50 UTC
  • Revision ID: vcs-imports@canonical.com-20030102052550-qqbl1i96tzg3bach
This commit was manufactured by cvs2svn to create branch
'Release_2_1-maint'.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2002 by the Free Software Foundation, Inc.
 
2
#
 
3
# This program is free software; you can redistribute it and/or
 
4
# modify it under the terms of the GNU General Public License
 
5
# as published by the Free Software Foundation; either version 2
 
6
# of the License, or (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
16
 
 
17
"""
 
18
    help
 
19
        Print this help message.
 
20
"""
 
21
 
 
22
import sys
 
23
import os
 
24
 
 
25
from Mailman import mm_cfg
 
26
from Mailman import Utils
 
27
from Mailman.i18n import _
 
28
 
 
29
EMPTYSTRING = ''
 
30
 
 
31
 
 
32
 
 
33
def gethelp(mlist):
 
34
    return _(__doc__)
 
35
 
 
36
 
 
37
 
 
38
def process(res, args):
 
39
    # Get the help text introduction
 
40
    mlist = res.mlist
 
41
    # Since this message is personalized, add some useful information if the
 
42
    # address requesting help is a member of the list.
 
43
    msg = res.msg
 
44
    for sender in  msg.get_senders():
 
45
        if mlist.isMember(sender):
 
46
            memberurl = mlist.GetOptionsURL(sender, absolute=1)
 
47
            urlhelp = _(
 
48
                'You can access your personal options via the following url:')
 
49
            res.results.append(urlhelp)
 
50
            res.results.append(memberurl)
 
51
            # Get a blank line in the output.
 
52
            res.results.append('')
 
53
            break
 
54
    # build the specific command helps from the module docstrings
 
55
    modhelps = {}
 
56
    import Mailman.Commands
 
57
    path = os.path.dirname(os.path.abspath(Mailman.Commands.__file__))
 
58
    for file in os.listdir(path):
 
59
        if not file.startswith('cmd_') or not file.endswith('.py'):
 
60
            continue
 
61
        module = os.path.splitext(file)[0]
 
62
        modname = 'Mailman.Commands.' + module
 
63
        try:
 
64
            __import__(modname)
 
65
        except ImportError:
 
66
            continue
 
67
        cmdname = module[4:]
 
68
        help = None
 
69
        if hasattr(sys.modules[modname], 'gethelp'):
 
70
            help = sys.modules[modname].gethelp(mlist)
 
71
        if help:
 
72
            modhelps[cmdname] = help
 
73
    # Now sort the command helps
 
74
    helptext = []
 
75
    keys = modhelps.keys()
 
76
    keys.sort()
 
77
    for cmd in keys:
 
78
        helptext.append(modhelps[cmd])
 
79
    commands = EMPTYSTRING.join(helptext)
 
80
    # Now craft the response
 
81
    helptext = Utils.maketext(
 
82
        'help.txt',
 
83
        {'listname'    : mlist.real_name,
 
84
         'version'     : mm_cfg.VERSION,
 
85
         'listinfo_url': mlist.GetScriptURL('listinfo', absolute=1),
 
86
         'requestaddr' : mlist.GetRequestEmail(),
 
87
         'adminaddr'   : mlist.GetOwnerEmail(),
 
88
         'commands'    : commands,
 
89
         }, mlist=mlist, lang=res.msgdata['lang'], raw=1)
 
90
    # Now add to the response
 
91
    res.results.append('help')
 
92
    res.results.append(helptext)