def write(cls, node, type_name, path, compress=True): """ """ graph_io = NodeGraphIOVersionRegistry.current_version()() export_data = graph_io.export_node_type(node, type_name) header = {"version":graph_io.VERSION} output = {"header":header, "data":export_data} if compress: f = gzip.open(path, "wb") else: f = open(path, "w") json.dump(output, f, indent=4) f.close()
def read(cls, path): """ """ if path.endswith(".gz"): f = gzip.open(path, "rb") else: f = open(path, "r") read_data = json.load(f) header = read_data["header"] version = header["version"] data = read_data["data"] graph_data = data["graph"] graph_io_class = NodeGraphIOVersionRegistry.get(version) graph_io = graph_io_class() graph = graph_io.import_graph(graph_data) return graph
def __init__(cls, name, bases, clsdict): """ """ super(_NodeGraphIOMeta, cls).__init__(name, bases, clsdict) NodeGraphIOVersionRegistry.register(cls.VERSION, cls)