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

Annotation of /build_system/web/index.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1253 - (hide annotations) (download)
Mon May 9 18:36:23 2011 UTC (12 years, 11 months ago) by misc
File size: 13940 byte(s)
nicer message when there is missing deps

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

  ViewVC Help
Powered by ViewVC 1.1.30