Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 7ee3c437 authored by Bruno Guillaume's avatar Bruno Guillaume
Browse files

add a function "save" for graphs

parent 01dc1834
No related branches found
No related tags found
No related merge requests found
LOCAL/
build/ build/
dist/ dist/
_build _build
...@@ -6,3 +7,4 @@ grewpy.native ...@@ -6,3 +7,4 @@ grewpy.native
bin bin
MANIFEST MANIFEST
*.pyc *.pyc
UD_French-GSD
...@@ -64,6 +64,10 @@ def graph(data=None): ...@@ -64,6 +64,10 @@ def graph(data=None):
raise GrewError('Library call error') 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): def add_node(g, s, a):
""" """
......
...@@ -11,7 +11,7 @@ setuptools.setup( ...@@ -11,7 +11,7 @@ setuptools.setup(
description="A binding to the Grew software", description="A binding to the Grew software",
long_description=long_description, long_description=long_description,
long_description_content_type="text/markdown", long_description_content_type="text/markdown",
url="http://grew.fr", url="https://grew.fr",
author="bguil", author="bguil",
author_email="Bruno.Guillaume@loria.fr" author_email="Bruno.Guillaume@loria.fr"
) )
...@@ -43,6 +43,20 @@ let run_command request = ...@@ -43,6 +43,20 @@ let run_command request =
| None -> json_error "no 'filename' in 'load_grs' command" | None -> json_error "no 'filename' in 'load_grs' command"
end 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 ======================= *) (* ======================= load_grs ======================= *)
| Some "load_grs" -> | Some "load_grs" ->
begin begin
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment