File: config-graph-json-to-dot.py

package info (click to toggle)
syslog-ng 4.8.1-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 20,456 kB
  • sloc: ansic: 177,631; python: 13,035; cpp: 11,611; makefile: 7,012; sh: 5,147; java: 3,651; xml: 3,344; yacc: 1,377; lex: 599; perl: 193; awk: 190; objc: 162
file content (21 lines) | stat: -rwxr-xr-x 517 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/env python3
import json, sys

j = None

if len(sys.argv) == 1:
    j = json.loads(sys.stdin.read())
else:
    file_name = sys.argv[1]
    with open(file_name) as f:
        j = json.loads(f.read())

nodes = j["nodes"]
arcs = j["arcs"]

print("digraph D {")
for node in nodes:
    print("  Node{} [label=\"{} {}\", shape=box]".format(node["node"], node["node"], ", ".join(node["info"])))
for arc in arcs:
    print("  Node{} -> Node{} [label=\"{}\"]".format(arc["from"], arc["to"], arc["type"]))
print("}")