]> git.ipfire.org Git - ipfire.org.git/blob - build/index.py
Added a small footer line with additional information.
[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 div.footer {
107 }
108 div.footer p {
109 text-align: center;
110 font-size: 5px;
111 }
112 p {
113 margin: 2px;
114 }
115 p.boxheader {
116 font-weight: bold;
117 }
118 p.online {
119 color: green;
120 }
121 p.offline {
122 color: red;
123 }
124 p.package {
125 font: bold;
126 font-size: 150%%;
127 }
128 img.right {
129 float: right;
130 }
131 p.desc {
132 text-decoration: bold;
133 }
134 a:link {
135 color: black; text-decoration: none;
136 }
137 a:visited {
138 color: black; text-decoration: none;
139 }
140 </style>
141 <meta http-equiv="refresh" content="90; URL=%(script)s" />
142 </head>
143 <body>
144 <div id="header">
145 <h1>IPFire Builder</h1>""" % self.config
146 if self.builders:
147 print """\
148 <p>
149 """,
150 for builder in self.builders:
151 print builder,
152 print """
153 </p>"""
154 for i in self.config["nightly_url"]:
155 print """\
156 <p><a href="%s" target="_blank">%s</a></p>""" % (i, i,)
157 print """\
158 </div>"""
159
160 self.content()
161
162 print "\t\t</body>\n</html>"
163
164 def content(self):
165 if self.builders:
166 count = 0
167 print """\
168 <div id="content">"""
169 for builder in self.builders:
170 builder(count)
171 count += 1
172 print """\
173 </div>"""
174
175 class Box:
176 def __init__(self, builder):
177 self.builder = builder
178
179 def __call__(self, count):
180 print """\
181 <a name="%s"></a>
182 <div class="box" style="%s">"""\
183 % (self.builder.hostname(), state2style[self.builder.state()],)
184 print """\
185 <div class="infobox">"""
186 self.distccinfo()
187 self.package()
188 self.time()
189 print """\
190 </div>"""
191 self.header()
192 self.stateinfo()
193 self.durations()
194 if self.builder.state() == "error":
195 self.log()
196 self.footer()
197 print """\
198 </div>"""
199
200 def __str__(self):
201 return """<a href="#%(hostname)s">%(hostname)s</a>""" % { "hostname" : self.builder.hostname(), }
202
203 def header(self):
204 print """\
205 <p class="boxheader">
206 %(hostname)s <span>[%(uuid)s]</span>
207 </p>
208 <!-- <img class="right" src="/images/%(state)s.png" /> -->""" \
209 % { "hostname" : self.builder.hostname(),
210 "state" : self.builder.state(),
211 "uuid" : self.builder.uuid, }
212
213 def package(self):
214 if self.builder.state() in [ "compiling", "error", ]:
215 print """\
216 <p class="package">%s</p>"""\
217 % self.builder.package()
218
219 def time(self):
220 print """\
221 <p>%s</p>""" \
222 % time.ctime(float(self.builder.state.time()))
223
224 def stateinfo(self):
225 if self.builder.state() in [ "compiling", "error", "idle", ]:
226 print """\
227 <p class="desc">%s</p>""" \
228 % statedesc[self.builder.state()]
229
230 def durations(self):
231 print """\
232 <p>Average Build Duration: %s</p>""" \
233 % format_time(self.builder.duration.get_avg())
234 if self.builder.state() == "compiling":
235 print """\
236 <p>ETA: %s</p>""" \
237 % self.builder.duration.get_eta(self.builder.state.time())
238
239 def distccinfo(self):
240 state = self.builder.distcc.ping()
241 port = self.builder.distcc()
242 if port == "0":
243 state = False
244 port = "disabled"
245 print """\
246 <p class="%s">Distcc: %s</p>""" \
247 % (ping2class[state], port,)
248
249 def log(self):
250 log = self.builder.log()
251 if log:
252 print """\
253 <div class="log">
254 <p>"""
255 for i in log:
256 print "%s<br />" % (i.rstrip("\n"),)
257 print """\
258 </p>
259 </div>
260 """
261
262 def footer(self):
263 print """\
264 <div class="footer">
265 <p>target: %s - jobs: %s</p>
266 </div>
267 """ % (self.builder.target(), self.builder.jobs(),)
268
269 site = Site(config)
270
271 boxes = []
272 for builder in getAllBuilders(3):
273 boxes.append(Box(builder))
274
275 site(boxes)