From bb02e16d10a707da25af7d164eda610f6a69a641 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20tom=20W=C3=B6rden?= <henrik@trineo.org> Date: Thu, 13 Jun 2019 13:59:40 +0200 Subject: [PATCH] ENH: added util to create svg from structure --- src/caosdb/utils/plantuml.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/caosdb/utils/plantuml.py b/src/caosdb/utils/plantuml.py index ea4d193b..92629784 100644 --- a/src/caosdb/utils/plantuml.py +++ b/src/caosdb/utils/plantuml.py @@ -33,6 +33,8 @@ convert it with: plantuml FILENAME.pu -> FILENAME.png """ +import os + import caosdb as db REFERENCE = "REFERENCE" @@ -175,3 +177,27 @@ def recordtypes_to_plantuml_string(iterable): result += "\n@enduml\n" return result + + +def to_graphics(recordtypes, filename): + """ calls recordtypes_to_plantuml_string(), saves result to file and + creates an svg image + + plantuml needs to be installed + @params: + recordtypes: itrable with the record types to be displayed + filname: filename of the image (e.g. data_structure; data_structure.pu and + data_structure.svg will be created. + """ + pu = recordtypes_to_plantuml_string(recordtypes) + + pu_filename = filename+".pu" + with open(pu_filename, "w") as pu_file: + pu_file.write(pu) + + cmd = "plantuml -tsvg %s" % pu_filename + print("Executing:", cmd) + + if os.system(cmd) != 0: + raise Exception("An error occured during the execution of plantuml. " + "Is plantuml installed?") -- GitLab