diff options
| -rw-r--r-- | buildout.cfg | 1 | ||||
| -rw-r--r-- | src/attic/cmd_confirm.py (renamed from src/mailman/commands/cmd_confirm.py) | 2 | ||||
| -rw-r--r-- | src/attic/cmd_help.py (renamed from src/mailman/commands/cmd_help.py) | 0 | ||||
| -rw-r--r-- | src/attic/cmd_info.py (renamed from src/mailman/commands/cmd_info.py) | 0 | ||||
| -rw-r--r-- | src/attic/cmd_leave.py (renamed from src/mailman/commands/cmd_leave.py) | 0 | ||||
| -rw-r--r-- | src/attic/cmd_lists.py (renamed from src/mailman/commands/cmd_lists.py) | 0 | ||||
| -rw-r--r-- | src/attic/cmd_password.py (renamed from src/mailman/commands/cmd_password.py) | 0 | ||||
| -rw-r--r-- | src/attic/cmd_remove.py (renamed from src/mailman/commands/cmd_remove.py) | 0 | ||||
| -rw-r--r-- | src/attic/cmd_set.py (renamed from src/mailman/commands/cmd_set.py) | 0 | ||||
| -rw-r--r-- | src/attic/cmd_unsubscribe.py (renamed from src/mailman/commands/cmd_unsubscribe.py) | 0 | ||||
| -rw-r--r-- | src/attic/cmd_who.py (renamed from src/mailman/commands/cmd_who.py) | 0 | ||||
| -rw-r--r-- | src/mailman/__init__.py | 31 | ||||
| -rw-r--r-- | src/mailman/app/commands.py | 27 | ||||
| -rw-r--r-- | src/mailman/app/finder.py | 58 | ||||
| -rw-r--r-- | src/mailman/commands/__init__.py | 22 | ||||
| -rw-r--r-- | src/mailman/core/pipelines.py | 4 | ||||
| -rw-r--r-- | src/mailman/core/rules.py | 4 | ||||
| -rw-r--r-- | src/mailman/interfaces/command.py | 5 | ||||
| -rw-r--r-- | src/mailman/pipeline/__init__.py | 53 | ||||
| -rw-r--r-- | src/mailman/rules/__init__.py | 53 |
20 files changed, 109 insertions, 151 deletions
diff --git a/buildout.cfg b/buildout.cfg index c02c4c332..54774fada 100644 --- a/buildout.cfg +++ b/buildout.cfg @@ -10,6 +10,7 @@ develop = . recipe = zc.recipe.egg interpreter = py eggs = + argparse lazr.config lazr.delegates locknix diff --git a/src/mailman/commands/cmd_confirm.py b/src/attic/cmd_confirm.py index b5e4182bd..0e2b7ad43 100644 --- a/src/mailman/commands/cmd_confirm.py +++ b/src/attic/cmd_confirm.py @@ -21,7 +21,7 @@ supplied by a mailback confirmation notice. """ -from mailman import Errors +from mailman import errors from mailman import Pending from mailman.config import config from mailman.i18n import _ diff --git a/src/mailman/commands/cmd_help.py b/src/attic/cmd_help.py index 30c8dc4d6..30c8dc4d6 100644 --- a/src/mailman/commands/cmd_help.py +++ b/src/attic/cmd_help.py diff --git a/src/mailman/commands/cmd_info.py b/src/attic/cmd_info.py index 3bdea178f..3bdea178f 100644 --- a/src/mailman/commands/cmd_info.py +++ b/src/attic/cmd_info.py diff --git a/src/mailman/commands/cmd_leave.py b/src/attic/cmd_leave.py index 5844824f7..5844824f7 100644 --- a/src/mailman/commands/cmd_leave.py +++ b/src/attic/cmd_leave.py diff --git a/src/mailman/commands/cmd_lists.py b/src/attic/cmd_lists.py index 234ef46fc..234ef46fc 100644 --- a/src/mailman/commands/cmd_lists.py +++ b/src/attic/cmd_lists.py diff --git a/src/mailman/commands/cmd_password.py b/src/attic/cmd_password.py index 545da0cb5..545da0cb5 100644 --- a/src/mailman/commands/cmd_password.py +++ b/src/attic/cmd_password.py diff --git a/src/mailman/commands/cmd_remove.py b/src/attic/cmd_remove.py index 8f3ce9669..8f3ce9669 100644 --- a/src/mailman/commands/cmd_remove.py +++ b/src/attic/cmd_remove.py diff --git a/src/mailman/commands/cmd_set.py b/src/attic/cmd_set.py index 020bc3636..020bc3636 100644 --- a/src/mailman/commands/cmd_set.py +++ b/src/attic/cmd_set.py diff --git a/src/mailman/commands/cmd_unsubscribe.py b/src/attic/cmd_unsubscribe.py index 456b8089d..456b8089d 100644 --- a/src/mailman/commands/cmd_unsubscribe.py +++ b/src/attic/cmd_unsubscribe.py diff --git a/src/mailman/commands/cmd_who.py b/src/attic/cmd_who.py index 6c66610b3..6c66610b3 100644 --- a/src/mailman/commands/cmd_who.py +++ b/src/attic/cmd_who.py diff --git a/src/mailman/__init__.py b/src/mailman/__init__.py index e69de29bb..d363d02ac 100644 --- a/src/mailman/__init__.py +++ b/src/mailman/__init__.py @@ -0,0 +1,31 @@ +# 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/>. + +"""The Mailman super-command.""" + +from __future__ import absolute_import, unicode_literals + +__metaclass__ = type +__all__ = [ + ] + + +## import os +## from pkg_resources import resource_listdir + +## from mailman.app.options import Options +## from mailman.interfaces.command import IBinCommand diff --git a/src/mailman/app/commands.py b/src/mailman/app/commands.py index cd4513629..7131defb4 100644 --- a/src/mailman/app/commands.py +++ b/src/mailman/app/commands.py @@ -25,9 +25,9 @@ __all__ = [ ] -import sys +from zope.interface.verify import verifyObject -from mailman import commands +from mailman.app.finder import find_components from mailman.config import config from mailman.interfaces.command import IEmailCommand @@ -35,19 +35,10 @@ from mailman.interfaces.command import IEmailCommand def initialize(): """Initialize the email commands.""" - for command_module in commands.__all__: - module_name = 'mailman.commands.' + command_module - __import__(module_name) - module = sys.modules[module_name] - for name in dir(module): - command_class = getattr(module, name) - try: - is_command = IEmailCommand.implementedBy(command_class) - except TypeError: - is_command = False - if not is_command: - continue - assert command_class.name not in config.commands, ( - 'Duplicate email command "{0}" found in {1}'.format( - command_class.name, module)) - config.commands[command_class.name] = command_class() + for command_class in find_components('mailman.commands', IEmailCommand): + command = command_class() + verifyObject(IEmailCommand, command) + assert command_class.name not in config.commands, ( + 'Duplicate email command "{0}" found in {1}'.format( + command_class.name, module)) + config.commands[command_class.name] = command_class() diff --git a/src/mailman/app/finder.py b/src/mailman/app/finder.py new file mode 100644 index 000000000..2632957b8 --- /dev/null +++ b/src/mailman/app/finder.py @@ -0,0 +1,58 @@ +# 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/>. + +"""Find various kinds of object in package space.""" + +from __future__ import absolute_import, unicode_literals + +__metaclass__ = type +__all__ = [ + 'find_components', + ] + + +import os +import sys +from pkg_resources import resource_listdir + + + +def find_components(package, interface): + """Find components which conform to a given interface. + + Search all the modules in a given package, returning an iterator over all + objects found that conform to the given interface. + + :param package: The package path to search. + :type package: string + :param interface: The interface that returned objects must conform to. + :type interface: `Interface` + """ + # Find all rules found in all modules inside our package. + for filename in resource_listdir(package, ''): + basename, extension = os.path.splitext(filename) + if extension <> '.py': + continue + module_name = '{0}.{1}'.format(package, basename) + __import__(module_name, fromlist='*') + module = sys.modules[module_name] + if not hasattr(module, '__all__'): + continue + for name in module.__all__: + component = getattr(module, name) + if interface.implementedBy(component): + yield component diff --git a/src/mailman/commands/__init__.py b/src/mailman/commands/__init__.py index 6e89bc6da..e69de29bb 100644 --- a/src/mailman/commands/__init__.py +++ b/src/mailman/commands/__init__.py @@ -1,22 +0,0 @@ -# Copyright (C) 2008-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/>. - -__all__ = [ - 'echo', - 'end', - 'join', - ] diff --git a/src/mailman/core/pipelines.py b/src/mailman/core/pipelines.py index aae3f11dd..cdfd1a462 100644 --- a/src/mailman/core/pipelines.py +++ b/src/mailman/core/pipelines.py @@ -29,11 +29,11 @@ __all__ = [ from zope.interface import implements from zope.interface.verify import verifyObject +from mailman.app.finder import find_components from mailman.config import config from mailman.i18n import _ from mailman.interfaces.handler import IHandler from mailman.interfaces.pipeline import IPipeline -from mailman.pipeline import builtin_handlers @@ -111,7 +111,7 @@ class VirginPipeline(BasePipeline): def initialize(): """Initialize the pipelines.""" # Find all handlers in the registered plugins. - for handler_class in builtin_handlers(): + for handler_class in find_components('mailman.pipeline', IHandler): handler = handler_class() verifyObject(IHandler, handler) assert handler.name not in config.handlers, ( diff --git a/src/mailman/core/rules.py b/src/mailman/core/rules.py index 82ae4c89b..587733d5e 100644 --- a/src/mailman/core/rules.py +++ b/src/mailman/core/rules.py @@ -27,16 +27,16 @@ __all__ = [ from zope.interface.verify import verifyObject +from mailman.app.finder import find_components from mailman.config import config from mailman.interfaces.rules import IRule -from mailman.rules import builtin_rules def initialize(): """Find and register all rules in all plugins.""" # Find rules in plugins. - for rule_class in builtin_rules(): + for rule_class in find_components('mailman.rules', IRule): rule = rule_class() verifyObject(IRule, rule) assert rule.name not in config.rules, ( diff --git a/src/mailman/interfaces/command.py b/src/mailman/interfaces/command.py index a9ad292f4..9995b80a9 100644 --- a/src/mailman/interfaces/command.py +++ b/src/mailman/interfaces/command.py @@ -66,3 +66,8 @@ class IEmailCommand(Interface): :return: A `ContinueProcessing` enum specifying whether to continue processing or not. """ + + + +class IBinCommand(Interface): + """A command line (i.e. bin) command.""" diff --git a/src/mailman/pipeline/__init__.py b/src/mailman/pipeline/__init__.py index e1efcb221..e69de29bb 100644 --- a/src/mailman/pipeline/__init__.py +++ b/src/mailman/pipeline/__init__.py @@ -1,53 +0,0 @@ -# Copyright (C) 2008-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/>. - -"""The built in set of pipeline handlers.""" - -from __future__ import absolute_import, unicode_literals - -__metaclass__ = type -__all__ = [ - 'builtin_handlers', - ] - - -import os -import sys -from pkg_resources import resource_listdir - -from mailman.interfaces.handler import IHandler - - - -def builtin_handlers(): - """Return the built-in handlers. - - Rules are auto-discovered by searching for IHandler implementations in all - importable modules in this subpackage. - """ - # Find all rules found in all modules inside our package. - for filename in resource_listdir('mailman.pipeline', ''): - basename, extension = os.path.splitext(filename) - if extension <> '.py': - continue - module_name = 'mailman.pipeline.' + basename - __import__(module_name, fromlist='*') - module = sys.modules[module_name] - for name in getattr(module, '__all__', ()): - handler = getattr(module, name) - if IHandler.implementedBy(handler): - yield handler diff --git a/src/mailman/rules/__init__.py b/src/mailman/rules/__init__.py index d58921078..e69de29bb 100644 --- a/src/mailman/rules/__init__.py +++ b/src/mailman/rules/__init__.py @@ -1,53 +0,0 @@ -# Copyright (C) 2007-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/>. - -"""The built in rule set.""" - -from __future__ import absolute_import, unicode_literals - -__metaclass__ = type -__all__ = [ - 'builtin_rules', - ] - - -import os -import sys -from pkg_resources import resource_listdir - -from mailman.interfaces.rules import IRule - - - -def builtin_rules(): - """Return the built-in rules. - - Rules are auto-discovered by searching for IRule implementations in all - importable modules in this subpackage. - """ - # Find all rules found in all modules inside our package. - for filename in resource_listdir('mailman.rules', ''): - basename, extension = os.path.splitext(filename) - if extension <> '.py': - continue - module_name = 'mailman.rules.' + basename - __import__(module_name, fromlist='*') - module = sys.modules[module_name] - for name in module.__all__: - rule = getattr(module, name) - if IRule.implementedBy(rule): - yield rule |
