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

Contents of /build_system/web/index.php

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.30