Introduce verbose mode and generalize output formats
Added program specific configurations in config.yaml under puudot and added key for verbose mode. Currently verbose mode prints 'dot' information when running the program. Refactored puudot.py and graph.py in order to allow easier addition of output formats.
This commit is contained in:
parent
e5d146cbe1
commit
0e5a2868b0
@ -1,5 +1,6 @@
|
||||
FROM alpine
|
||||
RUN apk add --no-cache \
|
||||
yq \
|
||||
python3 \
|
||||
py3-yaml \
|
||||
graphviz
|
||||
|
||||
@ -11,6 +11,8 @@ import uuid
|
||||
|
||||
|
||||
|
||||
support_formats = ["svg", "pdf"]
|
||||
|
||||
def make_header(config):
|
||||
return "graph {\n" + config["graph"] + "\n"
|
||||
|
||||
@ -145,12 +147,12 @@ 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", svg_file="graph.svg"):
|
||||
def make_dot(self, format="svg", dot_file="dot.gv", out_file="graph.svg"):
|
||||
if self.dot_file != "":
|
||||
with open(dot_file, "w") as f:
|
||||
f.write(self.dot_file)
|
||||
if format == "svg":
|
||||
os.system(f"dot -T{format} {dot_file} -o {svg_file}")
|
||||
if format in support_formats:
|
||||
os.system(f"dot -T{format} {dot_file} -o {out_file}")
|
||||
|
||||
|
||||
|
||||
@ -5,6 +5,7 @@ import os
|
||||
|
||||
DATA_DIR="/data"
|
||||
CONFIG_FILE="/config.yaml"
|
||||
FORMAT="pdf"
|
||||
|
||||
def main():
|
||||
# Get all YAML files in the data directory
|
||||
@ -22,8 +23,8 @@ 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")
|
||||
svg_file = os.path.join(DATA_DIR, f"{base_name}.svg")
|
||||
graph.make_dot("svg", dot_file, svg_file)
|
||||
out_file = os.path.join(DATA_DIR, f"{base_name}.{FORMAT}")
|
||||
graph.make_dot(FORMAT, dot_file, out_file)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
@ -1,14 +1,19 @@
|
||||
puudot:
|
||||
verbose: false
|
||||
dot:
|
||||
graph: |
|
||||
//graph [splines=ortho, nodesep=0.2, ranksep="0.5 equally"]
|
||||
//graph [splines=polyline, nodesep=0.2, ranksep="0.5 equally"]
|
||||
graph [splines=polyline, nodesep=0.2, ranksep="0.5 equally"]
|
||||
//graph [splines=curved, nodesep=0.2, ranksep="0.5 equally"]
|
||||
//graph [splines=true, nodesep=0.2, ranksep="0.5 equally"]
|
||||
graph [splines=line, nodesep=0.2, ranksep="0.5 equally"]
|
||||
//graph [splines=line, nodesep=0.2, ranksep="0.5 equally"]
|
||||
//node [color=white]
|
||||
//edge [headport=n, tailport=s]
|
||||
compound=true
|
||||
center=true
|
||||
fontname="Helvetica"
|
||||
charset="UTF-8"
|
||||
bgcolor="white"
|
||||
subgraph: |
|
||||
labeljust=l
|
||||
node:
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
BIN
data/styrman-blocks.pdf
Normal file
BIN
data/styrman-blocks.pdf
Normal file
Binary file not shown.
12
run.sh
12
run.sh
@ -6,5 +6,17 @@ if [ ! -f "/code/puudot.py" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if config.yaml exists
|
||||
if [ ! -f "/config.yaml" ]; then
|
||||
echo "Error: config.yaml not found in /config directory!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
verbose=$(yq eval '.puudot.verbose' /config.yaml)
|
||||
|
||||
if [ "$verbose" = true ]; then
|
||||
echo $(dot -v)
|
||||
fi
|
||||
|
||||
# Run the script
|
||||
python3 /code/puudot.py
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user