Mercurial > p > roundup > code
comparison scripts/schema_diagram.py @ 5376:64b05e24dbd8
Python 3 preparation: convert print to a function.
Tool-assisted patch. It is possible that some "from __future__ import
print_function" are not in fact needed, if a file only uses print()
with a single string as an argument and so would work fine in Python 2
without that import.
| author | Joseph Myers <jsm@polyomino.org.uk> |
|---|---|
| date | Tue, 24 Jul 2018 09:54:52 +0000 |
| parents | d56b7fc64923 |
| children | 23b8e6067f7c |
comparison
equal
deleted
inserted
replaced
| 5375:1ad46057ae4a | 5376:64b05e24dbd8 |
|---|---|
| 8 # | 8 # |
| 9 # %> ./schema.py | 9 # %> ./schema.py |
| 10 # %> dot -Tps schema.dot -o schema.ps | 10 # %> dot -Tps schema.dot -o schema.ps |
| 11 # %> gv schema.ps | 11 # %> gv schema.ps |
| 12 # | 12 # |
| 13 from __future__ import print_function | |
| 13 import sys | 14 import sys |
| 14 import roundup.instance | 15 import roundup.instance |
| 15 | 16 |
| 16 # open the instance | 17 # open the instance |
| 17 instance = roundup.instance.open(sys.argv[1]) | 18 instance = roundup.instance.open(sys.argv[1]) |
| 18 db = instance.open() | 19 db = instance.open() |
| 19 | 20 |
| 20 # diagram preamble | 21 # diagram preamble |
| 21 print 'digraph schema {' | 22 print('digraph schema {') |
| 22 print 'size="8,6"' | 23 print('size="8,6"') |
| 23 print 'node [shape="record" bgcolor="#ffe4c4" style=filled]' | 24 print('node [shape="record" bgcolor="#ffe4c4" style=filled]') |
| 24 print 'edge [taillabel="1" headlabel="1" dir=back arrowtail=ediamond]' | 25 print('edge [taillabel="1" headlabel="1" dir=back arrowtail=ediamond]') |
| 25 | 26 |
| 26 # get all the classes | 27 # get all the classes |
| 27 types = db.classes.keys() | 28 types = db.classes.keys() |
| 28 | 29 |
| 29 # one record node per class | 30 # one record node per class |
| 30 for i in range(len(types)): | 31 for i in range(len(types)): |
| 31 print 'node%d [label=\"{%s|}"]'%(i, types[i]) | 32 print('node%d [label=\"{%s|}"]'%(i, types[i])) |
| 32 | 33 |
| 33 # now draw in the relations | 34 # now draw in the relations |
| 34 for name in db.classes.keys(): | 35 for name in db.classes.keys(): |
| 35 type = db.classes[name] | 36 type = db.classes[name] |
| 36 attributes = type.getprops() | 37 attributes = type.getprops() |
| 37 for a in attributes.keys(): | 38 for a in attributes.keys(): |
| 38 attribute = attributes[a] | 39 attribute = attributes[a] |
| 39 if isinstance(attribute, roundup.hyperdb.Link): | 40 if isinstance(attribute, roundup.hyperdb.Link): |
| 40 print 'node%d -> node%d [label=%s]'%(types.index(name), | 41 print('node%d -> node%d [label=%s]'%(types.index(name), |
| 41 types.index(attribute.classname), | 42 types.index(attribute.classname), |
| 42 a) | 43 a)) |
| 43 elif isinstance(attribute, roundup.hyperdb.Multilink): | 44 elif isinstance(attribute, roundup.hyperdb.Multilink): |
| 44 print 'node%d -> node%d [taillabel="*" label=%s]'%(types.index(name), | 45 print('node%d -> node%d [taillabel="*" label=%s]'%(types.index(name), |
| 45 types.index(attribute.classname), | 46 types.index(attribute.classname), |
| 46 a) | 47 a)) |
| 47 # all done | 48 # all done |
| 48 print '}' | 49 print('}') |
