def __init__(self):
     import sys
     sys.setrecursionlimit(10000)
     self.output_img = 'dep_tree'
     self.graph = gv.Digraph(format='jpg')
     self.db_manager = DatabaseManager()
     self.db_manager.open('/home/buharin/Programming/PythonProjects/fastbuild/spike/dummy_project')
     self.__initialize_graph()
     self.__apply_styles(styles=DependencyGraphGenerator.styles)
class DependencyGraphGenerator:
    """
    http://matthiaseisen.com/articles/graphviz/
    """
    styles = {
        'graph': {
            'label': 'dummy project dependecy tree',
            'fontsize': '16',
            'fontcolor': 'white',
            'bgcolor': '#333333',
            'rankdir': 'BT',
        },
        'nodes': {
            'fontname': 'Helvetica',
            'shape': 'hexagon',
            'fontcolor': 'white',
            'color': 'white',
            'style': 'filled',
            'fillcolor': '#006699',
        },
        'edges': {
            'style': 'dashed',
            'color': 'white',
            'arrowhead': 'open',
            'fontname': 'Courier',
            'fontsize': '12',
            'fontcolor': 'white',
        }
    }

    def __init__(self):
        import sys
        sys.setrecursionlimit(10000)
        self.output_img = 'dep_tree'
        self.graph = gv.Digraph(format='jpg')
        self.db_manager = DatabaseManager()
        self.db_manager.open('/home/buharin/Programming/PythonProjects/fastbuild/spike/dummy_project')
        self.__initialize_graph()
        self.__apply_styles(styles=DependencyGraphGenerator.styles)

    def __initialize_graph(self):
        for key in self.db_manager:
            self.graph.node(key)
            for dep in self.db_manager.get_dependency(key):
                self.graph.edge(key, dep)

    def __apply_styles(self, styles):
        self.graph.graph_attr.update(
            ('graph' in styles and styles['graph']) or {}
        )
        self.graph.node_attr.update(
            ('nodes' in styles and styles['nodes']) or {}
        )
        self.graph.edge_attr.update(
            ('edges' in styles and styles['edges']) or {}
        )

    def save(self):
        self.graph.render(filename=self.output_img, directory='/home/buharin/Programming/PythonProjects/fastbuild/spike/dummy_project')

    def __str__(self):
        return self.graph.source