|
1 from iro import schema |
|
2 |
|
3 from sqlalchemy.orm import class_mapper |
|
4 tables = [] |
|
5 for attr in schema.__tables__: |
|
6 if attr[0] == '_': continue |
|
7 try: |
|
8 cls = getattr(schema, attr) |
|
9 tables.append(class_mapper(cls)) |
|
10 except: |
|
11 pass |
|
12 |
|
13 |
|
14 #schema plot |
|
15 def createSchemaPlot(fname): |
|
16 from sqlalchemy_schemadisplay3 import create_schema_graph |
|
17 graph = create_schema_graph(metadata=schema.Base.metadata, |
|
18 show_datatypes=True, # The image too large if datatypes shown |
|
19 show_indexes=True, # ditto for indexes |
|
20 rankdir='LR', # From left to right (instead of top to bottom) |
|
21 concentrate=True, # Don't try to join the relation lines together |
|
22 ) |
|
23 |
|
24 graph.set_size('6.5,10') |
|
25 #graph.set_ratio("fill") |
|
26 graph.write_svg(fname) |
|
27 |
|
28 #umlplot |
|
29 def createUMLPlot(fname): |
|
30 from sqlalchemy_schemadisplay3 import create_uml_graph |
|
31 from sqlalchemy.orm import class_mapper |
|
32 mappers = [] |
|
33 for attr in dir(schema.model): |
|
34 if attr[0] == '_': continue |
|
35 try: |
|
36 cls = getattr(schema.model, attr) |
|
37 mappers.append(class_mapper(cls)) |
|
38 except: |
|
39 pass |
|
40 #pass them to the function and set some formatting options |
|
41 graph = create_uml_graph(mappers, |
|
42 show_operations=False, # not necessary in this case |
|
43 show_multiplicity_one=True, # some people like to see the ones |
|
44 show_attributes=True, |
|
45 ) |
|
46 graph.set_size('6,5') |
|
47 graph.set_ratio("fill") |
|
48 graph.write_png('test.png') |