[Twisted-Python] twisted plugins
Gabriel Rossetti
mailing_lists at evotex.ch
Mon Mar 3 08:44:12 EST 2008
Hello,
I tried creating some test plugins using the plugin howto on the twisted
website. I did as shown, I added the plugins dir to the PYTHONPATH and
tested it. The problem is I get nothing back when calling
getPlugins(IMyInterface). Here is some code :
----------------------------------------------------------------------------------------------
from zope.interface import Interface
class IHelloWorld(Interface):
"""
A simple test plugin that displays "Hello world"
"""
def display():
"""
Displays on stdout "Hello world" in a language chosen by the
programmer
"""
----------------------------------------------------------------------------------------------
from twisted.plugin import IPlugin
from zope.interface import implements
from interfaces import ihelloworld
class EnglishHelloWorld(object):
implements(IPlugin, ihelloworld.IHelloWorld)
def display(self):
"""
Displays on stdout "Hello world" in English
"""
print "Hello world!"
----------------------------------------------------------------------------------------------
from twisted.plugin import getPlugins
from twisted.plugin import IPlugin
from interfaces import ihelloworld
def displayHelloWorld():
for h in getPlugins(ihelloworld.IHelloWorld):
h().display()
if(__name__ == "__main__"):
displayHelloWorld()
----------------------------------------------------------------------------------------------
I tried running in debug mode to see what happens, but I don't get it,
in the getPlugins() code, it does this :
allDropins = getCache(package)
and in this dict I see my plugins, but their inner "plugin" member is an
empty list. I looked at the code of some of the examples, they used
"classProvides()" and not "implements()", so I tried that :
----------------------------------------------------------------------------------------------
from twisted.plugin import IPlugin
from zope.interface import implements
from zope.interface import classProvides
from interfaces import ihelloworld
class EnglishHelloWorld(object):
classProvides(IPlugin, ihelloworld.IHelloWorld)
def display(self):
"""
Displays on stdout "Hello world" in English
"""
print "Hello world!"
----------------------------------------------------------------------------------------------
which works, is the doc out of sync with the current code or did I do
something wrong? Another question, it's not really very practical to
have to iterate all the plugins and I guess test to see which one is
which, is there a better way of doing it?
Thank you,
Gabriel
More information about the Twisted-Python
mailing list