diff options
Diffstat (limited to 'ipsilon/util/config.py')
-rw-r--r-- | ipsilon/util/config.py | 38 |
1 files changed, 38 insertions, 0 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) |