diff options
| -rw-r--r-- | src/mailman/app/finder.py | 5 | ||||
| -rw-r--r-- | src/mailman/commands/cli_info.py | 68 | ||||
| -rw-r--r-- | src/mailman/commands/docs/info.txt | 35 | ||||
| -rw-r--r-- | src/mailman/database/__init__.py | 2 |
4 files changed, 109 insertions, 1 deletions
diff --git a/src/mailman/app/finder.py b/src/mailman/app/finder.py index 2190c761e..c6d0a40db 100644 --- a/src/mailman/app/finder.py +++ b/src/mailman/app/finder.py @@ -54,6 +54,9 @@ def find_components(package, interface): if not hasattr(module, '__all__'): continue for name in module.__all__: - component = getattr(module, name) + missing = object() + component = getattr(module, name, missing) + assert component is not missing, ( + '%s has bad __all__: %s' % (module, name)) if interface.implementedBy(component): yield component diff --git a/src/mailman/commands/cli_info.py b/src/mailman/commands/cli_info.py new file mode 100644 index 000000000..0595c32fa --- /dev/null +++ b/src/mailman/commands/cli_info.py @@ -0,0 +1,68 @@ +# Copyright (C) 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/>. + +"""Information about this Mailman instance.""" + +from __future__ import absolute_import, unicode_literals + +__metaclass__ = type +__all__ = [ + 'Info' + ] + + +import sys + +from zope.interface import implements + +from mailman.config import config +from mailman.i18n import _ +from mailman.interfaces.command import ICLISubCommand +from mailman.version import MAILMAN_VERSION_FULL + + + +class Info: + """The `info` subcommand.""" + + implements(ICLISubCommand) + + def add(self, parser, subparser): + """See `ICLISubCommand`.""" + info_parser = subparser.add_parser( + 'info', help=_('Information about this Mailman instance.')) + info_parser.set_defaults(func=self.process) + info_parser.add_argument( + '-o', '--output', + action='store', help=_("""\ + File to send the output to. If not given, standard output is + used.""")) + + def process(self, args): + """See `ICLISubCommand`.""" + + if args.output is None: + output = sys.stdout + else: + # We don't need to close output because that will happen + # automatically when the script exits. + output = open(args.output, 'w') + + print >> output, MAILMAN_VERSION_FULL + print >> output, 'Python', sys.version + print >> output, 'config file:', config.filename + print >> output, 'db url:', config.db.url diff --git a/src/mailman/commands/docs/info.txt b/src/mailman/commands/docs/info.txt new file mode 100644 index 000000000..f524d8f0a --- /dev/null +++ b/src/mailman/commands/docs/info.txt @@ -0,0 +1,35 @@ +=================== +Getting information +=================== + +You can get information about Mailman's environment by using the command line +script 'mailman info'. By default, the info is printed to standard output. + + >>> from mailman.commands.cli_info import Info + >>> command = Info() + + >>> class FakeArgs: + ... output = None + >>> args = FakeArgs() + + >>> command.process(args) + GNU Mailman 3... + Python ... + ... + config file: .../test.cfg + db url: sqlite:.../mailman.db + +By passing in the -o/--output option, you can print the info to a file. + + >>> from mailman.config import config + >>> import os + >>> output_path = os.path.join(config.VAR_DIR, 'output.txt') + >>> args.output = output_path + >>> command.process(args) + >>> with open(output_path) as fp: + ... print fp.read() + GNU Mailman 3... + Python ... + ... + config file: .../test.cfg + db url: sqlite:.../mailman.db diff --git a/src/mailman/database/__init__.py b/src/mailman/database/__init__.py index dc3a86560..5943df660 100644 --- a/src/mailman/database/__init__.py +++ b/src/mailman/database/__init__.py @@ -55,6 +55,7 @@ class StockDatabase: implements(IDatabase) def __init__(self): + self.url = None self.list_manager = None self.user_manager = None self.message_store = None @@ -105,6 +106,7 @@ class StockDatabase: # ensuring the right permissions. We only try to do this for SQLite # engines, and yes, we could have chmod'd the file after the fact, but # half dozen and all... + self.url = url touch(url) database = create_database(url) store = Store(database, GenerationalCache()) |
