createerm.py
author Sandro Knauß <knauss@netzguerilla.net>
Tue, 28 Feb 2012 01:18:11 +0100
branchdevel
changeset 195 74d12f301a5d
parent 92 f479738b4879
child 251 3caa803a2dec
permissions -rw-r--r--
test default provider added as todo

from iro.model import schema

from sqlalchemy.orm import class_mapper
tables = []
for attr in schema.__tables__:
    if attr[0] == '_': continue
    try:
        cls = getattr(schema, attr)
        tables.append(class_mapper(cls))
    except:
        pass


#schema plot
def createSchemaPlot(fname):
    from sqlalchemy_schemadisplay3 import create_schema_graph
    graph = create_schema_graph(metadata=schema.Base.metadata,
        show_datatypes=True, # The image too large if datatypes shown
        show_indexes=True, # ditto for indexes
        rankdir='LR', # From left to right (instead of top to bottom)
        concentrate=True, # Don't try to join the relation lines together
    )

    graph.set_size('6.5,10')
    #graph.set_ratio("fill")
    graph.write_svg(fname)

#umlplot
def createUMLPlot(fname):
    from sqlalchemy_schemadisplay3 import create_uml_graph
    from sqlalchemy.orm import class_mapper
    mappers = []
    for attr in dir(schema.model):
        if attr[0] == '_': continue
        try:
            cls = getattr(schema.model, attr)
            mappers.append(class_mapper(cls))
        except:
            pass
    #pass them to the function and set some formatting options
    graph = create_uml_graph(mappers,
        show_operations=False, # not necessary in this case
        show_multiplicity_one=True, # some people like to see the ones
        show_attributes=True,
    )
    graph.set_size('6,5')
    graph.set_ratio("fill")
    graph.write_png('test.png')