plugins now are checked for post_init having ran when process() is called

This commit is contained in:
Nathan Fritz 2010-05-26 10:51:51 -07:00
parent 9cfe19c1e1
commit f4bc9d9722
7 changed files with 13 additions and 4 deletions

View file

@ -85,8 +85,13 @@ class basexmpp(object):
self.jid = self.getjidbare(jid) self.jid = self.getjidbare(jid)
self.username = jid.split('@', 1)[0] self.username = jid.split('@', 1)[0]
self.server = jid.split('@',1)[-1].split('/', 1)[0] self.server = jid.split('@',1)[-1].split('/', 1)[0]
def process(self, *args, **kwargs):
for idx in self.plugin:
if not self.plugin[idx].post_inited: self.plugin[idx].post_init()
return super(basexmpp, self).process(*args, **kwargs)
def registerPlugin(self, plugin, pconfig = {}, run_post=True): def registerPlugin(self, plugin, pconfig = {}):
"""Register a plugin not in plugins.__init__.__all__ but in the plugins """Register a plugin not in plugins.__init__.__all__ but in the plugins
directory.""" directory."""
# discover relative "path" to the plugins module from the main app, and import it. # discover relative "path" to the plugins module from the main app, and import it.
@ -100,8 +105,6 @@ class basexmpp(object):
if hasattr(self.plugin[plugin], 'xep'): if hasattr(self.plugin[plugin], 'xep'):
xep = "(XEP-%s) " % self.plugin[plugin].xep xep = "(XEP-%s) " % self.plugin[plugin].xep
logging.debug("Loaded Plugin %s%s" % (xep, self.plugin[plugin].description)) logging.debug("Loaded Plugin %s%s" % (xep, self.plugin[plugin].description))
if run_post:
self.plugin[plugin].post_init()
def register_plugins(self): def register_plugins(self):
"""Initiates all plugins in the plugins/__init__.__all__""" """Initiates all plugins in the plugins/__init__.__all__"""

View file

@ -24,6 +24,7 @@ class base_plugin(object):
self.description = 'Base Plugin' self.description = 'Base Plugin'
self.xmpp = xmpp self.xmpp = xmpp
self.config = config self.config = config
self.post_inited = False
self.enable = config.get('enable', True) self.enable = config.get('enable', True)
if self.enable: if self.enable:
self.plugin_init() self.plugin_init()
@ -32,4 +33,4 @@ class base_plugin(object):
pass pass
def post_init(self): def post_init(self):
pass self.post_inited = True

View file

@ -31,6 +31,7 @@ class xep_0004(base.base_plugin):
self.xmpp.add_handler("<message><x xmlns='jabber:x:data' /></message>", self.handler_message_xform) self.xmpp.add_handler("<message><x xmlns='jabber:x:data' /></message>", self.handler_message_xform)
def post_init(self): def post_init(self):
base.base_plugin.post_init(self)
self.xmpp.plugin['xep_0030'].add_feature('jabber:x:data') self.xmpp.plugin['xep_0030'].add_feature('jabber:x:data')
def handler_message_xform(self, xml): def handler_message_xform(self, xml):

View file

@ -185,6 +185,7 @@ class xep_0009(base.base_plugin):
self.activeCalls = [] self.activeCalls = []
def post_init(self): def post_init(self):
base.base_plugin.post_init(self)
self.xmpp.plugin['xep_0030'].add_feature('jabber:iq:rpc') self.xmpp.plugin['xep_0030'].add_feature('jabber:iq:rpc')
self.xmpp.plugin['xep_0030'].add_identity('automatition','rpc') self.xmpp.plugin['xep_0030'].add_identity('automatition','rpc')

View file

@ -42,6 +42,7 @@ class xep_0050(base.base_plugin):
self.sd = self.xmpp.plugin['xep_0030'] self.sd = self.xmpp.plugin['xep_0030']
def post_init(self): def post_init(self):
base.base_plugin.post_init(self)
self.sd.add_feature('http://jabber.org/protocol/commands') self.sd.add_feature('http://jabber.org/protocol/commands')
def addCommand(self, node, name, form, pointer=None, multi=False): def addCommand(self, node, name, form, pointer=None, multi=False):

View file

@ -33,6 +33,7 @@ class xep_0092(base.base_plugin):
self.xmpp.add_handler("<iq type='get' xmlns='%s'><query xmlns='jabber:iq:version' /></iq>" % self.xmpp.default_ns, self.report_version) self.xmpp.add_handler("<iq type='get' xmlns='%s'><query xmlns='jabber:iq:version' /></iq>" % self.xmpp.default_ns, self.report_version)
def post_init(self): def post_init(self):
base.base_plugin.post_init(self)
self.xmpp.plugin['xep_0030'].add_feature('jabber:iq:version') self.xmpp.plugin['xep_0030'].add_feature('jabber:iq:version')
def report_version(self, xml): def report_version(self, xml):

View file

@ -35,6 +35,7 @@ class xep_0199(base.base_plugin):
#self.xmpp.add_event_handler('session_start', self.handler_pingserver, threaded=True) #self.xmpp.add_event_handler('session_start', self.handler_pingserver, threaded=True)
def post_init(self): def post_init(self):
base.base_plugin.post_init(self)
self.xmpp.plugin['xep_0030'].add_feature('http://www.xmpp.org/extensions/xep-0199.html#ns') self.xmpp.plugin['xep_0030'].add_feature('http://www.xmpp.org/extensions/xep-0199.html#ns')
def handler_pingserver(self, xml): def handler_pingserver(self, xml):