Commit a6f5920b authored by Wout De Nolf's avatar Wout De Nolf
Browse files

esftaskgraph: add defaults on loading

parent 0427bb8c
......@@ -13,6 +13,12 @@ def load_graph(source=None, representation=None):
return TaskGraph(source=source, representation=representation)
def set_graph_defaults(graph_as_dict):
graph_as_dict.setdefault("directed", True)
graph_as_dict.setdefault("nodes", list())
graph_as_dict.setdefault("links", list())
def node_has_links(graph, node_name):
try:
next(graph.successors(node_name))
......@@ -224,13 +230,16 @@ class TaskGraph:
elif isinstance(source, TaskGraph):
graph = source.graph
elif representation == self.GraphRepresentation.json_dict:
set_graph_defaults(source)
graph = networkx.readwrite.json_graph.node_link_graph(source)
elif representation == self.GraphRepresentation.json_file:
with open(source, mode="r") as f:
source = json.load(f)
set_graph_defaults(source)
graph = networkx.readwrite.json_graph.node_link_graph(source)
elif representation == self.GraphRepresentation.json_string:
source = json.loads(source)
set_graph_defaults(source)
graph = networkx.readwrite.json_graph.node_link_graph(source)
elif representation == self.GraphRepresentation.yaml:
graph = networkx.readwrite.read_yaml(source)
......
Markdown is supported
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