]> git.ipfire.org Git - ipfire.org.git/blob - build/distcc.py
Imported other web components.
[ipfire.org.git] / build / distcc.py
1 #!/usr/bin/python
2
3 import cgitb, os, time, cgi, re, random, socket, DNS
4 cgitb.enable()
5
6 def print_http_header():
7 print "Content-type: text/html"
8 print
9
10 def print_header():
11 print_http_header()
12 print '''<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
13 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
14 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
15 <head>
16 <title>IPFire - DistccWatch</title>
17 <style type="text/css">
18 body { font-family: Verdana; font-size: 9pt; background-color:#f0f0f0; }
19 a:link { color: black; text-decoration: none; }
20 a:visited { color: black; text-decoration: none; }
21 table { font-family: Verdana; font-size: 8pt; border: 1px solid; }
22 td.header { background-color: #a0a0a0; text-align: center; color: white; }
23 td.date { text-align: center; }
24 font.installed { color: green; }
25 font.deleted { color: red; }
26 font.update { color: blue; }
27 font.error { color: red; }
28 td.online { background: green; color: white; text-align: center; }
29 td.offline { background: red; color: white; text-align: center; }
30 </style>
31 <meta http-equiv="refresh" content="60; URL=%s" />
32 </head>
33 <body>
34 <h1>IPFire DistccWatch</h1>
35 <p>Made: %s</p>''' % (os.environ['SCRIPT_NAME'], time.ctime())
36
37 def print_footer():
38 print "\t</body>\n</html>"
39
40 def print_dcc_info():
41 print "<pre>",
42 print os.popen("distcc --version").read(),
43 print "</pre>"
44
45 def read_hosts():
46 f = open("hosts")
47 hosts = []
48 while True:
49 line = f.readline()
50 if len(line) == 0:
51 hosts.sort()
52 return hosts
53 break #EOF
54
55 if not line.startswith("#"):
56 hosts.append(line.rstrip("\n"))
57
58 def process_hosts(hosts=""):
59 if not hosts:
60 print "You need to specify the hosts you want to check in the config file."
61 return
62
63 print '''<table width='66%'>
64 <tr>
65 <td class='header' width='68%'>Host</td>
66 <td class='header' width='16%'>State</td>
67 <td class='header' width='16%'>Probe</td>
68 </tr>'''
69
70 for hostname in hosts:
71
72 state = "DOWN"
73 time = "&nbsp;"
74 command = "HOME=tmp DISTCC_HOSTS=\"%s\" DISTCC_VERBOSE=1 distcc probe.c -S -o /dev/null 2>&1" % hostname
75 state_pattern = re.compile("on %s completed ok" % hostname)
76 time_pattern = re.compile("elapsed compilation time ")
77
78 for line in os.popen(command).readlines():
79 state_result = re.search(state_pattern, line)
80 time_result = re.search(time_pattern, line)
81 if not state_result == None:
82 state = "UP"
83 if not time_result == None:
84 if state == "UP":
85 time = time_result.string[-10:]
86
87 print "<tr><td><pre>%s</pre></td><td>%s</td><td>%s</td></tr>" % (hostname, state, time)
88
89 print "</table>"
90
91 def mixup_hosts(hosts=""):
92 string = ""
93 while True:
94 if len(hosts) == 0:
95 break
96
97 rand = random.randint(0, len(hosts)-1)
98 host, options = re.split(re.compile(':'),hosts[rand])
99 string += socket.gethostbyname(host) + ":" + options + " "
100 hosts.pop(rand)
101
102 print string
103
104 form = cgi.FieldStorage()
105 action = form.getfirst('action')
106
107 if action == "raw":
108 print_http_header()
109
110 hosts = read_hosts()
111
112 mixup_hosts(hosts)
113
114 else:
115
116 print_header()
117 print_dcc_info()
118
119 hosts = read_hosts()
120
121 process_hosts(hosts)
122
123 print_footer()