diff options
author | Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com> | 2011-09-21 12:19:36 +0100 |
---|---|---|
committer | Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com> | 2011-09-21 12:19:36 +0100 |
commit | 75a73b7182a7e5b2cc14331503c110591e6571e4 (patch) | |
tree | 6daff675afdb178578db9437411da88836eddb76 /pykolab/conf/__init__.py | |
parent | 038ef94e3b58484e3907f982ed2748e8936f37c3 (diff) | |
download | pykolab-75a73b7182a7e5b2cc14331503c110591e6571e4.tar.gz |
Add conf.get_list() function to retrieve a python list from a comma and/or space seperated list
Diffstat (limited to 'pykolab/conf/__init__.py')
-rw-r--r-- | pykolab/conf/__init__.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/pykolab/conf/__init__.py b/pykolab/conf/__init__.py index 295cd52..e9eaad3 100644 --- a/pykolab/conf/__init__.py +++ b/pykolab/conf/__init__.py @@ -439,6 +439,26 @@ class Conf(object): def has_option(self, section, option): return self.cfg_parser.has_option(section, option) + def get_list(self, section, key): + """ + Gets a comma and/or space seperated list from the configuration file + and returns a list. + """ + values = [] + untrimmed_values = [] + + setting = self.get_raw(section, key) + raw_values = setting.split(',') + + for raw_value in raw_values: + untrimmed_values.extend(raw_value.split(' ')) + + for value in untrimmed_values: + if not value.strip() == "": + values.append(value.strip().lower()) + + return values + def get_raw(self, section, key): if not self.cfg_parser: self.read_config() |