diff options
Diffstat (limited to 'ipsilon/util')
-rw-r--r-- | ipsilon/util/config.py | 38 | ||||
-rw-r--r-- | ipsilon/util/plugin.py | 39 |
2 files changed, 38 insertions, 39 deletions
diff --git a/ipsilon/util/config.py b/ipsilon/util/config.py index 947c697..523601d 100644 --- a/ipsilon/util/config.py +++ b/ipsilon/util/config.py @@ -322,3 +322,41 @@ class Condition(Pick): def import_value(self, value): self._assigned_value = value == 'True' + + +class ConfigHelper(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) diff --git a/ipsilon/util/plugin.py b/ipsilon/util/plugin.py index 1035ca8..be6dd2f 100644 --- a/ipsilon/util/plugin.py +++ b/ipsilon/util/plugin.py @@ -19,7 +19,6 @@ import os import imp import cherrypy import inspect -from ipsilon.util.config import Config from ipsilon.util.data import AdminStore from ipsilon.util.log import Log @@ -213,41 +212,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) |