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

Annotation of /build_system/web/index.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 313 - (hide annotations) (download)
Tue Jan 18 12:43:53 2011 UTC (13 years, 3 months ago) by pterjan
File size: 10659 byte(s)
Fixes
1 pterjan 268 <?php
2 rda 298 /**
3     * Mageia build-system quick status report script.
4     *
5 blino 300 * @copyright Copyright (C) 2011 Olivier Blin
6 rda 298 *
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 pterjan 268
25     error_reporting(E_ALL);
26    
27 rda 284 $g_user = isset($_GET['user']) ? htmlentities(strip_tags($_GET['user'])) : null;
28    
29 rda 283 $upload_dir = '/home/schedbot/uploads';
30 pterjan 268 $max_modified = 2;
31 rda 283 $title = '<a href="http://mageia.org/">Mageia</a> build system status';
32 rda 284 $robots = 'index,nofollow,nosnippet,noarchive';
33     if ($g_user) {
34     $title .= ' for ' . $g_user . "'s packages";
35     $robots = 'no' . $robots;
36     }
37 rda 283 $tz = new DateTimeZone('UTC');
38 rda 292 $date_gen = date('c');
39 pterjan 268
40 pterjan 269 # Temporary until initial mirror is ready
41 pterjan 270 chdir("data");
42 pterjan 269 $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 pterjan 268 chdir($upload_dir);
48    
49 pterjan 313 $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 rda 301 $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 pterjan 268
56     $pkgs = array();
57     foreach ($matches as $val) {
58 rda 283
59     if ($_GET['user'] && ($_GET['user'] != $val[7])) {
60     continue;
61 pterjan 269 }
62     $key = $val[6] . $val[7];
63 pterjan 268 if (!is_array($pkgs[$key])) {
64 rda 283
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 pterjan 268 }
76    
77     $status = $val[1];
78     $data = $val[10];
79 rda 283 $pkgs[$key]['status'][$status] = 1;
80 pterjan 268 $ext = $val[11];
81 rda 283 if ($ext == '.src.rpm.info') {
82 pterjan 268 preg_match("!^(?:@\d+:)?(.*)!", $data, $name);
83 rda 283 $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 pterjan 268 // parse build bot from $data
90 rda 283 $pkgs[$key]['status']['build'] = 1;
91 rda 301 } else if ($ext == '.done') {
92 pterjan 313 $pkgs[$key]['buildtime']['start'] = key2timestamp($val[6]);
93 rda 301 $pkgs[$key]['buildtime']['end'] = round($val[12]);
94     $pkgs[$key]['buildtime']['diff'] = $pkgs[$key]['buildtime']['end'] - $pkgs[$key]['buildtime']['start'];
95 pterjan 268 }
96     }
97     // sort by key in reverse order to have more recent pkgs first
98     krsort($pkgs);
99 rda 283
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 pterjan 313 * 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 rda 301 * Return human-readable time difference:
155     * - against $key (YmdHis expected format)
156     * - using only $diff (takes precedence over $key if provided)
157 rda 283 *
158 rda 301 * @param string $key past date to diff against from now
159     * @param integer $diff time difference in seconds
160     *
161 rda 283 * @return string
162     */
163 rda 301 global $tz;
164    
165     if (is_null($diff) || $diff <= 0) {
166 pterjan 313 $t = key2timestamp($key);
167     if (is_null($t))
168 rda 301 return null;
169    
170 pterjan 313 $diff = time() - $t;
171 rda 301 }
172 rda 283 if ($diff<60)
173 rda 301 return $diff . " second" . plural($diff);
174 rda 283 $diff = round($diff/60);
175     if ($diff<60)
176 rda 301 return $diff . " minute" . plural($diff);
177 rda 283 $diff = round($diff/60);
178     if ($diff<24)
179 rda 301 return $diff . " hour" . plural($diff);
180 rda 283 $diff = round($diff/24);
181    
182 rda 301 return $diff . " day" . plural($diff);
183 rda 283 }
184 rda 301
185 pterjan 268 ?>
186 rda 284 <!DOCTYPE html>
187 rda 281 <html lang="en">
188 pterjan 268 <head>
189 rda 284 <meta charset="utf-8">
190 rda 290 <title><?php echo strip_tags($title); ?></title>
191 rda 284 <meta name="robots" content="<?php echo $robots; ?>">
192     <style type="text/css">
193 rda 288 .clear { clear: both; }
194 rda 281 table {
195     border-spacing: 0;
196 rda 293 font-family: Helvetica, Verdana, Arial, sans-serif; font-size: 80%;
197 rda 281 border: 1px solid #ccc;
198 rda 288 float: left;
199 rda 281 }
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 pterjan 269
204 rda 281 tr { background: transparent; }
205 rda 282 tr.uploaded { background: #bbffbb; }
206     tr.failure, tr.rejected { background: #ffbbbb; }
207 rda 281 tr.todo { background: white; }
208 rda 282 tr.building { background: #ffff99; }
209     tr.partial { background: #bbbbff; }
210     tr.built { background: #cceeff; }
211     tr.youri { background: #aacc66; }
212 rda 281
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 rda 282 tr.built td.status-box { background: #00ccff; }
220 rda 281 tr.youri td.status-box { background: olive; }
221 rda 285
222     #stats { float: right; }
223 rda 293 #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 rda 284 </style>
227 pterjan 268 </head>
228     <body>
229 rda 281 <h1><?php echo $title ?></h1>
230 pterjan 268
231 rda 281 <?php
232 rda 289 if (!is_null($g_user))
233     echo '<a href="/">&laquo;&nbsp;Back to full list</a>';
234 pterjan 268
235 pterjan 269 # Temporary until initial mirror is ready
236 rda 281 echo sprintf(
237     '<p><a href="%s">%d src.rpm</a> rebuilt for Mageia out of <a href="%s">%d</a>
238 rda 283 (<a href="%s">list of Mandriva packages still present</a>).</p>',
239 rda 281
240     'data/src.mga.txt', $nb_rpm_mga,
241     'data/src.txt', $nb_rpm,
242     'data/src.mdv.txt'
243     );
244    
245 pterjan 269 #########################################
246    
247 rda 283 $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 rda 285
258 rda 286 // count all packages statuses
259 rda 285 $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 rda 286
269 rda 299 // count users' packages
270     $users = array();
271    
272 rda 286 // 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 rda 292 if ($total > 0) {
283     foreach ($pkgs as $key => $p) {
284     $p['type'] = pkg_gettype($p);
285 rda 283
286 rda 292 $stats[$p['type']] += 1;
287 rda 299
288     if (!array_key_exists($p['user'], $users))
289     $users[$p['user']] = 1;
290     else
291     $users[$p['user']] += 1;
292    
293 rda 292 $s .= sprintf($tmpl,
294     $p['type'],
295 rda 301 key2date($key) . ' ago',
296 rda 292 $p['user'], $p['user'],
297     $p['package'],
298     $p['version'],
299     $p['media'], $p['section']
300     );
301 rda 283
302 rda 292 $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 rda 301 $s .= '</td><td>';
315     if ($p['type'] == 'uploaded')
316 rda 303 $s .= key2date(null, $p['buildtime']['diff']);
317 rda 292 $s .= '</td>';
318     //$s .= '<td>' . sprintf($badges[$p['type']], $p['user']) . '</td>';
319     $s .= '</tr>';
320 pterjan 268 }
321 rda 292 // 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 rda 283
328 rda 292 // 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 rda 283
335 rda 292 $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 rda 299
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 rda 292 echo $s;
352 pterjan 268 }
353 rda 292 else
354     {
355     echo sprintf('<p>No package has been submitted in the past %d&nbsp;hours.</p>',
356     $max_modified * 24);
357 rda 285 }
358    
359 pterjan 268 ?>
360 rda 292 <div class="clear"></div>
361     <hr />
362     <p>Generated at <?php echo $date_gen; ?>.</p>
363 pterjan 268 </body>
364     </html>

  ViewVC Help
Powered by ViewVC 1.1.30