puudot/code/puudot.py
Lauri Koskenniemi 92a8675c41 Add output formats to puudot config
The output format(s) are now defined in the puudot config under
output key as a list.
2025-12-04 21:12:34 +02:00

36 lines
1.1 KiB
Python

from db import load_data, load_config
from graph import Graph
import os
DATA_DIR="/data"
CONFIG_FILE="/config.yaml"
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}...")
data = load_data(os.path.join(DATA_DIR, yaml_file))
graph = Graph()
graph.set_config(config)
graph.process_blocks(data)
graph.build_dot()
# 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")
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()