]> git.ipfire.org Git - ipfire.org.git/blob - build/index.py
Save $TARGET in database.
[ipfire.org.git] / build / index.py
1 #!/usr/bin/python
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2008 Michael Tremer & Christian Schmidt #
6 # #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
11 # #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
16 # #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 # #
20 ###############################################################################
21
22 import os
23 import sys
24 import time
25
26 sys.path.append(".")
27
28 from builder import Builder, getAllBuilders
29 from constants import *
30
31 def format_time(seconds, use_hours=1):
32 if seconds is None or seconds < 0:
33 if use_hours: return '--:--:--'
34 else: return '--:--'
35 else:
36 seconds = int(seconds)
37 minutes = seconds / 60
38 seconds = seconds % 60
39 if use_hours:
40 hours = minutes / 60
41 minutes = minutes % 60
42 return '%02i:%02i:%02i' % (hours, minutes, seconds)
43 else:
44 return '%02i:%02i' % (minutes, seconds)
45
46 class Site:
47 def __init__(self, config):
48 self.builders = None
49 self.config = config
50 print "Content-type: text/html"
51 print
52
53 def __call__(self, builders=None):
54 self.builders = builders
55 print """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
56 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
57 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
58 <head>
59 <title>%(title)s</title>
60 <style type="text/css">
61 * {
62 margin: auto;
63 padding: 0;
64 text-decoration: none;
65 outline: none;
66 }
67 body {
68 font-family: Verdana;
69 font-size: 90%%;
70 background-color:#f9f9f9;
71 }
72 h1 {
73 text-decoration: underline;
74 }
75 #header {
76 width: 800px;
77 height: 115px;
78 text-align: center;
79 background: #E0E0E0;
80 border: 1px solid #999;
81 padding-top: 10px;
82 }
83 #content {
84 padding-top: 10px;
85 width: 800px;
86 }
87 div.box {
88 padding: 5px;
89 margin: 10px 0 10px 0;
90 /* height: 80px; */
91 border: 1px solid;
92 }
93 div.infobox {
94 float: right;
95 width: 240px;
96 }
97 div.log {
98 background: #e55;
99 border: 1px dotted;
100 margin-top: 12px;
101 /* visibility: hidden; */
102 }
103 div.log p {
104 font-family: Courier New;
105 }
106 p {
107 margin: 2px;
108 }
109 p.boxheader {
110 font-weight: bold;
111 }
112 p.online {
113 color: green;
114 }
115 p.offline {
116 color: red;
117 }
118 p.package {
119 font: bold;
120 font-size: 150%%;
121 }
122 img.right {
123 float: right;
124 }
125 p.desc {
126 text-decoration: bold;
127 }
128 a:link {
129 color: black; text-decoration: none;
130 }
131 a:visited {
132 color: black; text-decoration: none;
133 }
134 </style>
135 <meta http-equiv="refresh" content="90; URL=%(script)s" />
136 </head>
137 <body>
138 <div id="header">
139 <h1>IPFire Builder</h1>""" % self.config
140 if self.builders:
141 print """\
142 <p>
143 """,
144 for builder in self.builders:
145 print builder,
146 print """
147 </p>"""
148 for i in self.config["nightly_url"]:
149 print """\
150 <p><a href="%s" target="_blank">%s</a></p>""" % (i, i,)
151 print """\
152 </div>"""
153
154 self.content()
155
156 print "\t\t</body>\n</html>"
157
158 def content(self):
159 if self.builders:
160 count = 0
161 print """\
162 <div id="content">"""
163 for builder in self.builders:
164 builder(count)
165 count += 1
166 print """\
167 </div>"""
168
169 class Box:
170 def __init__(self, builder):
171 self.builder = builder
172
173 def __call__(self, count):
174 print """\
175 <a name="%s"></a>
176 <div class="box" style="%s">"""\
177 % (self.builder.hostname(), state2style[self.builder.state()],)
178 print """\
179 <div class="infobox">"""
180 self.distccinfo()
181 self.package()
182 self.time()
183 print """\
184 </div>"""
185 self.header()
186 self.stateinfo()
187 self.durations()
188 if self.builder.state() == "error":
189 self.log()
190 print """\
191 </div>"""
192
193 def __str__(self):
194 return """<a href="#%(hostname)s">%(hostname)s</a>""" % { "hostname" : self.builder.hostname(), }
195
196 def header(self):
197 print """\
198 <p class="boxheader">
199 %(hostname)s <span>[%(uuid)s]</span>
200 </p>
201 <!-- <img class="right" src="/images/%(state)s.png" /> -->""" \
202 % { "hostname" : self.builder.hostname(),
203 "state" : self.builder.state(),
204 "uuid" : self.builder.uuid, }
205
206 def package(self):
207 if self.builder.state() in [ "compiling", "error", ]:
208 print """\
209 <p class="package">%s</p>"""\
210 % self.builder.package()
211
212 def time(self):
213 print """\
214 <p>%s</p>""" \
215 % time.ctime(float(self.builder.state.time()))
216
217 def stateinfo(self):
218 if self.builder.state() in [ "compiling", "error", "idle", ]:
219 print """\
220 <p class="desc">%s</p>""" \
221 % statedesc[self.builder.state()]
222
223 def durations(self):
224 print """\
225 <p>Average Build Duration: %s</p>""" \
226 % format_time(self.builder.duration.get_avg())
227 if self.builder.state() == "compiling":
228 print """\
229 <p>ETA: %s</p>""" \
230 % self.builder.duration.get_eta(self.builder.state.time())
231
232 def distccinfo(self):
233 state = self.builder.distcc.ping()
234 port = self.builder.distcc()
235 if port == "0":
236 state = False
237 port = "disabled"
238 print """\
239 <p class="%s">Distcc: %s</p>""" \
240 % (ping2class[state], port,)
241
242 def log(self):
243 log = self.builder.log()
244 if log:
245 print """\
246 <div class="log">
247 <p>"""
248 for i in log:
249 print "%s<br />" % (i.rstrip("\n"),)
250 print """\
251 </p>
252 </div>
253 """
254
255 site = Site(config)
256
257 boxes = []
258 for builder in getAllBuilders(3):
259 boxes.append(Box(builder))
260
261 site(boxes)