|
1 # Copyright (c) 2012 netzguerilla.net <iro@netzguerilla.net> |
|
2 # |
|
3 # This file is part of Iro. |
|
4 # |
|
5 # Permission is hereby granted, free of charge, to any person obtaining a copy of |
|
6 # this software and associated documentation files (the "Software"), to deal in |
|
7 # the Software without restriction, including without limitation the rights to use, |
|
8 # copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the |
|
9 # #Software, and to permit persons to whom the Software is furnished to do so, |
|
10 # subject to the following conditions: |
|
11 # |
|
12 # The above copyright notice and this permission notice shall be included in |
|
13 # all copies or substantial portions of the Software. |
|
14 # |
|
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, |
|
16 # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A |
|
17 # PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
18 # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
|
19 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
|
20 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|
21 |
|
22 from iro.model import schema |
|
23 |
|
24 tables = schema.Base.metadata.sorted_tables |
|
25 |
|
26 tables_cls={} |
|
27 for i in dir(schema): |
|
28 if i.startswith("__") or i == "Base": |
|
29 continue |
|
30 try: |
|
31 a = getattr(schema,i) |
|
32 tables_cls[a.__tablename__] = a |
|
33 except AttributeError: |
|
34 pass |
|
35 |
|
36 |
|
37 #schema plot |
|
38 def createSchemaPlot(fname): |
|
39 from sqlalchemy_schemadisplay3 import create_schema_graph |
|
40 graph = create_schema_graph(metadata=schema.Base.metadata, |
|
41 show_datatypes=True, # The image too large if datatypes shown |
|
42 show_indexes=True, # ditto for indexes |
|
43 rankdir='LR', # From left to right (instead of top to bottom) |
|
44 concentrate=True, # Don't try to join the relation lines together |
|
45 ) |
|
46 |
|
47 graph.set_size('6.5,10') |
|
48 #graph.set_ratio("fill") |
|
49 graph.write_svg(fname) |
|
50 |
|
51 #umlplot |
|
52 def createUMLPlot(fname): |
|
53 from sqlalchemy_schemadisplay3 import create_uml_graph |
|
54 from sqlalchemy.orm import class_mapper |
|
55 mappers = [] |
|
56 for attr in dir(schema.model): |
|
57 if attr[0] == '_': continue |
|
58 try: |
|
59 cls = getattr(schema.model, attr) |
|
60 mappers.append(class_mapper(cls)) |
|
61 except: |
|
62 pass |
|
63 #pass them to the function and set some formatting options |
|
64 graph = create_uml_graph(mappers, |
|
65 show_operations=False, # not necessary in this case |
|
66 show_multiplicity_one=True, # some people like to see the ones |
|
67 show_attributes=True, |
|
68 ) |
|
69 graph.set_size('6,5') |
|
70 graph.set_ratio("fill") |
|
71 graph.write_png('test.png') |