s3-spoolss: Fix Bug #6568: _spoolss_GetPrintProcessorDirectory() implementation.
[Samba.git] / source4 / script / depfilter.py
blob74d1d179c722700b02cf6ff43b5fdcd4230e20a9
1 #!/usr/bin/python
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 import sys, sre
11 if len(sys.argv) != 2:
12 print 'Usage: depfilter.py NODE'
13 sys.exit(1)
15 top = sys.argv[1]
17 # Read in dot file
19 lines = sys.stdin.readlines()
21 graph = {}
23 for arc in lines[1:-1]:
24 match = sre.search('"(.*)" -> "(.*)"', arc)
25 n1, n2 = match.group(1), match.group(2)
26 if not graph.has_key(n1):
27 graph[n1] = []
28 graph[n1].append(n2)
30 # Create subset of 'graph' rooted at 'top'
32 subgraph = {}
34 def add_deps(node):
35 if graph.has_key(node) and not subgraph.has_key(node):
36 subgraph[node] = graph[node]
37 for n in graph[node]:
38 add_deps(n)
40 add_deps(top)
42 # Generate output
44 print lines[0],
46 for key, value in subgraph.items():
47 for n in value:
48 print '\t"%s" -> "%s"' % (key, n)
50 print lines[-1],