X-Git-Url: http://git.cascardo.info/?p=cascardo%2Fipsilon.git;a=blobdiff_plain;f=ipsilon%2Futil%2Fplugin.py;h=2f9c003e7fe740dedc815a7ee2d6c22bc84f656c;hp=ae98b4c49ebd648c35cecd83d638908e91f99df6;hb=aa5dc3b417db962a075a092d0d3528010c1059f7;hpb=b07ee59ded4f926a38cd1b30d7f8de7b568840a8 diff --git a/ipsilon/util/plugin.py b/ipsilon/util/plugin.py old mode 100755 new mode 100644 index ae98b4c..2f9c003 --- a/ipsilon/util/plugin.py +++ b/ipsilon/util/plugin.py @@ -1,5 +1,3 @@ -#!/usr/bin/python -# # Copyright (C) 2013 Simo Sorce # # see file 'COPYING' for use and warranty information @@ -21,7 +19,7 @@ import os import imp import cherrypy import inspect -from ipsilon.util.config import Config +import logging from ipsilon.util.data import AdminStore from ipsilon.util.log import Log @@ -33,7 +31,7 @@ class Plugins(object): def _load_class(self, tree, class_type, file_name, *pargs): cherrypy.log.error('Check module %s for class %s' % (file_name, - class_type)) + class_type), severity=logging.DEBUG) name, ext = os.path.splitext(os.path.split(file_name)[-1]) try: if ext.lower() == '.py': @@ -43,21 +41,24 @@ class Plugins(object): else: return except Exception, e: # pylint: disable=broad-except - cherrypy.log.error('Failed to load "%s" module: [%s]' % (name, e)) + cherrypy.log.error('Failed to load "%s" module: [%s]' % (name, e), + severity=logging.ERROR) return if hasattr(mod, class_type): instance = getattr(mod, class_type)(*pargs) public_name = getattr(instance, 'name', name) tree[public_name] = instance - cherrypy.log.error('Added module %s as %s' % (name, public_name)) + cherrypy.log.error('Added module %s as %s' % (name, public_name), + severity=logging.DEBUG) def _load_classes(self, tree, path, class_type, *pargs): files = None try: files = os.listdir(path) except Exception, e: # pylint: disable=broad-except - cherrypy.log.error('No modules in %s: [%s]' % (path, e)) + cherrypy.log.error('No modules in %s: [%s]' % (path, e), + severity=logging.ERROR) return for name in files: @@ -185,7 +186,11 @@ class PluginObject(Log): def refresh_plugin_config(self): config = self.get_plugin_config() if config: - self.import_config(config) + try: + self.import_config(config) + except Exception, e: # pylint: disable=broad-except + self.error('Failed to refresh config for %s (%s)' % + (self.name, e)) def save_plugin_config(self, config=None): if config is None: @@ -211,41 +216,3 @@ class PluginObject(Log): def wipe_data(self): self._data.wipe_data(self.name) - - -class PluginConfig(Log): - - def __init__(self): - self._config = None - - def new_config(self, name, *config_args): - self._config = Config(name, *config_args) - - def get_config_obj(self): - if self._config is None: - raise AttributeError('Config not initialized') - return self._config - - def import_config(self, config): - if not self._config: - raise AttributeError('Config not initialized, cannot import') - - for key, value in config.iteritems(): - if key in self._config: - self._config[key].import_value(str(value)) - - def export_config(self): - config = dict() - for name, option in self._config.iteritems(): - config[name] = option.export_value() - return config - - def get_config_value(self, name): - if not self._config: - raise AttributeError('Config not initialized') - return self._config[name].get_value() - - def set_config_value(self, name, value): - if not self._config: - raise AttributeError('Config not initialized') - return self._config[name].set_value(value)