def graph_from_json_list (self, ilist): # Give each item a unique identifier registry = Registry() found = {} first_guid = None counter = 0 for i in ilist: i["guid"] = registry.get_guid() found[counter] = i counter+=1 # load all the json into a dict with {"guid" : Graph} loaded = {} counter = 0 for i in ilist: g = self.graph_from_json(found[counter]) g.guid = i["guid"] loaded[found[counter]["guid"]] = copy.deepcopy(g) counter += 1 # Convert loaded to an array loaded_array = [] for i in found: loaded_array.append(loaded[found[i]["guid"]]) # Go through all of the nexts and make sure they're set to the right value for i in found: nexts = found[i]["nexts"] new_nexts = [] for n in nexts: if (n < 0): new_nexts.append(None) else: new_nexts.append(loaded_array[n]) loaded[found[i]["guid"]].nexts = new_nexts # Find the first node, the one to return anchor = copy.deepcopy(loaded[found[0]["guid"]]) # Update the start nodes to the loaded values start = anchor.startNode new_nexts = [] for n in start.nexts: if type(n) is int: new_nexts.append(loaded_array[n]) else: new_nexts.append(n) start.nexts = new_nexts return anchor
def set_guids (self, node, registry=None): if (registry == None): registry = Registry() node.clear_guids(node) if not node: return if not node.guid == "": return else: node.guid = registry.get_guid() for n in node.nexts: if n: n.set_guids(n, registry=registry) node.set_guids(node.startNode,registry=registry) return