コード例 #1
0
ファイル: DBManager.py プロジェクト: vkuznet/PyQueryBuilder
 def write_graph(self, db_alias, format_l=None):
     """
     Write graph of DB schema to db_alias.dot file
     Using dot in shell to create result in given format
     """
     file_name = "%s.dot" % db_alias
     if  self.verbose:
         print "Writing graph of DB schema to", file_name
     dot = DotGraph(file(file_name, "w"))
     # load all tables before building a graph
     t_dict = self.load_tables(db_alias)
     if  self.verbose:
         print t_dict
     for key in t_dict.keys():
         table = t_dict[key]
         table_name = key
         f_keys = table.foreign_keys
         for f_key in f_keys:
             right = f_key.column.table.name
             if right != 'person': # exclude person table
                 dot.add_edge(table_name, right)
     dot.finish_output()
     if  format_l:
         if  format_l not in self.formats:
             msg = "Unsupported format '%s', please use %s" \
                    % (format_l, str(self.formats))
             raise Exception, msg
         cmd = "dot -v -T%s -O %s" % (format_l, file_name)
         try:
             status = os.system(cmd)
             print "Executing", cmd
         except Error:
             print "Fail to execute %s " % cmd , status
             print "Please verify that you have dot installed on your system"
             print traceback.print_exc()
コード例 #2
0
def write_core_graph(simschema, filename="coreschema"):
    """view core graph on simulate schema graph"""
    fns = filename + '.dot'
    fls = open(fns, 'w')
    dot = DotGraph(fls)
    relations = simschema.get_graph_from_schema()
    graph = Graph(relations)
    ugraph = graph.get_undirected()
    cycles = simschema.get_cycle_basis(ugraph._graph)
    nodes = set([])
    order = simschema.ordered
    for cycle in cycles:
        nodes = nodes.union(set(cycle))
    for node in nodes:
        start_node = relations[node]
        for end_node in start_node:
            if end_node in nodes:
                dot.add_edge(order[node], order[end_node[0]], end_node[1])
    dot.finish_output()
コード例 #3
0
def write_core_wgraph(simschema, filename="coreschema"):
    """view core graph on simulate schema graph"""
    fns = filename + '.dot'
    fls = open(fns, 'w')
    dot = DotGraph(fls)
    relations = simschema.get_wgraph_from_schema()
    wgraph = WGraph(relations)
    core = wgraph.get_core_graph()
    order = simschema.ordered
    nodes = set([])
    for node in range(len(core)):
        if core[node] != []:
            nodes.add(node)
#            for end_node in core[node]:
#                dot.add_edge(order[node], order[end_node[0]], end_node[1])
    for node in nodes:
        start_node = relations[node]
        for end_node in start_node:
            if end_node[0] in nodes:
                dot.add_edge(order[node], order[end_node[0]], end_node[1])
    dot.finish_output()
コード例 #4
0
ファイル: DBManager.py プロジェクト: liangd/PyQueryBuilder
 def write_graph(self, db_alias, f_mat=None):
     """
     Write graph of DB schema to db_alias.dot file
     Using dot in shell to create result in given format
     """
     file_name = "%s.dot" % db_alias
     if  self.verbose:
         print "Writing graph of DB schema to", file_name
     dot = DotGraph(file(file_name, "w"))
     # load all tables before building a graph
     t_dict = self.load_tables(db_alias) 
     if  self.verbose:
         print t_dict
     for key in t_dict.keys():
         table = t_dict[key]
         table_name = key
         f_keys = table.foreign_keys
         for f_key in f_keys:
             right = f_key.column.table.name
             if right != 'person': # exclude person table
                 dot.add_edge(table_name, right)
     dot.finish_output()