:rtype: :py:class:`Cnf`
All additional keyword arguments will be used to overwrite the defaults.
+ They cannot add new variables, not present in defaults.
"""
log.info(f"Generating a template {name} cnfvar")
cnf = Cnf(name, value=value, instance=instance)
defaults = {} if defaults is None else defaults
- cnf.add_children(*[(key, value) for key, value in defaults.items()])
+ for key, value in defaults.items():
+ if isinstance(value, dict):
+ sub_children = value.pop("children")
+ new_child = Cnf(name=key, **value)
+ new_child.add_children(*sub_children)
+ cnf.add_child(new_child)
+ else:
+ cnf.add_child(key, value)
+ prefix = name.lower() + "_"
for key in kwargs.keys():
- cnf.children.single_with_name(f"{name}_{key}").value = kwargs[key]
+ if key.lower().startswith(prefix):
+ log.warning(f"For overwriting template params, omit the leading name "
+ f"(here: {name}_) from keys (here: {key})")
+ cnf.children.single_with_name(f"{prefix}{key}").value = kwargs[key]
return cnf