summaryrefslogtreecommitdiffstats
path: root/src/lib/Bcfg2/Options/Types.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/Bcfg2/Options/Types.py')
-rw-r--r--src/lib/Bcfg2/Options/Types.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/lib/Bcfg2/Options/Types.py b/src/lib/Bcfg2/Options/Types.py
index 329c671ea..5769d674a 100644
--- a/src/lib/Bcfg2/Options/Types.py
+++ b/src/lib/Bcfg2/Options/Types.py
@@ -28,6 +28,28 @@ def colon_list(value):
return value.split(':')
+def comma_dict(value):
+ """ Split an option string on commas, optionally surrounded by
+ whitespace, and split the resulting items again on equals signs,
+ returning a dict """
+ result = dict()
+ if value:
+ items = comma_list(value)
+ for item in items:
+ if '=' in item:
+ key, value = item.split(r'=', 1)
+ try:
+ result[key] = bool(value)
+ except ValueError:
+ try:
+ result[key] = int(value)
+ except ValueError:
+ result[key] = value
+ else:
+ result[item] = True
+ return result
+
+
def octal(value):
""" Given an octal string, get an integer representation. """
return int(value, 8)