Ajout script mise a jour de tracker
[auf_roundup.git] / scripts / schema_diagram.py
CommitLineData
c638d827
CR
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#
13import sys
14import roundup.instance
15
16# open the instance
17instance = roundup.instance.open(sys.argv[1])
18db = instance.open()
19
20# diagram preamble
21print 'digraph schema {'
22print 'size="8,6"'
23print 'node [shape="record" bgcolor="#ffe4c4" style=filled]'
24print 'edge [taillabel="1" headlabel="1" dir=back arrowtail=ediamond]'
25
26# get all the classes
27types = db.classes.keys()
28
29# one record node per class
30for i in range(len(types)):
31 print 'node%d [label=\"{%s|}"]'%(i, types[i])
32
33# now draw in the relations
34for 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
48print '}'