Merge lp:~divmod-dev/divmod.org/simplify-metaASC-3030 into lp:divmod.org

Proposed by Tristan Seligmann
Status: Merged
Approved by: Jonathan Jacobs
Approved revision: 2676
Merged at revision: 2681
Proposed branch: lp:~divmod-dev/divmod.org/simplify-metaASC-3030
Merge into: lp:divmod.org
Diff against target: 79 lines (+30/-9)
1 file modified
Axiom/axiom/scripts/axiomatic.py (+30/-9)
To merge this branch: bzr merge lp:~divmod-dev/divmod.org/simplify-metaASC-3030
Reviewer Review Type Date Requested Status
Jonathan Jacobs Approve
Review via email: mp+72321@code.launchpad.net

Description of the change

Simplify the metaclass trickery that makes subclasses of AxiomaticCommand automatically provide IPlugin and IAxiomaticCommand.

To post a comment you must log in.
Revision history for this message
Jonathan Jacobs (jjacobs) wrote :

Looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'Axiom/axiom/scripts/axiomatic.py'
--- Axiom/axiom/scripts/axiomatic.py 2009-06-22 20:54:01 +0000
+++ Axiom/axiom/scripts/axiomatic.py 2011-08-21 02:40:49 +0000
@@ -1,5 +1,5 @@
1# -*- test-case-name: axiomatic.test.test_axiomatic -*-1# -*- test-case-name: axiomatic.test.test_axiomatic -*-
2from zope.interface import directlyProvides2from zope.interface import alsoProvides, noLongerProvides
33
4import os4import os
5import sys5import sys
@@ -7,12 +7,12 @@
7import errno7import errno
8import signal8import signal
99
10from twisted import plugin10from twisted.plugin import IPlugin, getPlugins
11from twisted.python import usage11from twisted.python import usage
12from twisted.python.runtime import platform12from twisted.python.runtime import platform
13from twisted.scripts import twistd13from twisted.scripts import twistd
1414
15from axiom import iaxiom15from axiom.iaxiom import IAxiomaticCommand
1616
17class AxiomaticSubCommandMixin(object):17class AxiomaticSubCommandMixin(object):
18 store = property(lambda self: self.parent.getStore())18 store = property(lambda self: self.parent.getStore())
@@ -23,18 +23,39 @@
23 codec = getattr(sys.stdin, 'encoding', None) or sys.getdefaultencoding()23 codec = getattr(sys.stdin, 'encoding', None) or sys.getdefaultencoding()
24 return unicode(cmdline, codec)24 return unicode(cmdline, codec)
2525
26class _metaASC(type):26
27
28class _AxiomaticCommandMeta(type):
29 """
30 Metaclass for L{AxiomaticCommand}.
31
32 This serves to make subclasses provide L{IPlugin} and L{IAxiomaticCommand}.
33 """
27 def __new__(cls, name, bases, attrs):34 def __new__(cls, name, bases, attrs):
28 newcls = type.__new__(cls, name, bases, attrs)35 newcls = type.__new__(cls, name, bases, attrs)
29 if not (newcls.__name__ == 'AxiomaticCommand' and newcls.__module__ == _metaASC.__module__):36 alsoProvides(newcls, IPlugin, IAxiomaticCommand)
30 directlyProvides(newcls, plugin.IPlugin, iaxiom.IAxiomaticCommand)
31 return newcls37 return newcls
3238
39
40
33class AxiomaticSubCommand(usage.Options, AxiomaticSubCommandMixin):41class AxiomaticSubCommand(usage.Options, AxiomaticSubCommandMixin):
34 pass42 """
43 L{twisted.python.usage.Options} subclass for Axiomatic sub commands.
44 """
45
46
3547
36class AxiomaticCommand(usage.Options, AxiomaticSubCommandMixin):48class AxiomaticCommand(usage.Options, AxiomaticSubCommandMixin):
37 __metaclass__ = _metaASC49 """
50 L{twisted.python.usage.Options} subclass for Axiomatic plugin commands.
51
52 Subclass this to have your class automatically provide the necessary
53 interfaces to be picked up by axiomatic.
54 """
55 __metaclass__ = _AxiomaticCommandMeta
56
57noLongerProvides(AxiomaticCommand, IPlugin)
58noLongerProvides(AxiomaticCommand, IAxiomaticCommand)
3859
3960
4061
@@ -119,7 +140,7 @@
119 yield ('status', None, Status, 'Report whether a server is running from the given Axiom database')140 yield ('status', None, Status, 'Report whether a server is running from the given Axiom database')
120141
121 from axiom import plugins142 from axiom import plugins
122 for plg in plugin.getPlugins(iaxiom.IAxiomaticCommand, plugins):143 for plg in getPlugins(IAxiomaticCommand, plugins):
123 try:144 try:
124 yield (plg.name, None, plg, plg.description)145 yield (plg.name, None, plg, plg.description)
125 except AttributeError:146 except AttributeError:

Subscribers

People subscribed via source and target branches

to all changes: