summaryrefslogtreecommitdiff
path: root/src/mailman/bin/list_lists.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/mailman/bin/list_lists.py')
-rw-r--r--src/mailman/bin/list_lists.py104
1 files changed, 104 insertions, 0 deletions
diff --git a/src/mailman/bin/list_lists.py b/src/mailman/bin/list_lists.py
new file mode 100644
index 000000000..ea1640910
--- /dev/null
+++ b/src/mailman/bin/list_lists.py
@@ -0,0 +1,104 @@
+# Copyright (C) 1998-2009 by the Free Software Foundation, Inc.
+#
+# This file is part of GNU Mailman.
+#
+# GNU Mailman 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 3 of the License, or (at your option)
+# any later version.
+#
+# GNU Mailman 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
+# GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
+
+from mailman.config 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)