Changeset View
Changeset View
Standalone View
Standalone View
pykolab/plugins/__init__.py
Show First 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | def check_plugins(self): | ||||
True (loadable) or False -- not enabled, not installed or | True (loadable) or False -- not enabled, not installed or | ||||
not loadable. | not loadable. | ||||
""" | """ | ||||
for plugin in self.plugins: | for plugin in self.plugins: | ||||
try: | try: | ||||
exec("from pykolab.plugins import %s" % (plugin)) | exec("from pykolab.plugins import %s" % (plugin)) | ||||
self.plugins[plugin] = True | self.plugins[plugin] = True | ||||
self.load_plugins(plugins=[plugin]) | self.load_plugins(plugins=[plugin]) | ||||
except ImportError, e: | except ImportError as e: | ||||
log.error(_("ImportError for plugin %s: %s") % (plugin, e)) | log.error(_("ImportError for plugin %s: %s") % (plugin, e)) | ||||
traceback.print_exc() | traceback.print_exc() | ||||
self.plugins[plugin] = False | self.plugins[plugin] = False | ||||
except RuntimeError, e: | except RuntimeError as e: | ||||
log.error( _("RuntimeError for plugin %s: %s") % (plugin, e)) | log.error( _("RuntimeError for plugin %s: %s") % (plugin, e)) | ||||
traceback.print_exc() | traceback.print_exc() | ||||
self.plugins[plugin] = False | self.plugins[plugin] = False | ||||
except Exception, e: | except Exception as e: | ||||
log.error(_("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() | traceback.print_exc() | ||||
except: | except: | ||||
traceback.print_exc() | traceback.print_exc() | ||||
def load_plugins(self, plugins=[]): | def load_plugins(self, plugins=[]): | ||||
""" | """ | ||||
Loads plugins specified by a list of plugins or loads them all | Loads plugins specified by a list of plugins or loads them all | ||||
Show All 21 Lines | def set_defaults(self, defaults, plugins=[]): | ||||
if not self.plugins[plugin]: | if not self.plugins[plugin]: | ||||
continue | continue | ||||
if not hasattr(self, plugin): | if not hasattr(self, plugin): | ||||
continue | continue | ||||
if hasattr(getattr(self, plugin), "set_defaults"): | if hasattr(getattr(self, plugin), "set_defaults"): | ||||
try: | try: | ||||
getattr(self, plugin).set_defaults(defaults) | getattr(self, plugin).set_defaults(defaults) | ||||
except TypeError, e: | except TypeError as e: | ||||
log.error(_("Cannot set defaults for plugin %s: %s") % (plugin, e)) | log.error(_("Cannot set defaults for plugin %s: %s") % (plugin, e)) | ||||
except RuntimeError, e: | except RuntimeError as e: | ||||
log.error(_("Cannot set defaults for plugin %s: %s") % (plugin, e)) | log.error(_("Cannot set defaults for plugin %s: %s") % (plugin, e)) | ||||
except: | except: | ||||
log.error(_("Cannot set defaults for plugin %s: Unknown Error") % (plugin)) | log.error(_("Cannot set defaults for plugin %s: Unknown Error") % (plugin)) | ||||
else: | else: | ||||
log.debug(_("Not setting defaults for plugin %s: No function 'set_defaults()'") % plugin, level=5) | log.debug(_("Not setting defaults for plugin %s: No function 'set_defaults()'") % plugin, level=5) | ||||
def set_runtime(self, runtime, plugins=[]): | def set_runtime(self, runtime, plugins=[]): | ||||
""" | """ | ||||
Set runtime variables from plugins, like 'i_did_all_this' | Set runtime variables from plugins, like 'i_did_all_this' | ||||
""" | """ | ||||
if len(plugins) < 1: | if len(plugins) < 1: | ||||
plugins = self.plugins.keys() | plugins = self.plugins.keys() | ||||
for plugin in plugins: | for plugin in plugins: | ||||
if not self.plugins[plugin]: | if not self.plugins[plugin]: | ||||
continue | continue | ||||
if not hasattr(self, plugin): | if not hasattr(self, plugin): | ||||
continue | continue | ||||
if hasattr(getattr(self, plugin), "set_runtime"): | if hasattr(getattr(self, plugin), "set_runtime"): | ||||
try: | try: | ||||
getattr(self, plugin).set_runtime(runtime) | getattr(self, plugin).set_runtime(runtime) | ||||
except RuntimeError, e: | except RuntimeError as e: | ||||
log.error(_("Cannot set runtime for plugin %s: %s") % (plugin, e)) | log.error(_("Cannot set runtime for plugin %s: %s") % (plugin, e)) | ||||
else: | else: | ||||
log.debug(_("Not setting runtime for plugin %s: No function 'set_runtime()'") % (plugin), level=5) | log.debug(_("Not setting runtime for plugin %s: No function 'set_runtime()'") % (plugin), level=5) | ||||
def add_options(self, parser, plugins=[]): | def add_options(self, parser, plugins=[]): | ||||
""" | """ | ||||
Add options specified in a plugin to parser. Takes a list of plugin names or does them all | Add options specified in a plugin to parser. Takes a list of plugin names or does them all | ||||
""" | """ | ||||
if len(plugins) < 1: | if len(plugins) < 1: | ||||
plugins = self.plugins.keys() | plugins = self.plugins.keys() | ||||
for plugin in plugins: | for plugin in plugins: | ||||
if not self.plugins[plugin]: | if not self.plugins[plugin]: | ||||
continue | continue | ||||
if not hasattr(self, plugin): | if not hasattr(self, plugin): | ||||
continue | continue | ||||
if hasattr(getattr(self, plugin), "add_options"): | if hasattr(getattr(self, plugin), "add_options"): | ||||
try: | try: | ||||
exec("self.%s.add_options(parser)" % plugin) | exec("self.%s.add_options(parser)" % plugin) | ||||
except RuntimeError, e: | except RuntimeError as e: | ||||
log.error(_("Cannot add options for plugin %s: %s") % (plugin, e)) | log.error(_("Cannot add options for plugin %s: %s") % (plugin, e)) | ||||
except TypeError, e: | except TypeError as e: | ||||
log.error(_("Cannot add options for plugin %s: %s") % (plugin, e)) | log.error(_("Cannot add options for plugin %s: %s") % (plugin, e)) | ||||
else: | else: | ||||
log.debug(_("Not adding options for plugin %s: No function 'add_options()'") % plugin, level=5) | log.debug(_("Not adding options for plugin %s: No function 'add_options()'") % plugin, level=5) | ||||
def check_options(self, plugins=[]): | def check_options(self, plugins=[]): | ||||
""" | """ | ||||
Executes plugin.check_plugins() for all enabled plugins or the list of plugin names specified. | Executes plugin.check_plugins() for all enabled plugins or the list of plugin names specified. | ||||
""" | """ | ||||
if len(plugins) < 1: | if len(plugins) < 1: | ||||
plugins = self.plugins.keys() | plugins = self.plugins.keys() | ||||
for plugin in plugins: | for plugin in plugins: | ||||
if not self.plugins[plugin]: | if not self.plugins[plugin]: | ||||
continue | continue | ||||
if not hasattr(self, plugin): | if not hasattr(self, plugin): | ||||
continue | continue | ||||
if hasattr(getattr(self, plugin), "check_options"): | if hasattr(getattr(self, plugin), "check_options"): | ||||
try: | try: | ||||
exec("self.%s.check_options()" % plugin) | exec("self.%s.check_options()" % plugin) | ||||
except AttributeError, e: | except AttributeError as e: | ||||
log.error(_("Cannot check options for plugin %s: %s") % (plugin, e)) | log.error(_("Cannot check options for plugin %s: %s") % (plugin, e)) | ||||
else: | else: | ||||
log.debug(_("Not checking options for plugin %s: No function 'check_options()'") % (plugin), level=5) | log.debug(_("Not checking options for plugin %s: No function 'check_options()'") % (plugin), level=5) | ||||
def plugin_check_setting(self, func, option, val, plugins=[]): | def plugin_check_setting(self, func, option, val, plugins=[]): | ||||
""" | """ | ||||
Checks one setting specified by 'option' against the 'val' it is passed by all plugins or by the list of plugins specified | Checks one setting specified by 'option' against the 'val' it is passed by all plugins or by the list of plugins specified | ||||
""" | """ | ||||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | def return_true_boolean_from_plugins(self, bool, plugins=[]): | ||||
if not self.plugins[plugin]: | if not self.plugins[plugin]: | ||||
continue | continue | ||||
if not hasattr(self, plugin): | if not hasattr(self, plugin): | ||||
continue | continue | ||||
if hasattr(getattr(self, plugin), bool): | if hasattr(getattr(self, plugin), bool): | ||||
try: | try: | ||||
exec("boolval = self.%s.%s" % (plugin, bool)) | exec("boolval = self.%s.%s" % (plugin, bool)) | ||||
except AttributeError, e: | except AttributeError: | ||||
pass | pass | ||||
else: | else: | ||||
boolval = None | boolval = None | ||||
if boolval: retval = True | if boolval: retval = True | ||||
return retval | return retval |