summaryrefslogtreecommitdiffstats
path: root/pykolab/plugins/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'pykolab/plugins/__init__.py')
-rw-r--r--pykolab/plugins/__init__.py69
1 files changed, 32 insertions, 37 deletions
diff --git a/pykolab/plugins/__init__.py b/pykolab/plugins/__init__.py
index 116b777..8ef44f8 100644
--- a/pykolab/plugins/__init__.py
+++ b/pykolab/plugins/__init__.py
@@ -20,32 +20,31 @@
import logging
import os
import pdb
-import pykolab
import sys
import traceback
+import pykolab
+
if False:
import pykolab.plugins.defaultfolders
import pykolab.plugins.dynamicquota
import pykolab.plugins.recipientpolicy
-# Translation
from pykolab.translate import _
-class KolabPlugins:
+log = pykolab.getLogger('pykolab.plugins')
+conf = pykolab.getConf()
+
+class KolabPlugins(object):
"""
Detects, loads and interfaces with plugins for different
Kolab components.
"""
- def __init__(self, init=False, conf=None):
+ def __init__(self):
"""
Searches the plugin directory for plugins, and loads
them into a list.
"""
- self.conf = conf
-
- self.log = logging.getLogger('pykolab.plugins')
-
self.plugins = {}
for plugin_path in [ '/usr/share/pykolab/plugins', './pykolab/plugins' ]:
@@ -54,9 +53,9 @@ class KolabPlugins:
if os.path.isdir('%s/%s/' %(plugin_path,plugin,)):
self.plugins[plugin] = False
- self.check_plugins(init=init)
+ self.check_plugins()
- def check_plugins(self, init=False):
+ def check_plugins(self):
"""
Checks all plugins in self.plugins and sets the values to
True (loadable) or False -- not enabled, not installed or
@@ -66,22 +65,22 @@ class KolabPlugins:
try:
exec("from pykolab.plugins import %s" %(plugin))
self.plugins[plugin] = True
- self.load_plugins(plugins=[plugin], init=init)
+ self.load_plugins(plugins=[plugin])
except ImportError, e:
- if not init: print >> sys.stderr, _("ImportError for plugin %s: %s") % (plugin,e)
+ log.error(_("ImportError for plugin %s: %s") % (plugin,e))
traceback.print_exc()
self.plugins[plugin] = False
except RuntimeError, e:
- if not init: print >> sys.stderr, _("RuntimeError for plugin %s: %s") % (plugin,e)
+ log.error( _("RuntimeError for plugin %s: %s") % (plugin,e))
traceback.print_exc()
self.plugins[plugin] = False
except Exception, e:
- if not init: print >> sys.stderr, _("Plugin %s failed to load (%s: %s)") % (plugin, e.__class__, e)
+ log.error(_("Plugin %s failed to load (%s: %s)") % (plugin, e.__class__, e))
traceback.print_exc()
except:
traceback.print_exc()
- def load_plugins(self, plugins=[], init=False):
+ def load_plugins(self, plugins=[]):
"""
Loads plugins specified by a list of plugins or loads them all
"""
@@ -92,7 +91,7 @@ class KolabPlugins:
for plugin in plugins:
if self.plugins[plugin]:
try:
- exec("self.%s = %s.Kolab%s(conf=self.conf)" % (plugin,plugin,plugin.capitalize()))
+ exec("self.%s = %s.Kolab%s()" % (plugin,plugin,plugin.capitalize()))
except:
# TODO: A little better verbosity please!
traceback.print_exc()
@@ -114,17 +113,14 @@ class KolabPlugins:
try:
getattr(self,plugin).set_defaults(defaults)
except TypeError, e:
- print >> sys.stderr, _("Cannot set defaults for plugin %s: %s") % (plugin,e)
+ log.error(_("Cannot set defaults for plugin %s: %s") % (plugin,e))
except RuntimeError, e:
- print >> sys.stderr, _("Cannot set defaults for plugin %s: %s") % (plugin,e)
+ log.error(_("Cannot set defaults for plugin %s: %s") % (plugin,e))
except:
- print >> sys.stderr, _("Cannot set defaults for plugin %s: Unknown Error") % (plugin)
+ log.error(_("Cannot set defaults for plugin %s: Unknown Error") % (plugin))
else:
- if hasattr(self.conf, "log"):
- self.conf.log.debug(_("Not setting defaults for plugin %s: No function 'set_defaults()'") % plugin, level=5)
- else:
- print >> sys.stderr, _("Not setting defaults for plugin %s: No function 'set_defaults()'") % plugin
+ log.debug(_("Not setting defaults for plugin %s: No function 'set_defaults()'") % plugin, level=5)
def set_runtime(self, runtime, plugins=[]):
"""
@@ -143,9 +139,9 @@ class KolabPlugins:
try:
getattr(self,plugin).set_runtime(runtime)
except RuntimeError, e:
- print >> sys.stderr, _("Cannot set runtime for plugin %s: %s") % (plugin,e)
+ log.error(_("Cannot set runtime for plugin %s: %s") % (plugin,e))
else:
- print >> sys.stderr, _("Not setting runtime for plugin %s: No function 'set_runtime()'") % plugin
+ log.debug(_("Not setting runtime for plugin %s: No function 'set_runtime()'") % (plugin), level=5)
def add_options(self, parser, plugins=[]):
"""
@@ -164,14 +160,13 @@ class KolabPlugins:
try:
exec("self.%s.add_options(parser)" % plugin)
except RuntimeError, e:
- print >> sys.stderr, _("Cannot add options for plugin %s: %s") % (plugin,e)
+ log.error(_("Cannot add options for plugin %s: %s") % (plugin,e))
+ except TypeError, e:
+ log.error(_("Cannot add options for plugin %s: %s") % (plugin,e))
else:
- if hasattr(self.conf, "log"):
- self.conf.log.debug(_("Not adding options for plugin %s: No function 'add_options()'") % plugin, level=5)
- else:
- print >> sys.stderr, _("Not adding options for plugin %s: No function 'add_options()'") % plugin
+ log.debug(_("Not adding options for plugin %s: No function 'add_options()'") % plugin, level=5)
- def check_options(self, conf, plugins=[]):
+ def check_options(self, plugins=[]):
"""
Executes plugin.check_plugins() for all enabled plugins or the list of plugin names specified.
"""
@@ -187,11 +182,11 @@ class KolabPlugins:
if hasattr(getattr(self,plugin),"check_options"):
try:
- exec("self.%s.check_options(conf, conf.cli_options)" % plugin)
+ exec("self.%s.check_options()" % plugin)
except AttributeError, e:
- print >> sys.stderr, _("Cannot check options for plugin %s: %s") % (plugin,e)
+ log.error(_("Cannot check options for plugin %s: %s") % (plugin,e))
else:
- print >> sys.stderr, _("Not checking options for plugin %s: No function 'check_options()'") % plugin
+ log.debug(_("Not checking options for plugin %s: No function 'check_options()'") %(plugin), level=5)
def plugin_check_setting(self, func, option, val, plugins=[]):
"""
@@ -229,11 +224,11 @@ class KolabPlugins:
if hasattr(getattr(self,plugin),hook):
try:
- exec("retval = self.%s.%s(kw=%r, args=%r)" % (plugin,hook,kw,args))
+ exec("retval = self.%s.%s(*args, **kw)" %(plugin,hook))
except TypeError, e:
- print >> sys.stderr, _("Cannot execute hook %s for plugin %s: %s") % (hook,plugin,e)
+ log.error(_("Cannot execute hook %s for plugin %s: %s") %(hook,plugin,e))
except AttributeError, e:
- print >> sys.stderr, _("Cannot execute hook %s for plugin %s: %s") % (hook,plugin,e)
+ log.error(_("Cannot execute hook %s for plugin %s: %s") %(hook,plugin,e))
return retval