Skip to content
Snippets Groups Projects
Commit e346ddc6 authored by Karl-Hermann Wieners's avatar Karl-Hermann Wieners
Browse files

unmergeconfig: changed to insert globals into the appropriate section

parent 3ea194a3
No related branches found
No related tags found
No related merge requests found
......@@ -27,9 +27,12 @@ global_matcher = re.compile(r'\$(\w+)')
def get_globals(config, result):
for key in config.sections:
get_globals_section(config[key], key, config.scalars, result)
get_globals_section(config[key], key,
{s: '' for s in config.scalars}, result)
def get_globals_section(section, path, global_keys, result):
all_keys = global_keys.copy()
all_keys.update({s: path for s in section.scalars})
for key in section.scalars:
value = section[key]
if not isinstance(value, (list, tuple)):
......@@ -37,9 +40,10 @@ def get_globals_section(section, path, global_keys, result):
if match:
global_key = match.group(1)
if True: ### global_key in global_keys:
result[path+'/'+key] = global_key
result[path+'/'+key] = (global_key,
all_keys.get(global_key, ''))
for key in section.sections:
get_globals_section(section[key], path+'/'+key, global_keys, result)
get_globals_section(section[key], path+'/'+key, all_keys, result)
def eval_globals(config, global_dict):
for key in config.sections:
......@@ -51,16 +55,20 @@ def eval_globals_section(section, path, global_dict):
if not isinstance(value, (list, tuple)):
global_key = path+'/'+key
if global_key in global_dict:
global_var = global_dict[global_key]
if global_var in section.main:
if section.main[global_var] != value:
warn("global '%s' already set to '%s', "
"keeping '%s' at '%s'", global_var,
section.main[global_var], global_key, value)
global_var, global_path = global_dict[global_key]
global_section = section.main
if global_path:
for name in global_path.split('/'):
global_section = global_section[name]
if global_var in global_section:
if global_section[global_var] != value:
warn("global '%s' at '%s' already set to '%s', "
"keeping '%s' at '%s'", global_var, global_path,
global_section[global_var], global_key, value)
else:
section[key] = '$' + global_var
else:
section.main[global_var] = value
global_section[global_var] = value
section[key] = '$' + global_var
for key in section.sections:
eval_globals_section(section[key], path+'/'+key, global_dict)
......
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