summaryrefslogtreecommitdiff
path: root/mailman/bin/list_lists.py
blob: 68a5190b9080a34cc4b3bd6b474d25926c311fca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# Copyright (C) 1998-2008 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.

from mailman import Defaults
from mailman.configuration import config
from mailman.i18n import _
from mailman.options import Options



class ScriptOptions(Options):
    usage=_("""\
%prog [options]

List all mailing lists.""")

    def add_options(self):
        super(ScriptOptions, self).add_options()
        self.parser.add_option(
            '-a', '--advertised',
            default=False, action='store_true',
            help=_("""\
List only those mailing lists that are publicly advertised"""))
        self.parser.add_option(
            '-b', '--bare',
            default=False, action='store_true',
            help=_("""\
Displays only the list name, with no description."""))
        self.parser.add_option(
            '-d', '--domain',
            default=[], type='string', action='append',
            dest='domains', help=_("""\
List only those mailing lists that match the given virtual domain, which may
be either the email host or the url host name.  Multiple -d options may be
given."""))
        self.parser.add_option(
            '-f', '--full',
            default=False, action='store_true',
            help=_("""\
Print the full list name, including the posting address."""))

    def sanity_check(self):
        if len(self.arguments) > 0:
            self.parser.error(_('Unexpected arguments'))



def main():
    options = ScriptOptions()
    options.initialize()

    mlists = []
    longest = 0

    listmgr = config.db.list_manager
    for fqdn_name in sorted(listmgr.names):
        mlist = listmgr.get(fqdn_name)
        if options.options.advertised and not mlist.advertised:
            continue
        if options.options.domains:
            for domain in options.options.domains:
                if domain in mlist.web_page_url or domain == mlist.host_name:
                    mlists.append(mlist)
                    break
        else:
            mlists.append(mlist)
        if options.options.full:
            name = mlist.fqdn_listname
        else:
            name = mlist.real_name
        longest = max(len(name), longest)

    if not mlists and not options.options.bare:
        print _('No matching mailing lists found')
        return

    if not options.options.bare:
        num_mlists = len(mlists)
        print _('$num_mlists matching mailing lists found:')

    format = '%%%ds - %%.%ds' % (longest, 77 - longest)
    for mlist in mlists:
        if options.options.full:
            name = mlist.fqdn_listname
        else:
            name = mlist.real_name
        if options.options.bare:
            print name
        else:
            description = mlist.description or _('[no description available]')
            print '   ', format % (name, description)