diff options
author | Simo Sorce <simo@redhat.com> | 2014-10-14 11:57:28 -0400 |
---|---|---|
committer | Patrick Uiterwijk <puiterwijk@redhat.com> | 2014-10-24 18:02:20 +0200 |
commit | c6fab2542f52f6cca71c207c1925785971e51295 (patch) | |
tree | 83c4bb441c7eb62c41b8b58c738e070bde674045 /ipsilon/util | |
parent | cecf9f6c60a048f4f7c947a969f1610695d1d3be (diff) | |
download | ipsilon.git-c6fab2542f52f6cca71c207c1925785971e51295.tar.gz ipsilon.git-c6fab2542f52f6cca71c207c1925785971e51295.tar.xz ipsilon.git-c6fab2542f52f6cca71c207c1925785971e51295.zip |
Handle lists type options in plugins configuration
Autodetect and convert config values based on the options definition.
If the option is marked as list split a string on setting the configuration
or join the list into a string before saving it to the database.
Signed-off-by: Simo Sorce <simo@redhat.com>
Diffstat (limited to 'ipsilon/util')
-rwxr-xr-x | ipsilon/util/plugin.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/ipsilon/util/plugin.py b/ipsilon/util/plugin.py index 48edf0e..9222a35 100755 --- a/ipsilon/util/plugin.py +++ b/ipsilon/util/plugin.py @@ -132,8 +132,23 @@ class PluginObject(Log): return '' return opt[0] + def _value_to_list(self, name): + if name not in self._config: + return + value = self._config[name] + if type(value) is list: + return + vlist = [x.strip() for x in value.split(',')] + self._config[name] = vlist + def set_config(self, config): self._config = config + if self._config is None: + return + if self._options: + for name, opt in self._options.iteritems(): + if opt[1] == 'list': + self._value_to_list(name) def get_config_value(self, name): value = None @@ -154,6 +169,9 @@ class PluginObject(Log): if not self._config: self._config = dict() self._config[option] = value + if self._options and option in self._options: + if self._options[option][1] == 'list': + self._value_to_list(option) def get_plugin_config(self, facility): return self._data.load_options(facility, self.name) @@ -165,6 +183,12 @@ class PluginObject(Log): def save_plugin_config(self, facility, config=None): if config is None: config = self._config + config = config.copy() + + for key, value in config.items(): + if type(value) is list: + config[key] = ','.join(value) + self._data.save_options(facility, self.name, config) def get_data(self, idval=None, name=None, value=None): |