From 92a8675c41511c1958121192585c266325986159 Mon Sep 17 00:00:00 2001 From: Lauri Koskenniemi Date: Thu, 4 Dec 2025 21:12:34 +0200 Subject: [PATCH] Add output formats to puudot config The output format(s) are now defined in the puudot config under output key as a list. --- code/graph.py | 6 ++---- code/puudot.py | 11 ++++++++--- config.yaml | 3 +++ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/code/graph.py b/code/graph.py index 33cd2ba..1897452 100644 --- a/code/graph.py +++ b/code/graph.py @@ -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}") diff --git a/code/puudot.py b/code/puudot.py index 64dd733..2080d7f 100644 --- a/code/puudot.py +++ b/code/puudot.py @@ -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() diff --git a/config.yaml b/config.yaml index 7093fc1..44e3a15 100644 --- a/config.yaml +++ b/config.yaml @@ -1,5 +1,8 @@ puudot: verbose: false + output: + - pdf + - svg dot: graph: | //graph [splines=ortho, nodesep=0.2, ranksep="0.5 equally"]