------------------------------------------------------------
revno: 6712
committer: Barry Warsaw <[email protected]>
branch nick: hacking
timestamp: Sun 2009-03-29 15:40:22 -0500
message:
Add argparse 'cause I think this might end up being cool.
Refactor the finding of components so that it's much easier to find and
register the ones that come with Mailman by default.
Move all the old cmd_*.py commands into the attic. These will eventually be
ported to the new framework.
added:
src/mailman/app/finder.py
renamed:
src/mailman/commands/cmd_confirm.py => src/attic/cmd_confirm.py
src/mailman/commands/cmd_help.py => src/attic/cmd_help.py
src/mailman/commands/cmd_info.py => src/attic/cmd_info.py
src/mailman/commands/cmd_leave.py => src/attic/cmd_leave.py
src/mailman/commands/cmd_lists.py => src/attic/cmd_lists.py
src/mailman/commands/cmd_password.py => src/attic/cmd_password.py
src/mailman/commands/cmd_remove.py => src/attic/cmd_remove.py
src/mailman/commands/cmd_set.py => src/attic/cmd_set.py
src/mailman/commands/cmd_unsubscribe.py => src/attic/cmd_unsubscribe.py
src/mailman/commands/cmd_who.py => src/attic/cmd_who.py
modified:
buildout.cfg
src/mailman/__init__.py
src/mailman/app/commands.py
src/mailman/commands/__init__.py
src/mailman/core/pipelines.py
src/mailman/core/rules.py
src/mailman/interfaces/command.py
src/mailman/pipeline/__init__.py
src/mailman/rules/__init__.py
src/attic/cmd_confirm.py
=== modified file 'buildout.cfg'
--- buildout.cfg 2009-01-07 00:55:59 +0000
+++ buildout.cfg 2009-03-29 20:40:22 +0000
@@ -10,6 +10,7 @@
recipe = zc.recipe.egg
interpreter = py
eggs =
+ argparse
lazr.config
lazr.delegates
locknix
=== renamed file 'src/mailman/commands/cmd_confirm.py' =>
'src/attic/cmd_confirm.py'
--- src/mailman/commands/cmd_confirm.py 2009-01-01 22:16:51 +0000
+++ src/attic/cmd_confirm.py 2009-03-29 20:40:22 +0000
@@ -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 _
=== renamed file 'src/mailman/commands/cmd_help.py' => 'src/attic/cmd_help.py'
=== renamed file 'src/mailman/commands/cmd_info.py' => 'src/attic/cmd_info.py'
=== renamed file 'src/mailman/commands/cmd_leave.py' => 'src/attic/cmd_leave.py'
=== renamed file 'src/mailman/commands/cmd_lists.py' => 'src/attic/cmd_lists.py'
=== renamed file 'src/mailman/commands/cmd_password.py' =>
'src/attic/cmd_password.py'
=== renamed file 'src/mailman/commands/cmd_remove.py' =>
'src/attic/cmd_remove.py'
=== renamed file 'src/mailman/commands/cmd_set.py' => 'src/attic/cmd_set.py'
=== renamed file 'src/mailman/commands/cmd_unsubscribe.py' =>
'src/attic/cmd_unsubscribe.py'
=== renamed file 'src/mailman/commands/cmd_who.py' => 'src/attic/cmd_who.py'
=== modified file 'src/mailman/__init__.py'
--- src/mailman/__init__.py 2007-01-19 04:38:06 +0000
+++ src/mailman/__init__.py 2009-03-29 20:40:22 +0000
@@ -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
=== modified file 'src/mailman/app/commands.py'
--- src/mailman/app/commands.py 2009-03-10 03:42:21 +0000
+++ src/mailman/app/commands.py 2009-03-29 20:40:22 +0000
@@ -25,9 +25,9 @@
]
-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 @@
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()
=== added file 'src/mailman/app/finder.py'
--- src/mailman/app/finder.py 1970-01-01 00:00:00 +0000
+++ src/mailman/app/finder.py 2009-03-29 20:40:22 +0000
@@ -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
=== modified file 'src/mailman/commands/__init__.py'
--- src/mailman/commands/__init__.py 2009-01-01 22:16:51 +0000
+++ src/mailman/commands/__init__.py 2009-03-29 20:40:22 +0000
@@ -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',
- ]
=== modified file 'src/mailman/core/pipelines.py'
--- src/mailman/core/pipelines.py 2009-03-10 03:49:20 +0000
+++ src/mailman/core/pipelines.py 2009-03-29 20:40:22 +0000
@@ -29,11 +29,11 @@
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 @@
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, (
=== modified file 'src/mailman/core/rules.py'
--- src/mailman/core/rules.py 2009-03-10 03:54:22 +0000
+++ src/mailman/core/rules.py 2009-03-29 20:40:22 +0000
@@ -27,16 +27,16 @@
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, (
=== modified file 'src/mailman/interfaces/command.py'
--- src/mailman/interfaces/command.py 2009-01-17 02:04:21 +0000
+++ src/mailman/interfaces/command.py 2009-03-29 20:40:22 +0000
@@ -66,3 +66,8 @@
:return: A `ContinueProcessing` enum specifying whether to continue
processing or not.
"""
+
+
+
+class IBinCommand(Interface):
+ """A command line (i.e. bin) command."""
=== modified file 'src/mailman/pipeline/__init__.py'
--- src/mailman/pipeline/__init__.py 2009-03-29 15:14:58 +0000
+++ src/mailman/pipeline/__init__.py 2009-03-29 20:40:22 +0000
@@ -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
=== modified file 'src/mailman/rules/__init__.py'
--- src/mailman/rules/__init__.py 2009-03-29 15:14:58 +0000
+++ src/mailman/rules/__init__.py 2009-03-29 20:40:22 +0000
@@ -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
--
Primary development focus
https://code.launchpad.net/~mailman-coders/mailman/3.0
Your team Mailman Checkins is subscribed to branch lp:mailman.
To unsubscribe from this branch go to
https://code.launchpad.net/~mailman-coders/mailman/3.0/+edit-subscription.
_______________________________________________
Mailman-checkins mailing list
[email protected]
Unsubscribe:
http://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org