unix/minit

contrib/minit-graph in master
Repositories | Summary | Log | Files | README | COPYING

minit-graph (1009B) download


 1#!/usr/bin/python
 2
 3# Contributed by Tommi Virtanen <[email protected]>
 4# Try:
 5# minit-graph /etc/minit >foo.dot
 6# dot -Tps -o foo.ps foo.dot
 7# gv foo.ps
 8
 9# dot is part of graphviz (http://www.graphviz.org/) --fefe
10
11import os, errno, string
12
13def safe(s):
14    r=""
15    for c in s:
16        if c not in "abcdefghijklmnopqrstuvwxyz0123456789_":
17            c="_"
18        r+=c
19    return r
20
21import sys
22try:
23    dir = sys.argv[1]
24except IndexError:
25    dir = '.'
26
27print "digraph minit {"
28
29for svc in os.listdir(dir):
30    if svc=="in" or svc=="out":
31        continue
32    if os.path.exists(os.path.join(dir, svc, "sync")):
33        print "%s [shape=box];"%safe(svc)
34    else:
35        print "%s;"%safe(svc)
36    try:
37        file = open(os.path.join(dir, svc, "depends"))
38    except IOError, e:
39        if e.errno == errno.ENOENT:
40            pass
41        else:
42            raise
43    else:
44        for dep in file.xreadlines():
45            print "%s -> %s;" % (safe(svc), safe(dep.strip()))
46        file.close()
47
48print "};"
49