Skip to content
Snippets Groups Projects
Commit f17cb4bc authored by Dominic Kempf's avatar Dominic Kempf
Browse files

Enable type conversion of form options

parent 6f9e551b
No related branches found
No related tags found
No related merge requests found
......@@ -123,21 +123,20 @@ def update_options_from_commandline(opt):
def update_options_from_inifile(opt):
""" Return an options array object with updated values from an inifile """
if opt.ini_file:
def parse_ini(section):
def parse_ini(section, opttype):
def _fix_types(k, v):
if hasattr(type(opt), k) and getattr(type(opt), k).type is bool:
if hasattr(opttype, k) and getattr(opttype, k).type is bool:
return bool(eval(v))
if hasattr(type(opt), k):
return getattr(type(opt), k).type(v)
if hasattr(opttype, k):
return getattr(opttype, k).type(v)
return v
ini = parse_ini_file(opt.ini_file).get(section, {})
return {k: _fix_types(k, v) for k, v in ini.items()}
opt = opt.copy(**parse_ini("formcompiler"))
opt = opt.copy(**parse_ini("formcompiler", PerftoolGlobalOptionsArray))
# Also parse form-specific options
for form in [i.strip() for i in opt.operators.split(",")]:
_form_options[form] = PerftoolFormOptionsArray(**parse_ini("formcompiler.{}".format(form)))
_form_options[form] = PerftoolFormOptionsArray(**parse_ini("formcompiler.{}".format(form), PerftoolFormOptionsArray))
return opt
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment