createerm.py
changeset 313 a88add2b3eea
parent 294 0e75bd39767d
equal deleted inserted replaced
312:42fd5075a5d1 313:a88add2b3eea
    34         pass
    34         pass
    35 
    35 
    36 
    36 
    37 #schema plot
    37 #schema plot
    38 def createSchemaPlot(fname):
    38 def createSchemaPlot(fname):
    39     from sqlalchemy_schemadisplay3 import create_schema_graph
    39     from sqlalchemy_schemadisplay import create_schema_graph
    40     graph = create_schema_graph(metadata=schema.Base.metadata,
    40     graph = create_schema_graph(engine=None,
       
    41         metadata=schema.Base.metadata,
       
    42         tables=tables,
    41         show_datatypes=True, # The image too large if datatypes shown
    43         show_datatypes=True, # The image too large if datatypes shown
    42         show_indexes=True, # ditto for indexes
    44         show_indexes=True, # ditto for indexes
    43         rankdir='LR', # From left to right (instead of top to bottom)
    45         rankdir='LR', # From left to right (instead of top to bottom)
    44         concentrate=True, # Don't try to join the relation lines together
    46         concentrate=True, # Don't try to join the relation lines together
    45     )
    47     )
    46 
    48 
    47     graph.set_size('6.5,10')
    49     graph.set_size('6.5,10')
    48     #graph.set_ratio("fill")
    50     #graph.set_ratio("fill")
    49     graph.write_svg(fname)
    51     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')