Commit 1e5e4ebd authored by Sebastien Petitdemange's avatar Sebastien Petitdemange
Browse files

config: fixed bliss plugin to get reference object in config node.

- now deep_copy change the parent with the copied parent =>
  get_inherited on reference object works.
parent 75570908
......@@ -9,16 +9,48 @@
from .utils import find_class_and_node, replace_reference_by_object
def _find_name_in_list(l, name):
for item in l:
if isinstance(item, dict):
find_node = _find_name_in_node(item, name)
if find_node is not None:
return find_node
elif isinstance(item, list):
find_node = _find_name_in_list(item, name)
if find_node is not None:
return find_node
def _find_name_in_node(node, name):
for key, value in node.items():
if key == "name" and value == name:
return node
if isinstance(value, dict):
find_node = _find_name_in_node(value, name)
if find_node is not None:
return find_node
elif isinstance(value, list):
find_node = _find_name_in_list(value, name)
if find_node is not None:
return find_node
def create_objects_from_config_node(config, cfg_node):
item_cfg_node = cfg_node.deep_copy()
klass, node = find_class_and_node(item_cfg_node)
klass, node = find_class_and_node(cfg_node)
node = node.deep_copy()
item_name = item_cfg_node["name"]
item_name = cfg_node["name"]
referenced_objects = dict()
if node.get("name") != item_name:
cfg_node = _find_name_in_node(node, item_name)
assert cfg_node is not None
else:
cfg_node = node
replace_reference_by_object(config, node, referenced_objects)
o = klass(item_name, item_cfg_node)
o = klass(item_name, cfg_node)
for name, object in referenced_objects.items():
if hasattr(o, name):
......
......@@ -327,12 +327,13 @@ class Node(dict):
if isinstance(value, Node):
child_node = value.deep_copy()
node[key] = child_node
child_node._parent = node
elif isinstance(value, dict):
child_node = Node()
child_node.update(value)
node[key] = child_node.deep_copy()
elif isinstance(value, list):
new_list = Node._copy_list(value)
new_list = Node._copy_list(value, node)
node[key] = new_list
else:
node[key] = value
......@@ -350,25 +351,29 @@ class Node(dict):
child_dict = value.to_dict()
newdict[key] = child_dict
elif isinstance(value, list):
new_list = Node._copy_list(value, dict_mode=True)
new_list = Node._copy_list(value, self, dict_mode=True)
newdict[key] = new_list
else:
newdict[key] = value
return newdict
@staticmethod
def _copy_list(l, dict_mode=False):
def _copy_list(l, parent, dict_mode=False):
new_list = list()
for v in l:
if isinstance(v, Node):
new_node = v.deep_copy() if not dict_mode else v.to_dict()
if dict_mode:
new_node = v.to_dict()
else:
new_node = v.deep_copy()
new_node._parent = parent
new_list.append(new_node)
elif isinstance(v, dict):
tmp_node = Node()
tmp_node.update(v)
new_list.append(tmp_node.deep_copy().to_dict())
elif isinstance(v, list):
child_list = Node._copy_list(v, dict_mode=dict_mode)
child_list = Node._copy_list(v, parent, dict_mode=dict_mode)
new_list.append(child_list)
else:
new_list.append(v)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment