3 # Schema diagram generator contributed by Stefan Seefeld of the fresco
4 # project http://www.fresco.org/.
6 # It generates a 'dot file' that is then fed into the 'dot'
7 # tool (http://www.graphviz.org) to generate a graph:
10 # %> dot -Tps schema.dot -o schema.ps
14 import roundup
.instance
17 instance
= roundup
.instance
.open(sys
.argv
[1])
21 print 'digraph schema {'
23 print 'node [shape="record" bgcolor="#ffe4c4" style=filled]'
24 print 'edge [taillabel="1" headlabel="1" dir=back arrowtail=ediamond]'
27 types
= db
.classes
.keys()
29 # one record node per class
30 for i
in range(len(types
)):
31 print 'node%d [label=\"{%s|}"]'%(i
, types
[i
])
33 # now draw in the relations
34 for name
in db
.classes
.keys():
35 type = db
.classes
[name
]
36 attributes
= type.getprops()
37 for a
in attributes
.keys():
38 attribute
= attributes
[a
]
39 if isinstance(attribute
, roundup
.hyperdb
.Link
):
40 print 'node%d -> node%d [label=%s]'%(types
.index(name
),
41 types
.index(attribute
.classname
),
43 elif isinstance(attribute
, roundup
.hyperdb
.Multilink
):
44 print 'node%d -> node%d [taillabel="*" label=%s]'%(types
.index(name
),
45 types
.index(attribute
.classname
),