blob: ee2ce9d706a10b768c63e99080016f0aed189754 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
#!/usr/bin/env python3
#
# Filter out arcs in a dotty graph that are at or below a certain
# node. This is useful for visualising parts of the dependency graph.
#
# Command line stuff
import sys
import re
if len(sys.argv) != 2:
print('Usage: depfilter.py NODE')
sys.exit(1)
top = sys.argv[1]
# Read in dot file
lines = sys.stdin.readlines()
graph = {}
for arc in lines[1:-1]:
match = re.search('"(.*)" -> "(.*)"', arc)
n1, n2 = match.group(1), match.group(2)
if n1 not in graph:
graph[n1] = []
graph[n1].append(n2)
# Create subset of 'graph' rooted at 'top'
subgraph = {}
def add_deps(node):
if node in graph and node not in subgraph:
subgraph[node] = graph[node]
for n in graph[node]:
add_deps(n)
add_deps(top)
# Generate output
print(lines[0], end=' ')
for key, value in subgraph.items():
for n in value:
print('\t"%s" -> "%s"' % (key, n))
print(lines[-1], end=' ')
|