-
Notifications
You must be signed in to change notification settings - Fork 332
/
gen-dot.py
executable file
·47 lines (40 loc) · 1.09 KB
/
gen-dot.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python3
# generate dot diagram of top down tree from module
from __future__ import print_function
import sys
max_level = 5
first = 1
if sys.argv[1:] and sys.argv[1][:2] == "-l":
max_level = int(sys.argv[1][2:])
first += 1
if len(sys.argv) > first and sys.argv[first] == "simple":
import simple_ratios
m = simple_ratios
else:
import adl_glc_ratios
m = adl_glc_ratios
def has(obj, name):
return name in obj.__class__.__dict__
class Runner:
def __init__(self):
self.olist = []
def run(self, n):
if n.level <= max_level:
self.olist.append(n)
def metric(self, n):
pass
def finish(self):
for n in self.olist:
if n.level == 1:
print('"%s";' % (n.name))
elif n.parent:
print('"%s" -> "%s";' % (n.parent.name, n.name))
#if n.sibling:
# print('"%s" -> "%s";' % (n.name, n.sibling.name))
runner = Runner()
m.Setup(runner)
print(runner.olist, file=sys.stderr)
print("digraph {")
print("fontname=\"Courier\";")
runner.finish()
print("}")