From 7ee3c437a821ed040283ac9b9549fd18edfde43e Mon Sep 17 00:00:00 2001 From: Bruno Guillaume <Bruno.Guillaume@loria.fr> Date: Wed, 24 Feb 2021 17:34:39 +0100 Subject: [PATCH] add a function "save" for graphs --- .gitignore | 2 ++ grew/graph.py | 4 ++++ setup.py | 2 +- src_ocaml/grewpy.ml | 14 ++++++++++++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 2c31706..2172968 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +LOCAL/ build/ dist/ _build @@ -6,3 +7,4 @@ grewpy.native bin MANIFEST *.pyc +UD_French-GSD diff --git a/grew/graph.py b/grew/graph.py index 54d9d5b..a10edb6 100644 --- a/grew/graph.py +++ b/grew/graph.py @@ -64,6 +64,10 @@ def graph(data=None): raise GrewError('Library call error') +def save(gr, filename): + req = { "command": "save_graph", "graph": json.dumps(gr), "filename": filename } + reply = network.send_and_receive(req) + return def add_node(g, s, a): """ diff --git a/setup.py b/setup.py index 6deb4fe..4cabc9b 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ setuptools.setup( description="A binding to the Grew software", long_description=long_description, long_description_content_type="text/markdown", - url="http://grew.fr", + url="https://grew.fr", author="bguil", author_email="Bruno.Guillaume@loria.fr" ) diff --git a/src_ocaml/grewpy.ml b/src_ocaml/grewpy.ml index 0e9e970..f837387 100644 --- a/src_ocaml/grewpy.ml +++ b/src_ocaml/grewpy.ml @@ -43,6 +43,20 @@ let run_command request = | None -> json_error "no 'filename' in 'load_grs' command" end + (* ======================= save_graph ======================= *) + | Some "save_graph" -> + begin + match ( + json |> member "graph" |> to_string_option, + json |> member "filename" |> to_string_option + ) with + | Some graph, Some filename -> + let gr = Graph.of_json_python ~config (Yojson.Basic.from_string graph) in + Yojson.Basic.to_file filename (Graph.to_json gr); + Yojson.Basic.to_string (`Assoc [("status", `String "OK"); ("data", `Null)]) + | _ -> json_error "incomplete 'save_graph' command" + end + (* ======================= load_grs ======================= *) | Some "load_grs" -> begin -- GitLab