#NEWLINE# def visualize( self , filename = None , tables_to_show = None ) : #NEWLINE# #INDENT# 'Visualize databases and create an er-diagram\n\n        Args:\n            filename(str): filepath for saving the er-diagram\n            tables_to_show(list): A list of tables to actually visualize.\n                Tables not included in this list will not be visualized,\n                but their foreign keys will be visualize if it refers to a\n                table in this list\n        ' #NEWLINE# try : #NEWLINE# #INDENT# import pygraphviz #NEWLINE# #UNINDENT# except ImportError : #NEWLINE# #INDENT# logger . error ( 'Install pygraphviz for visualizing databases' ) #NEWLINE# raise #NEWLINE# #UNINDENT# if ( filename is None ) : #NEWLINE# #INDENT# raise DatabaseInputError ( 'Filename must be provided for visualization' ) #NEWLINE# #UNINDENT# logger . info ( 'Creating a visualization of the database' ) #NEWLINE# graph = pygraphviz . AGraph ( name = 'Database' , label = 'Database' ) #NEWLINE# tables = [ r for r in self . relations ( ) if isinstance ( r , Table ) ] #NEWLINE# if ( tables_to_show is None ) : #NEWLINE# #INDENT# tables_to_show = [ table . full_name for table in tables ] #NEWLINE# #UNINDENT# for table in tables : #NEWLINE# #INDENT# if ( table . full_name in tables_to_show ) : #NEWLINE# #INDENT# graph . add_node ( table . full_name , shape = 'none' , label = self . _make_node_label ( table ) ) #NEWLINE# #UNINDENT# #UNINDENT# for table in tables : #NEWLINE# #INDENT# for ( cols , ref_table , ref_cols ) in table . foreign_key_references ( ) : #NEWLINE# #INDENT# if ( ( table . full_name in tables_to_show ) or ( ref_table in tables_to_show ) ) : #NEWLINE# #INDENT# graph . add_edge ( ref_table , table . full_name , tailport = ref_cols [ 0 ] , headport = cols [ 0 ] , dir = 'both' , arrowhead = 'crow' , arrowtail = 'dot' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# graph . layout ( prog = 'dot' ) #NEWLINE# graph . draw ( filename )