Code

issue2550678: Allow pagesize=-1 which returns all results.
[roundup.git] / scripts / schema_diagram.py
1 #! /usr/bin/python
2 #
3 # Schema diagram generator contributed by Stefan Seefeld of the fresco
4 # project http://www.fresco.org/.
5 #
6 # It generates a 'dot file' that is then fed into the 'dot'
7 # tool (http://www.graphviz.org) to generate a graph:
8 #
9 # %> ./schema.py
10 # %> dot -Tps schema.dot -o schema.ps
11 # %> gv schema.ps
12 #
13 import sys
14 import roundup.instance
16 # open the instance
17 instance = roundup.instance.open(sys.argv[1])
18 db = instance.open()
20 # diagram preamble
21 print 'digraph schema {'
22 print 'size="8,6"'
23 print 'node [shape="record" bgcolor="#ffe4c4" style=filled]'
24 print 'edge [taillabel="1" headlabel="1" dir=back arrowtail=ediamond]'
26 # get all the classes
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),
42                                                  a)
43         elif isinstance(attribute, roundup.hyperdb.Multilink):
44             print 'node%d -> node%d [taillabel="*" label=%s]'%(types.index(name),
45                                                  types.index(attribute.classname),
46                                                  a)
47 # all done
48 print '}'