# Path: py-hwaftools/orch/graph.py
# class Graph(object):
#     def __init__(self, name, **options):
#         self.name = name
#         self.options = options
#         self._subgraphs = list()
#         self.nodes = set()
#         self.edges = set()
# 
#     def get_subgraph(self, name):
#         for sg in self._subgraphs:
#             if sg.name == name:
#                 return sg
#         return
# 
#     def set_subgraph(self, sg):
#         for ind, oldsg in enumerate(self._subgraphs):
#             if oldsg.name == name:
#                 self._subgraphs[ind] = sg
#                 return oldsg
#         self._subgraphs.append(sg)
#         return
# 
#     def graph(self, name = None):
#         if name is None or name == self.name:
#             return self
#         g = self.get_subgraph(name)
#         if not g: 
#             g = Graph(name)
#             self.set_subgraph(g)
#         return g
# 
#     def add_subgraph(self, name, **options):
#         already = self.get_subgraph(name)
#         if already:
#             already.options = options
#             return already
#         g = Graph(name, **options)
#         self._subgraphs.append(g)
#         return g
# 
#     def add_node(self, name, graph_name = None, **options):
#         self.graph(graph_name).nodes.add(Node(name,**options))
# 
#     def add_edge(self, tail, head, graph_name = None, **options):
#         self.graph(graph_name).edges.add(Edge(tail,head,**options))
# 
#     def todot(self, depth = 0):
#         ret = []
#         tab = '    '
# 
#         indent = tab * depth 
# 
#         graphtype = "digraph "
#         if depth:
#             graphtype = "subgraph cluster"
#         ret.append('%s%s%s {' % (indent, graphtype, self.name))
# 
#         for k,v in self.options.items():
#             ret.append('%s%s = "%s";' % (indent, k, v))
# 
#         for sg in self._subgraphs:
#             ret.append(sg.todot(depth+1))
# 
#         indent = tab * (depth + 1)
#         for node in self.nodes:
#             ret.append('%s"%s" [%s];' % (indent, node.name, opt_to_str(node.options)))
# 
#         for edge in self.edges: # fixme: this ignore edge options
#             ret.append('%s"%s" -> "%s" [%s];' % (indent, edge.tail, edge.head, 
#                                                  opt_to_str(edge.options)))
# 
#         ret.append('%s}' % indent)
#         return '\n'.join(ret)
# 
#     def __str__(self):
#         return self.todot()


from .graph import Graph
import waflib.Logs as msg
#!/usr/bin/env python
'''
Write a dot file which shows the waf dependency graph.
'''

def make(bld):
    '''
    Return a graph of the task dependencies
    '''

    # Explicit posting of the top level task generators, which are
    # features, is needed so they can run an produce their (sub) task
    # generators
    #for tg in bld.get_all_task_gen():
    #    tg.post()

    for tg in bld.get_all_task_gen():
        msg.debug('dot: tg = %s, "%s"' % (tg, '", "'.join(sorted(tg.__dict__.keys()))))
        msg.debug('dot: name:%s -  source:%s -> target:%s, depends_on:%s' % \
            (tg.name, tg.source, tg.target,
             getattr(tg, 'depends_on', 'none')))



# Path: py-hwaftools/orch/graph.py
# class Graph(object):
#     def __init__(self, name, **options):
#         self.name = name
#         self.options = options
#         self._subgraphs = list()
#         self.nodes = set()
#         self.edges = set()
# 
#     def get_subgraph(self, name):
#         for sg in self._subgraphs:
#             if sg.name == name:
#                 return sg
#         return
# 
#     def set_subgraph(self, sg):
#         for ind, oldsg in enumerate(self._subgraphs):
#             if oldsg.name == name:
#                 self._subgraphs[ind] = sg
#                 return oldsg
#         self._subgraphs.append(sg)
#         return
# 
#     def graph(self, name = None):
#         if name is None or name == self.name:
#             return self
#         g = self.get_subgraph(name)
#         if not g: 
#             g = Graph(name)
#             self.set_subgraph(g)
#         return g
# 
#     def add_subgraph(self, name, **options):
#         already = self.get_subgraph(name)
#         if already:
#             already.options = options
#             return already
#         g = Graph(name, **options)
#         self._subgraphs.append(g)
#         return g
# 
#     def add_node(self, name, graph_name = None, **options):
#         self.graph(graph_name).nodes.add(Node(name,**options))
# 
#     def add_edge(self, tail, head, graph_name = None, **options):
#         self.graph(graph_name).edges.add(Edge(tail,head,**options))
# 
#     def todot(self, depth = 0):
#         ret = []
#         tab = '    '
# 
#         indent = tab * depth 
# 
#         graphtype = "digraph "
#         if depth:
#             graphtype = "subgraph cluster"
#         ret.append('%s%s%s {' % (indent, graphtype, self.name))
# 
#         for k,v in self.options.items():
#             ret.append('%s%s = "%s";' % (indent, k, v))
# 
#         for sg in self._subgraphs:
#             ret.append(sg.todot(depth+1))
# 
#         indent = tab * (depth + 1)
#         for node in self.nodes:
#             ret.append('%s"%s" [%s];' % (indent, node.name, opt_to_str(node.options)))
# 
#         for edge in self.edges: # fixme: this ignore edge options
#             ret.append('%s"%s" -> "%s" [%s];' % (indent, edge.tail, edge.head, 
#                                                  opt_to_str(edge.options)))
# 
#         ret.append('%s}' % indent)
#         return '\n'.join(ret)
# 
#     def __str__(self):
#         return self.todot()


# Path: py-hwaftools/orch/dot.py
from .graph import Graph
import waflib.Logs as msg

#!/usr/bin/env python
'''
Write a dot file which shows the waf dependency graph.
'''

def make(bld):
    '''
    Return a graph of the task dependencies
    '''

    # Explicit posting of the top level task generators, which are
    # features, is needed so they can run an produce their (sub) task
    # generators
    #for tg in bld.get_all_task_gen():
    #    tg.post()

    for tg in bld.get_all_task_gen():
        msg.debug('dot: tg = %s, "%s"' % (tg, '", "'.join(sorted(tg.__dict__.keys()))))
        msg.debug('dot: name:%s -  source:%s -> target:%s, depends_on:%s' % \
            (tg.name, tg.source, tg.target,
             getattr(tg, 'depends_on', 'none')))



    maingraph = Graph('worch', rankdir='LR')