You guys might want to put this on a new page in the Wiki and add a link to it on the Goodies page at: http://elixir.ematia.de/trac/wiki/Goodies
On Wed, Nov 18, 2009 at 22:44, Andrew Jones <[email protected]> wrote: > Modified to handle class inheritance. > > #!/usr/bin/env python > import elixir, model, inspect > from model import * > > classes = [m for m in model.__dict__.values() if inspect.isclass(m) > and issubclass(m, Entity) and m.__name__ != 'Entity' ] > > print('digraph G {') > print('node [shape=plaintext]') > #print('edge [arrowsize=0.5 fontsize=9]') > print('edge [arrowsize=0.25 fontsize=11 fontcolor=blue]') > > for c in classes: > > manytoones = [f for f in c.__dict__.values() if f.__class__ == > elixir.relationships.ManyToOne] > onetomanys = [f for f in c.__dict__.values() if f.__class__ == > elixir.relationships.OneToMany] > onetoones = [f for f in c.__dict__.values() if f.__class__ == > elixir.relationships.OneToOne] > manytomanys = [f for f in c.__dict__.values() if f.__class__ == > elixir.relationships.ManyToMany] > inheritsfrom = [bc for bc in c.__bases__ if bc != Entity] > > fields = [f for f in c.__dict__.values() if f.__class__ == > elixir.fields.Field] > > fieldstr = '<tr><td align="left">' + '</td></tr><tr><td > align="left">'.join(["+%s"%(f.name) for f in fields]) + "</td></tr>" > relstr = ''.join(['<tr><td align="left" port="%s">%s</td></tr>'% > (f.name, f.name) for f in manytoones + onetomanys + onetoones + > manytomanys]) > if relstr == '': > relstr = '<tr><td></td></tr>' > > print('%s [label=< \ > <TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" > CELLPADDING="0"> \ > <TR CELLBORDER="1" CELLSPACING="0" CELLPADDING="0" > border="1"><TD border="1" bgcolor="lightblue">%s</TD></TR> \ > <TR><TD> <table BORDER="0" CELLBORDER="0" >%s</table> </ > TD></TR> \ > <TR><TD> <table BORDER="0" CELLBORDER="0" >%s</table> </ > TD></TR> \ > </TABLE>>]; \ > '%(c.__name__, c.__name__, fieldstr, relstr)) > > for c2 in manytoones: > #print('%s -> %s [headlabel="%s" taillabel="%s" label="%s"]'% > (c.__name__, c2.of_kind, '1', '*', c2.name)) > print('%s : %s -> %s [headlabel="%s" taillabel="%s"]'% > (c.__name__, c2.name , c2.of_kind, '1', '*')) > > for c2 in onetomanys: > #print('%s -> %s [headlabel="%s" taillabel="%s" label="%s"]'% > (c.__name__, c2.of_kind, '*', '1', c2.name)) > print('%s : %s -> %s [headlabel="%s" taillabel="%s"]'% > (c.__name__, c2.name , c2.of_kind, '*', '1')) > for c2 in onetoones: > #print('%s -> %s [headlabel="%s" taillabel="%s" label="%s"]'% > (c.__name__, c2.of_kind, '1', '1', c2.name)) > print('%s : %s -> %s [headlabel="%s" taillabel="%s"]'% > (c.__name__, c2.name , c2.of_kind, '1', '1')) > for c2 in manytomanys: > #print('%s -> %s [headlabel="%s" taillabel="%s" label="%s"]'% > (c.__name__, c2.of_kind, '*', '*', c2.name)) > print('%s : %s -> %s [headlabel="%s" taillabel="%s"]'% > (c.__name__, c2.name , c2.of_kind, '*', '*')) > for c2 in inheritsfrom: > print('%s -> %s [headlabel="%s" taillabel="%s"]' % > (c.__name__, c2.__name__, '1', '1')) > print('}') > > -- > > You received this message because you are subscribed to the Google Groups > "SQLElixir" group. > To post to this group, send email to [email protected]. > For more options, visit this group at > http://groups.google.com/group/sqlelixir?hl=. > > > -- Gaëtan de Menten http://openhex.org -- You received this message because you are subscribed to the Google Groups "SQLElixir" group. To post to this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sqlelixir?hl=.
