From 9768c137934d96b176be7232b64e50153abe3275 Mon Sep 17 00:00:00 2001 From: Costa Shulyupin Date: Sun, 29 Jul 2018 09:06:36 +0300 Subject: [PATCH] *digraph_tree --- srcxray.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/srcxray.py b/srcxray.py index 49d1b27..86f4423 100755 --- a/srcxray.py +++ b/srcxray.py @@ -419,7 +419,7 @@ def digraph_tree(dg, starts=None): def sub(node): tree.add_node(node) for o in dg.successors(node): - if o in black_list or tree.has_edge(node, o): + if o in black_list or tree.has_node(o): continue tree.add_edge(node,o) sub(o) @@ -430,12 +430,14 @@ def digraph_tree(dg, starts=None): for i in [n for (n, d) in dg.in_degree if not d]: starts[i] = dg.out_degree(i) starts = [a[0] for a in sorted(starts.items(), key=lambda k: k[1], reverse=True)] - if len(starts) > 1: - o.add_node('starts') - for o in starts: - if o in black_list: - continue - sub(o) + if len(starts) == 1: + sub(starts[0]) + elif len(starts) > 1: + for o in starts: + if o in black_list: + continue + tree.add_edge('start',o) + sub(o) return tree