diff options
author | Alexander Sulfrian <alexander@sulfrian.net> | 2013-06-18 20:52:31 +0200 |
---|---|---|
committer | Alexander Sulfrian <alexander@sulfrian.net> | 2013-06-28 14:23:48 +0200 |
commit | b9022e96e1353dab0843e6341239469dec773b1f (patch) | |
tree | 64bf3a0329e26e75a8544448aca722e603ec9ef6 | |
parent | 1c2f6df17aeeb5af01a75e959e7c71aedf4df6a8 (diff) | |
download | bcfg2-b9022e96e1353dab0843e6341239469dec773b1f.tar.gz bcfg2-b9022e96e1353dab0843e6341239469dec773b1f.tar.bz2 bcfg2-b9022e96e1353dab0843e6341239469dec773b1f.zip |
Opitons: add cook function to parse a dict for the config file
-rw-r--r-- | src/lib/Bcfg2/Options.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/lib/Bcfg2/Options.py b/src/lib/Bcfg2/Options.py index 243c4ed2a..f027268e1 100644 --- a/src/lib/Bcfg2/Options.py +++ b/src/lib/Bcfg2/Options.py @@ -319,6 +319,28 @@ def colon_split(c_string): return [] +def dict_split(c_string): + """ split an option string on commans, optionally sourrunded by + whitespace and split the resulting items again on equals signs, + returning a dict """ + result = dict() + if c_string: + items = re.split(r'\s*,\s*', c_string) + for item in items: + if r'=' in item: + key, value = item.split(r'=', 1) + try: + result[key] = get_bool(value) + except ValueError: + try: + result[key] = get_int(value) + except ValueError: + result[key] = value + else: + result[item] = True + return result + + def get_bool(val): """ given a string value of a boolean configuration option, return an actual bool (True or False) """ |