s3 rpc_client: Fix Asan stack use after scope
[Samba.git] / source4 / script / depfilter.py
blob1f741f746e08f4dcafdb5d25452e1f7a2c8e138d
1 #!/usr/bin/env python3
3 # Filter out arcs in a dotty graph that are at or below a certain
4 # node. This is useful for visualising parts of the dependency graph.
7 # Command line stuff
9 from __future__ import print_function
10 import sys
11 import re
13 if len(sys.argv) != 2:
14 print('Usage: depfilter.py NODE')
15 sys.exit(1)
17 top = sys.argv[1]
19 # Read in dot file
21 lines = sys.stdin.readlines()
23 graph = {}
25 for arc in lines[1:-1]:
26 match = re.search('"(.*)" -> "(.*)"', arc)
27 n1, n2 = match.group(1), match.group(2)
28 if n1 not in graph:
29 graph[n1] = []
30 graph[n1].append(n2)
32 # Create subset of 'graph' rooted at 'top'
34 subgraph = {}
37 def add_deps(node):
38 if node in graph and node not in subgraph:
39 subgraph[node] = graph[node]
40 for n in graph[node]:
41 add_deps(n)
44 add_deps(top)
46 # Generate output
48 print(lines[0], end=' ')
50 for key, value in subgraph.items():
51 for n in value:
52 print('\t"%s" -> "%s"' % (key, n))
54 print(lines[-1], end=' ')