diff --git a/src/caosdb/utils/plantuml.py b/src/caosdb/utils/plantuml.py index ea4d193b5e75d3d5aeeddc994c39904a09cfeb8f..92629784a2fa0da01563052d3063b35dc02382d0 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?")