From 257eb0c174ef2fdaa2015975c5919979afa8da90 Mon Sep 17 00:00:00 2001 From: Sol Jerome Date: Tue, 4 Nov 2014 09:57:08 -0600 Subject: Options.py: Fix database OPTIONS parsing Instead of parsing key/value pairs from bcfg2.conf, this allows the setting of the literal value which is then passed through to django as the value of the OPTIONS setting. This change allows for setting arbitrary options since some settings require nested dictionaries, etc. Signed-off-by: Sol Jerome --- src/lib/Bcfg2/Options.py | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/lib/Bcfg2/Options.py b/src/lib/Bcfg2/Options.py index 9752ab758..652e216a5 100644 --- a/src/lib/Bcfg2/Options.py +++ b/src/lib/Bcfg2/Options.py @@ -1,14 +1,16 @@ """Option parsing library for utilities.""" +import ast import copy import getopt +import grp import inspect import os +import pwd import re import shlex import sys -import grp -import pwd + import Bcfg2.Client.Tools from Bcfg2.Compat import ConfigParser from Bcfg2.version import __version__ @@ -329,25 +331,9 @@ def colon_split(c_string): def dict_split(c_string): - """ 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 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 + """ literally evaluate the option in order to allow for arbitrarily nested + dictionaries """ + return ast.literal_eval(c_string) def get_bool(val): -- cgit v1.2.3-1-g7c22