Add output formats to puudot config
The output format(s) are now defined in the puudot config under output key as a list.
This commit is contained in:
parent
0e5a2868b0
commit
92a8675c41
@ -11,8 +11,6 @@ import uuid
|
||||
|
||||
|
||||
|
||||
support_formats = ["svg", "pdf"]
|
||||
|
||||
def make_header(config):
|
||||
return "graph {\n" + config["graph"] + "\n"
|
||||
|
||||
@ -147,11 +145,11 @@ class Graph:
|
||||
self.dot_file += add_links(self.links, self.config)
|
||||
self.dot_file += make_footer()
|
||||
|
||||
def make_dot(self, format="svg", dot_file="dot.gv", out_file="graph.svg"):
|
||||
def make_dot(self, dot_file, out_file, format):
|
||||
if self.dot_file != "":
|
||||
with open(dot_file, "w") as f:
|
||||
f.write(self.dot_file)
|
||||
if format in support_formats:
|
||||
if format:
|
||||
os.system(f"dot -T{format} {dot_file} -o {out_file}")
|
||||
|
||||
|
||||
|
||||
@ -5,12 +5,12 @@ import os
|
||||
|
||||
DATA_DIR="/data"
|
||||
CONFIG_FILE="/config.yaml"
|
||||
FORMAT="pdf"
|
||||
|
||||
def main():
|
||||
# Get all YAML files in the data directory
|
||||
yaml_files = [f for f in os.listdir(DATA_DIR) if f.endswith(('.yaml', '.yml'))]
|
||||
config = load_config(CONFIG_FILE)
|
||||
puudot_config = config.get('puudot', {})
|
||||
|
||||
for yaml_file in yaml_files:
|
||||
print(f"Processing {yaml_file}...")
|
||||
@ -23,8 +23,13 @@ def main():
|
||||
# Use the base name of the YAML file (without extension) as the output name
|
||||
base_name = os.path.splitext(yaml_file)[0]
|
||||
dot_file = os.path.join(DATA_DIR, f"{base_name}.gv")
|
||||
out_file = os.path.join(DATA_DIR, f"{base_name}.{FORMAT}")
|
||||
graph.make_dot(FORMAT, dot_file, out_file)
|
||||
|
||||
if puudot_config.get('verbose') == True:
|
||||
print(f"Output formats: {puudot_config.get('output')}")
|
||||
|
||||
for format in puudot_config.get('output'):
|
||||
out_file = os.path.join(DATA_DIR, f"{base_name}.{format}")
|
||||
graph.make_dot(dot_file, out_file, format)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
puudot:
|
||||
verbose: false
|
||||
output:
|
||||
- pdf
|
||||
- svg
|
||||
dot:
|
||||
graph: |
|
||||
//graph [splines=ortho, nodesep=0.2, ranksep="0.5 equally"]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user