/[soft]/build_system/web/index.php
ViewVC logotype

Contents of /build_system/web/index.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 947 - (show annotations) (download)
Tue Apr 19 12:01:43 2011 UTC (13 years ago) by rda
File size: 12370 byte(s)
obsolete badges
1 <?php
2 /**
3 * Mageia build-system quick status report script.
4 *
5 * @copyright Copyright (C) 2011 Mageia.Org
6 *
7 * @author Olivier Blin
8 * @author Pascal Terjan
9 * @author Romain d'Alverny
10 *
11 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU GPL v2
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License aspublished by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version.
17 *
18 *
19 * Shows submitted packages in the past $max_modified 24 hours and their
20 * status (built & uploaded, failed build, rejected, etc.).
21 *
22 * This was written anew in Jan. 2011 because existing Mandriva build-system
23 * web report code was not clearly licensed at this very time.
24 */
25
26 error_reporting(E_ALL);
27
28 /**
29 * @param array $pkg
30 *
31 * @return string
32 */
33 function pkg_gettype($pkg) {
34 if (array_key_exists("rejected", $pkg["status"]))
35 return "rejected";
36 if (array_key_exists("youri", $pkg["status"])) {
37 if (array_key_exists("src", $pkg["status"]))
38 return "youri";
39 else
40 return "uploaded";
41 }
42 if (array_key_exists("failure", $pkg["status"]))
43 return "failure";
44 if (array_key_exists("done", $pkg["status"]))
45 return "partial";
46 if (array_key_exists("build", $pkg["status"]))
47 return "building";
48 if (array_key_exists("todo", $pkg["status"]))
49 return "todo";
50 return "unknown";
51 }
52
53 /**
54 * @param integer $num
55 *
56 * @return string
57 */
58 function plural($num) {
59 if ($num > 1)
60 return "s";
61 }
62
63 /**
64 * Return timestamp from package key
65 * @param string $key package submission key
66 *
67 * @return integer
68 */
69
70 function key2timestamp($key) {
71 global $tz;
72
73 $date = DateTime::createFromFormat("YmdHis", $key+0, $tz);
74 if ($date <= 0)
75 return null;
76
77 return $date->getTimestamp();
78 }
79
80 function timediff($start, $end) {
81 /**
82 * Return human-readable time difference
83 *
84 * @param integer $start timestamp
85 * @param integer $end timestamp, defaults to now
86 *
87 * @return string
88 */
89 if (is_null($end)) {
90 $end = time();
91 }
92 $diff = $end - $start;
93 if ($diff<60)
94 return $diff . " second" . plural($diff);
95 $diff = round($diff/60);
96 if ($diff<60)
97 return $diff . " minute" . plural($diff);
98 $diff = round($diff/60);
99 if ($diff<24)
100 return $diff . " hour" . plural($diff);
101 $diff = round($diff/24);
102
103 return $diff . " day" . plural($diff);
104 }
105
106 $g_user = isset($_GET['user']) ? htmlentities(strip_tags($_GET['user'])) : null;
107
108 $upload_dir = '/home/schedbot/uploads';
109 $max_modified = 2;
110 $title = '<a href="http://mageia.org/">Mageia</a> build system status';
111 $robots = 'index,nofollow,nosnippet,noarchive';
112 if ($g_user) {
113 $title .= ' for ' . $g_user . "'s packages";
114 $robots = 'no' . $robots;
115 }
116 $tz = new DateTimeZone('UTC');
117 $date_gen = date('c');
118
119 # Temporary until initial mirror is ready
120 chdir("data");
121 $missing_deps = file("missing-deps.i586.txt");
122 #########################################
123
124 chdir($upload_dir);
125
126 $all_files = shell_exec("find \( -name '*.rpm' -o -name '*.src.rpm.info' -o -name '*.youri' -o -name '*.lock' -o -name '*.done' \) -ctime -$max_modified -printf \"%p\t%T@\\n\"");
127 $re = "!^\./(\w+)/((\w+)/(\w+)/(\w+)/(\d+)\.(\w+)\.(\w+)\.(\d+))_?(.*)(\.src\.rpm(?:\.info)?|\.youri|\.lock|\.done)\s+(\d+\.\d+)$!m";
128 $r = preg_match_all($re,
129 $all_files,
130 $matches,
131 PREG_SET_ORDER);
132
133 $pkgs = array();
134
135 $buildtime_total = 0;
136 $build_count = 0;
137
138 foreach ($matches as $val) {
139
140 if ($_GET['user'] && ($_GET['user'] != $val[7])) {
141 continue;
142 }
143 $key = $val[6] . $val[7];
144 if (!is_array($pkgs[$key])) {
145
146 $pkgs[$key] = array(
147 'status' => array(),
148 'path' => $val[2],
149 'version' => $val[3],
150 'media' => $val[4],
151 'section' => $val[5],
152 'user' => $val[7],
153 'host' => $val[8],
154 'job' => $val[9]
155 );
156 }
157 $status = $val[1];
158 $data = $val[10];
159 if (preg_match("/@(\d+):/", $data, $revision)) {
160 $pkgs[$key]['revision'] = $revision[1];
161 }
162 $pkgs[$key]['status'][$status] = 1;
163 $ext = $val[11];
164 if ($ext == '.src.rpm.info') {
165 preg_match("!^(?:@\d+:)?(.*)!", $data, $name);
166 $pkgs[$key]['package'] = $name[1];
167 } else if ($ext == '.src') {
168 $pkgs[$key]['status']['src'] = 1;
169 } else if ($ext == '.youri') {
170 $pkgs[$key]['status']['youri'] = 1;
171 } else if ($ext == '.lock') {
172 // parse build bot from $data
173 $pkgs[$key]['status']['build'] = 1;
174 } else if ($ext == '.done') {
175 $pkgs[$key]['buildtime']['start'] = key2timestamp($val[6]);
176 $pkgs[$key]['buildtime']['end'] = round($val[12]);
177 $pkgs[$key]['buildtime']['diff'] = $pkgs[$key]['buildtime']['end'] - $pkgs[$key]['buildtime']['start'];
178 $buildtime_total += $pkgs[$key]['buildtime']['diff'];
179 $build_count += 1;
180 }
181 }
182 // sort by key in reverse order to have more recent pkgs first
183 krsort($pkgs);
184
185 // count all packages statuses
186 $stats = array(
187 'uploaded' => 0,
188 'failure' => 0,
189 'todo' => 0,
190 'building' => 0,
191 'partial' => 0,
192 'built' => 0,
193 );
194 $total = count($pkgs);
195
196 // count users' packages
197 $users = array();
198
199 if ($total > 0) {
200 foreach ($pkgs as $key => $p) {
201 $pkgs[$key]['type'] = pkg_gettype($p);
202
203 $stats[$pkgs[$key]['type']] += 1;
204
205 if (!array_key_exists($p['user'], $users))
206 $users[$p['user']] = 1;
207 else
208 $users[$p['user']] += 1;
209 }
210 }
211
212 foreach ($stats as $k => $v) {
213 Header("X-BS-Queue-$k: $v");
214 }
215
216 $w = $stats['todo'] - 10;
217 if($w < 0)
218 $w = 0;
219 $w = $w * 60;
220 Header("X-BS-Throttle: $w");
221
222 $buildtime_total = $buildtime_total / 60;
223 header(sprintf('X-BS-Buildtime: %d', round($buildtime_total)));
224 $buildtime_avg = round($buildtime_total / $build_count, 2);
225 header(sprintf('X-BS-Buildtime-Average: %5.2f', $buildtime_avg));
226 ?>
227 <!DOCTYPE html>
228 <html lang="en">
229 <head>
230 <meta charset="utf-8">
231 <title><?php echo strip_tags($title); ?></title>
232 <meta name="robots" content="<?php echo $robots; ?>">
233 <link rel="icon" type="image/png" href="favicon.png" />
234 <style type="text/css">
235 .clear { clear: both; }
236 table {
237 border-spacing: 0;
238 font-family: Helvetica, Verdana, Arial, sans-serif; font-size: 80%;
239 border: 1px solid #ccc;
240 float: left;
241 }
242 table tr { padding: 0; margin: 0; }
243 table th { padding: 0.2em 0.5em; margin: 0; border-bottom: 2px solid #ccc; border-right: 1px solid #ccc; }
244 table td { padding: 0; margin: 0; padding: 0.2em 0.5em; border-bottom: 1px solid #ccc; }
245
246 tr { background: transparent; }
247 tr.uploaded { background: #bbffbb; }
248 tr.failure, tr.rejected { background: #ffbbbb; }
249 tr.todo { background: white; }
250 tr.building { background: #ffff99; }
251 tr.partial { background: #bbbbff; }
252 tr.built { background: #cceeff; }
253 tr.youri { background: #aacc66; }
254
255 td.status-box { width: 1em; height: 1em; }
256 tr.uploaded td.status-box { background: green; }
257 tr.failure td.status-box, tr.rejected td.status-box { background: red; }
258 tr.todo td.status-box { background: white; }
259 tr.building td.status-box { background: yellow; }
260 tr.partial td.status-box { background: blue; }
261 tr.built td.status-box { background: #00ccff; }
262 tr.youri td.status-box { background: olive; }
263
264 #stats { float: right; }
265 #score { margin-bottom: 2em; font-family: Helvetica, Verdana, Arial, sans-serif; }
266 #score-box { width: 100px; height: 100px; background: #faa; }
267 #score-meter { width: 100px; background: #afa; }
268 </style>
269 </head>
270 <body>
271 <h1><?php echo $title ?></h1>
272
273 <?php
274 if (!is_null($g_user))
275 echo '<a href="/">&laquo;&nbsp;Back to full list</a>';
276
277 # Temporary until initial mirror is ready
278 echo sprintf(
279 '<p><a href="%s">%d broken dependencies</a>. <strong><a href="%s">You can help!</a></strong></p>',
280 'data/missing-deps.i586.txt', count($missing_deps),
281 'http://www.mageia.org/wiki/doku.php?id=packaging#starting_package_import'
282 );
283
284 #########################################
285
286 $buildtime_stats = array();
287
288 $s = '';
289 $tmpl = <<<T
290 <tr class="%s">
291 <td>%s</td>
292 <td><a href="?user=%s">%s</a></td>
293 <td><a href="http://svnweb.mageia.org/packages?view=revision&revision=%d" title="%s">%s</a></td>
294 <td>%s</td>
295 <td>%s/%s</td>
296 <td class="status-box"></td>
297 T;
298
299 if ($total > 0) {
300 foreach ($pkgs as $key => $p) {
301 $s .= sprintf($tmpl,
302 $p['type'],
303 timediff(key2timestamp($key)) . ' ago',
304 $p['user'], $p['user'],
305 $p['revision'],
306 addslashes($p['summary']),
307 $p['package'],
308 $p['version'],
309 $p['media'], $p['section']
310 );
311
312 $typelink = '';
313 if ($p['type'] == 'failure') {
314 $typelink = '/uploads/' . $p['type'] . '/' . $p['path'];
315 } elseif ($p['type'] == 'rejected') {
316 $typelink = '/uploads/' . $p['type'] . '/' . $p['path'] . '.youri';
317 }
318
319 $s .= '<td>';
320 $s .= ($typelink != '') ?
321 sprintf('<a href="%s">%s</a>', $typelink, $p['type']) :
322 $p['type'];
323
324 $s .= '</td><td>';
325 if ($p['type'] == 'uploaded') {
326 $tdiff = timediff($p['buildtime']['start'], $p['buildtime']['end']); // use $p['buildtime']['diff']; instead?
327 $s .= $tdiff;
328 @$buildtime_stats[$tdiff] += 1;
329 }
330 $s .= '</td>';
331 $s .= '</tr>';
332 }
333 // Table
334 echo '<table>',
335 '<caption>', $total, ' packages submitted in the past ', $max_modified * 24, '&nbsp;hours.</caption>',
336 '<tr><th>Submitted</th><th>User</th>
337 <th>Package</th><th>Target</th><th>Media</th>
338 <th colspan="2">Status</th><th>Build time</th></tr>',
339 $s,
340 '</table>';
341
342 // Stats
343 $s = '<div id="stats">';
344 $score = round($stats['uploaded']/$total * 100);
345 $s .= sprintf('<div id="score"><h3>Score: %d/100</h3>
346 <div id="score-box"><div id="score-meter" style="height: %dpx;"></div></div></div>',
347 $score, $score);
348
349 $s .= '<table style="width: 100%"><caption>Stats.</caption><tr><th colspan="2">Status</th><th>Count</th><th>%</th></tr>';
350 foreach ($stats as $k => $v) {
351 $s .= sprintf('<tr class="%s"><td class="status-box"></td><td>%s</td><td>%d</td><td>%d%%</td></tr>',
352 $k, $k, $v, round($v/$total*100));
353 }
354
355 $s .= '</table><br /><br />';
356
357 $s .= '<table style="width: 100%"><caption>Packagers</caption><tr><th>User</th><th>Packages</th></tr>';
358 arsort($users);
359 foreach ($users as $k => $v)
360 $s .= sprintf('<tr><td><a href="/?user=%s">%s</a></td><td>%d</td></tr>',
361 $k, $k, $v);
362
363 $s .= '</table><br /><br />';
364
365 /**
366 */
367 function timesort($a, $b)
368 {
369 $a = explode(' ', trim($a));
370 $b = explode(' ', trim($b));
371
372 if ($a[1] == 'hour' || $a[1] == 'hours')
373 $a[0] *= 3600;
374
375 if ($b[1] == 'hour' || $a[1] == 'hours')
376 $b[0] *= 3600;
377
378 if ($a[0] > $b[0])
379 return 1;
380 elseif ($a[0] < $b[0])
381 return -1;
382
383 return 0;
384 }
385 uksort($buildtime_stats, "timesort");
386
387 $bts = '';
388 foreach ($buildtime_stats as $time => $count) {
389 $bts .= sprintf('<tr><td>%s</td><td>%d</td></tr>',
390 $time, $count);
391
392 $tmp = explode(' ', $time);
393 }
394
395 $s .= '<table style="width: 100%;"><caption>Build time</caption>';
396
397 $s .= sprintf('<tr><td>Total time</td><td>%s</td></tr>
398 <tr><td>Average</td><td>%s</td></tr>
399 <tr><td>Builds count</td><td>%s</td></tr>',
400 $buildtime_total,
401 $buildtime_avg,
402 $buildtime_cnt);
403
404 $s .= '<tr><th title="Build time">Duration</th><th title="Packages number">Pack. nb.</th></tr>';
405 $s .= $bts;
406 $s .= '</table><span style="font-size: 85%;">Does not take<br />build failures<br />into account.</span>';
407
408 $s .= '</div>';
409
410 echo $s;
411 }
412 else
413 {
414 echo sprintf('<p>No package has been submitted in the past %d&nbsp;hours.</p>',
415 $max_modified * 24);
416 }
417
418 ?>
419 <div class="clear"></div>
420 <hr />
421 <p>Generated at <?php echo $date_gen; ?>.</p>
422 </body>
423 </html>

  ViewVC Help
Powered by ViewVC 1.1.30