Mercurial > p > roundup > code
comparison scripts/schema_diagram.py @ 1166:d56b7fc64923
additions
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Wed, 18 Sep 2002 05:13:11 +0000 |
| parents | |
| children | 64b05e24dbd8 |
comparison
equal
deleted
inserted
replaced
| 1165:14467c765167 | 1166:d56b7fc64923 |
|---|---|
| 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 | |
| 15 | |
| 16 # open the instance | |
| 17 instance = roundup.instance.open(sys.argv[1]) | |
| 18 db = instance.open() | |
| 19 | |
| 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]' | |
| 25 | |
| 26 # get all the classes | |
| 27 types = db.classes.keys() | |
| 28 | |
| 29 # one record node per class | |
| 30 for i in range(len(types)): | |
| 31 print 'node%d [label=\"{%s|}"]'%(i, types[i]) | |
| 32 | |
| 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 '}' |
