forked from galaxyproject/galaxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgalaxy_schemadisp.py
56 lines (48 loc) · 1.67 KB
/
galaxy_schemadisp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import os
import sys
from db_shell import * # noqa
from sqlalchemy import MetaData
from sqlalchemy.orm import class_mapper
try:
from sqlalchemy_schemadisplay import (
create_schema_graph,
create_uml_graph,
)
except ImportError:
print("please install sqlalchemy_schemadisplay to use this script (pip install sqlalchemy_schemadisplay)")
raise
gxy_root = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
sys.path.insert(1, os.path.abspath(os.path.join(gxy_root, "lib")))
from galaxy import model
if __name__ == "__main__":
gxy_root = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
sqlitedb = os.path.join(gxy_root, "database/universe.sqlite")
# Try to build a representation of what's in the sqlite database
if os.path.exists(sqlitedb):
graph = create_schema_graph(
metadata=MetaData("sqlite:///" + sqlitedb),
show_datatypes=False,
show_indexes=False,
rankdir="LR",
concentrate=False,
)
print(f"Writing galaxy_universe.png, built from {sqlitedb}")
graph.write_png("galaxy_universe.png")
else:
print(f"No sqlitedb available at {sqlitedb}, skipping rendering")
# Build UML graph from loaded mapper
mappers = []
for attr in dir(model):
if attr[0] == "_":
continue
try:
cls = getattr(model, attr)
mappers.append(class_mapper(cls))
except Exception:
pass
graph = create_uml_graph(
mappers,
show_operations=False,
)
print("Writing galaxy_uml.png")
graph.write_png("galaxy_uml.png") # write out the file