Reorganize features into plugins.

This commit is contained in:
Lance Stout
2011-06-30 15:40:22 -07:00
parent 9ed972ffeb
commit 754ac5092a
10 changed files with 391 additions and 198 deletions

View File

@@ -165,9 +165,14 @@ class BaseXMPP(XMLStream):
try:
# Import the given module that contains the plugin.
if not module:
module = sleekxmpp.plugins
module = __import__("%s.%s" % (module.__name__, plugin),
globals(), locals(), [plugin])
try:
module = sleekxmpp.plugins
module = __import__("%s.%s" % (module.__name__, plugin),
globals(), locals(), [plugin])
except ImportError:
module = sleekxmpp.features
module = __import__("%s.%s" % (module.__name__, plugin),
globals(), locals(), [plugin])
if isinstance(module, str):
# We probably want to load a module from outside
# the sleekxmpp package, so leave out the globals().
@@ -176,12 +181,14 @@ class BaseXMPP(XMLStream):
# Load the plugin class from the module.
self.plugin[plugin] = getattr(module, plugin)(self, pconfig)
# Let XEP implementing plugins have some extra logging info.
xep = ''
if hasattr(self.plugin[plugin], 'xep'):
xep = "(XEP-%s) " % self.plugin[plugin].xep
# Let XEP/RFC implementing plugins have some extra logging info.
spec = '(CUSTOM) '
if self.plugin[plugin].xep:
spec = "(XEP-%s) " % self.plugin[plugin].xep
elif self.plugin[plugin].rfc:
spec = "(RFC-%s) " % self.plugin[plugin].rfc
desc = (xep, self.plugin[plugin].description)
desc = (spec, self.plugin[plugin].description)
log.debug("Loaded Plugin %s%s" % desc)
except:
log.exception("Unable to load plugin: %s", plugin)