Reputation: 11476
I am trying to construct a python call graph as below,I have a change which has internal and external dependencies and these dependencies need to be recursivley into until each leaf gets a change which is closed...i have the logic to get the internal and external dependency ,I need some inputs or a body how to construct a graph as below..
change
/ \
/ \
/ \
internal dependency external dependency
/ \ /\
/ \ / \
/ \ / \
/ \ / \
internal dep external dep internal dep external dep (repeat this until the dependency change is in closed state)
Upvotes: 1
Views: 2851
Reputation: 103844
This will be easier if you turn the expected output on its side. Then create a tree structure of what you want:
class Tree(object):
def __init__(self, name, *children):
self.name = name
self.children = children
def __str__(self):
return '\n'.join(self.tree_lines())
def tree_lines(self):
yield self.name
last = self.children[-1] if self.children else None
for child in self.children:
prefix = '`-' if child is last else '+-'
for line in child.tree_lines():
yield prefix + line
prefix = ' ' if child is last else '| '
tree = Tree('Change',
Tree('External',
Tree('External A'),Tree('External B'),Tree('External C',Tree('Sub Ext C'))),
Tree('Internal',
Tree('Internal A'),Tree('Internal B',Tree('Sub Int B')),Tree('Internal C'))
)
print tree
Prints:
Change
+-External
| +-External A
| +-External B
| `-External C
| `-Sub Ext C
`-Internal
+-Internal A
+-Internal B
| `-Sub Int B
`-Internal C
Upvotes: 2