-
Notifications
You must be signed in to change notification settings - Fork 0
/
rock2dot.py
executable file
·30 lines (25 loc) · 1.25 KB
/
rock2dot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#! /usr/bin/env python
import sys
infile, outfile = sys.argv[1], sys.argv[2]
inf,outf = open(infile), open(outfile,"w")
outf.write("graph \"" + infile + "\" {\n")
outf.write("graph [nodesep=1.5 ranksep=1.0];\n")
outf.write("node [margin=0.2 shape=box];\n")
for line in inf.readlines():
if "#" not in line:
if ".connect_to" in line:
splitted = line.lstrip().replace("\n","").split(".connect_to ")
sourceSplit = splitted[0].lstrip().split(".")
targetSplit = splitted[1].lstrip().split(".")
sourceNode,sourcePort = "\""+sourceSplit[0]+"\"","\""+sourceSplit[1]+"\""
targetNode,targetPort = "\""+targetSplit[0]+"\"","\""+targetSplit[1]+"\""
outf.write(sourceNode + " -- " + targetNode + "[ taillabel=" + sourcePort + " headlabel=" + targetPort + " ];\n")
if ".log(" in line:
splitted = line.lstrip().replace("\n","").split(".log(")
targetNode = splitted[0].lstrip()
sourceSplit = splitted[1].lstrip().replace(")","").split(".")
sourceNode,sourcePort = "\""+sourceSplit[0]+"\"","\""+sourceSplit[1]+"\""
outf.write(sourceNode + " -- " + targetNode + "[ taillabel=" + sourcePort + " ];\n")
outf.write("}\n")
inf.close()
outf.close()