def dot(desc, color, title="Trump's ORM"):
    """Generate dot file

    :param desc: result of sadisplay.describe function

    Return string
    """

    classes, relations, inherits = desc
	
    CLASS_TEMPLATE = """
        %(name)s [label=<
        <TABLE BGCOLOR="{ncolor}" BORDER="0"
            CELLBORDER="0" CELLSPACING="0">
                <TR><TD COLSPAN="2" CELLPADDING="4"
                        ALIGN="CENTER" BGCOLOR="{ncolor}"
                ><FONT FACE="Helvetica Bold" COLOR="black"
                >%(name)s</FONT></TD></TR>%(cols)s%(props)s%(methods)s
        </TABLE>
    >]
    """.format(**color)

    COLUMN_TEMPLATE = """<TR><TD ALIGN="LEFT" BORDER="0"
        BGCOLOR="{ccolor}"
        ><FONT FACE="Bitstream Vera Sans">%(name)s</FONT
        ></TD><TD BGCOLOR="{ccolor}" ALIGN="RIGHT"
        ><FONT FACE="Bitstream Vera Sans">%(type)s</FONT
        ></TD></TR>""".format(**color)

    PROPERTY_TEMPLATE = """<TR><TD ALIGN="LEFT" BORDER="0"
        BGCOLOR="{pcolor}"
        ><FONT FACE="Bitstream Vera Sans">%(name)s</FONT></TD
        ><TD BGCOLOR="{pcolor}" ALIGN="RIGHT"
        ><FONT FACE="Bitstream Vera Sans">PROP</FONT
        ></TD></TR>""".format(**color)

    METHOD_TEMPLATE = """<TR><TD ALIGN="LEFT" BORDER="0"
        BGCOLOR="{mcolor}"
        ><FONT FACE="Bitstream Vera Sans">%(name)s()</FONT></TD
        ><TD BGCOLOR="{mcolor}" ALIGN="RIGHT"
        ><FONT FACE="Bitstream Vera Sans">METH</FONT
        ></TD></TR>""".format(**color)

    EDGE_INHERIT = "\tedge [\n\t\tarrowhead = empty\n\t]"
    INHERIT_TEMPLATE = "\t%(child)s -> %(parent)s \n"

    EDGE_REL = "\tedge [\n\t\tarrowhead = ediamond\n\t\tarrowtail = open\n\t]"
    RELATION_TEMPLATE = "\t\"%(from)s\" -> \"%(to)s\" [label = \"%(by)s\"]"

    result = ["""
        digraph G {
            label = "%s";
            fontname = "Bitstream Vera Sans"
            fontsize = 12

            node [
                fontname = "Bitstream Vera Sans"
                fontsize = 8
                shape = "plaintext"
            ]

            edge [
                fontname = "Bitstream Vera Sans"
                fontsize = 8
            ]
    """ % title]

    for cls in classes:
        cols = ' '.join([
            COLUMN_TEMPLATE % {'type': c[0], 'name': c[1]} for c in cls['cols']
        ])
        props = ' '.join([
            PROPERTY_TEMPLATE % {'name': p} for p in cls['props']
        ])
        methods = ' '.join([
            METHOD_TEMPLATE % {'name': m} for m in cls['methods']
        ])
        renderd = CLASS_TEMPLATE % {
            'name': cls['name'],
            'cols': cols,
            'props': props,
            'methods': methods,
        }

        result.append(renderd)

    result += [EDGE_INHERIT]
    for item in inherits:
        result.append(INHERIT_TEMPLATE % item)

    result += [EDGE_REL]
    for item in relations:
        result.append(RELATION_TEMPLATE % item)

    result += [
        '}'
    ]

    return '\n'.join(result)
def dot ( desc , color , title = "Trump's ORM" ) : classes , relations , inherits = desc CLASS_TEMPLATE = """
        %(name)s [label=<
        <TABLE BGCOLOR="{ncolor}" BORDER="0"
            CELLBORDER="0" CELLSPACING="0">
                <TR><TD COLSPAN="2" CELLPADDING="4"
                        ALIGN="CENTER" BGCOLOR="{ncolor}"
                ><FONT FACE="Helvetica Bold" COLOR="black"
                >%(name)s</FONT></TD></TR>%(cols)s%(props)s%(methods)s
        </TABLE>
    >]
    """ . format ( ** color ) COLUMN_TEMPLATE = """<TR><TD ALIGN="LEFT" BORDER="0"
        BGCOLOR="{ccolor}"
        ><FONT FACE="Bitstream Vera Sans">%(name)s</FONT
        ></TD><TD BGCOLOR="{ccolor}" ALIGN="RIGHT"
        ><FONT FACE="Bitstream Vera Sans">%(type)s</FONT
        ></TD></TR>""" . format ( ** color ) PROPERTY_TEMPLATE = """<TR><TD ALIGN="LEFT" BORDER="0"
        BGCOLOR="{pcolor}"
        ><FONT FACE="Bitstream Vera Sans">%(name)s</FONT></TD
        ><TD BGCOLOR="{pcolor}" ALIGN="RIGHT"
        ><FONT FACE="Bitstream Vera Sans">PROP</FONT
        ></TD></TR>""" . format ( ** color ) METHOD_TEMPLATE = """<TR><TD ALIGN="LEFT" BORDER="0"
        BGCOLOR="{mcolor}"
        ><FONT FACE="Bitstream Vera Sans">%(name)s()</FONT></TD
        ><TD BGCOLOR="{mcolor}" ALIGN="RIGHT"
        ><FONT FACE="Bitstream Vera Sans">METH</FONT
        ></TD></TR>""" . format ( ** color ) EDGE_INHERIT = "\tedge [\n\t\tarrowhead = empty\n\t]" INHERIT_TEMPLATE = "\t%(child)s -> %(parent)s \n" EDGE_REL = "\tedge [\n\t\tarrowhead = ediamond\n\t\tarrowtail = open\n\t]" RELATION_TEMPLATE = "\t\"%(from)s\" -> \"%(to)s\" [label = \"%(by)s\"]" result = [ """
        digraph G {
            label = "%s";
            fontname = "Bitstream Vera Sans"
            fontsize = 12
            node [
                fontname = "Bitstream Vera Sans"
                fontsize = 8
                shape = "plaintext"
            ]
            edge [
                fontname = "Bitstream Vera Sans"
                fontsize = 8
            ]
    """ % title ] for cls in classes : cols = ' ' . join ( [ COLUMN_TEMPLATE % { 'type' : c [ 0 ] , 'name' : c [ 1 ] } for c in cls [ 'cols' ] ] ) props = ' ' . join ( [ PROPERTY_TEMPLATE % { 'name' : p } for p in cls [ 'props' ] ] ) methods = ' ' . join ( [ METHOD_TEMPLATE % { 'name' : m } for m in cls [ 'methods' ] ] ) renderd = CLASS_TEMPLATE % { 'name' : cls [ 'name' ] , 'cols' : cols , 'props' : props , 'methods' : methods , } result . append ( renderd ) result += [ EDGE_INHERIT ] for item in inherits : result . append ( INHERIT_TEMPLATE % item ) result += [ EDGE_REL ] for item in relations : result . append ( RELATION_TEMPLATE % item ) result += [ '}' ] return '\n' . join ( result )
Generate dot file

    :param desc: result of sadisplay.describe function

    Return string