diff --git a/odin/adapters/parameter_tree.py b/odin/adapters/parameter_tree.py index 3d17fc81..2623a6d6 100644 --- a/odin/adapters/parameter_tree.py +++ b/odin/adapters/parameter_tree.py @@ -7,6 +7,7 @@ James Hogge, Tim Nicholls, STFC Application Engineering Group. """ +from platform import node class ParameterTreeError(Exception): @@ -203,13 +204,20 @@ def __recursive_build_tree(self, node, path=''): # Convert list or non-callable tuple to enumerated dict ; TODO - remove this? if isinstance(node, list) or isinstance(node, tuple): - node = {str(i): node[i] for i in range(len(node))} + #print "BUILD 1 I AM AT ", type(node), "node", node, "path", path + + return [self.__recursive_build_tree(elem, path=path) for elem in node] + #node = {str(i): node[i] for i in range(len(node))} # Recursively check child elements if isinstance(node, dict): + #print "BUILD 2 I AM AT ", type(node), "node", node, "path", path return {k: self.__recursive_build_tree( v, path=path + k + '/') for k, v in node.items()} - + + #if isinstance(node, list) or isinstance(node, tuple): + #print "BUILD 3 I AM AT ", type(node), "node", node, "path", path + return node def __recursive_populate_tree(self, node): @@ -224,13 +232,20 @@ def __recursive_populate_tree(self, node): """ # If this is a branch node recurse down the tree if isinstance(node, dict): + #print "POPULATE 1 I AM AT", type(node), "node", node return {k: self.__recursive_populate_tree(v) for k, v in node.items()} + if isinstance(node, list) or isinstance(node, tuple): + #print "POPULATE 2 I AM AT", type(node), "node", node + return [self.__recursive_populate_tree(item) for item in node] + # If this is a leaf node, check if the leaf is a r/w tuple and substitute the # read element of that tuple into the node if isinstance(node, ParameterAccessor): + #print "POPULATE 3 I AM AT", type(node), "node", node return node.get() + #print "POPULATE 4 I AM AT", type(node), "node", node return node # Replaces values in data_tree with values from new_data