From 434bffc3b1ab4a74f0f23508e624e7427987aaf8 Mon Sep 17 00:00:00 2001 From: Rob Crittenden Date: Wed, 8 Apr 2015 09:44:14 -0400 Subject: Rename and move PluginConfig to ConfigHelper The configuration class was originally intended to be tied. At this point it is quite generic and useful outside of plugins. Rename it to something more generic and move it into the config module. https://fedorahosted.org/ipsilon/ticket/25 Signed-off-by: Rob Crittenden Reviewed-by: Simo Sorce --- ipsilon/util/config.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'ipsilon/util/config.py') 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) -- cgit