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

Annotation of /build_system/web/index.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 315 - (hide annotations) (download)
Tue Jan 18 12:56:36 2011 UTC (13 years, 3 months ago) by pterjan
File size: 10454 byte(s)
Fix param name
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 pterjan 315 function timediff($start, $end) {
153 pterjan 313 /**
154 pterjan 314 * Return human-readable time difference
155 rda 283 *
156 pterjan 314 * @param integer $start timestamp
157     * @param integer $end timestamp, defaults to now
158 rda 301 *
159 rda 283 * @return string
160     */
161 pterjan 314 if (is_null($end)) {
162     $end = time();
163 rda 301 }
164 pterjan 314 $diff = $end - $start;
165 rda 283 if ($diff<60)
166 rda 301 return $diff . " second" . plural($diff);
167 rda 283 $diff = round($diff/60);
168     if ($diff<60)
169 rda 301 return $diff . " minute" . plural($diff);
170 rda 283 $diff = round($diff/60);
171     if ($diff<24)
172 rda 301 return $diff . " hour" . plural($diff);
173 rda 283 $diff = round($diff/24);
174    
175 rda 301 return $diff . " day" . plural($diff);
176 rda 283 }
177 rda 301
178 pterjan 268 ?>
179 rda 284 <!DOCTYPE html>
180 rda 281 <html lang="en">
181 pterjan 268 <head>
182 rda 284 <meta charset="utf-8">
183 rda 290 <title><?php echo strip_tags($title); ?></title>
184 rda 284 <meta name="robots" content="<?php echo $robots; ?>">
185     <style type="text/css">
186 rda 288 .clear { clear: both; }
187 rda 281 table {
188     border-spacing: 0;
189 rda 293 font-family: Helvetica, Verdana, Arial, sans-serif; font-size: 80%;
190 rda 281 border: 1px solid #ccc;
191 rda 288 float: left;
192 rda 281 }
193     table tr { padding: 0; margin: 0; }
194     table th { padding: 0.2em 0.5em; margin: 0; border-bottom: 2px solid #ccc; border-right: 1px solid #ccc; }
195     table td { padding: 0; margin: 0; padding: 0.2em 0.5em; border-bottom: 1px solid #ccc; }
196 pterjan 269
197 rda 281 tr { background: transparent; }
198 rda 282 tr.uploaded { background: #bbffbb; }
199     tr.failure, tr.rejected { background: #ffbbbb; }
200 rda 281 tr.todo { background: white; }
201 rda 282 tr.building { background: #ffff99; }
202     tr.partial { background: #bbbbff; }
203     tr.built { background: #cceeff; }
204     tr.youri { background: #aacc66; }
205 rda 281
206     td.status-box { width: 1em; height: 1em; }
207     tr.uploaded td.status-box { background: green; }
208     tr.failure td.status-box, tr.rejected td.status-box { background: red; }
209     tr.todo td.status-box { background: white; }
210     tr.building td.status-box { background: yellow; }
211     tr.partial td.status-box { background: blue; }
212 rda 282 tr.built td.status-box { background: #00ccff; }
213 rda 281 tr.youri td.status-box { background: olive; }
214 rda 285
215     #stats { float: right; }
216 rda 293 #score { margin-bottom: 2em; font-family: Helvetica, Verdana, Arial, sans-serif; }
217     #score-box { width: 100px; height: 100px; background: #faa; }
218     #score-meter { width: 100px; background: #afa; }
219 rda 284 </style>
220 pterjan 268 </head>
221     <body>
222 rda 281 <h1><?php echo $title ?></h1>
223 pterjan 268
224 rda 281 <?php
225 rda 289 if (!is_null($g_user))
226     echo '<a href="/">&laquo;&nbsp;Back to full list</a>';
227 pterjan 268
228 pterjan 269 # Temporary until initial mirror is ready
229 rda 281 echo sprintf(
230     '<p><a href="%s">%d src.rpm</a> rebuilt for Mageia out of <a href="%s">%d</a>
231 rda 283 (<a href="%s">list of Mandriva packages still present</a>).</p>',
232 rda 281
233     'data/src.mga.txt', $nb_rpm_mga,
234     'data/src.txt', $nb_rpm,
235     'data/src.mdv.txt'
236     );
237    
238 pterjan 269 #########################################
239    
240 rda 283 $s = '';
241     $tmpl = <<<T
242     <tr class="%s">
243     <td>%s</td>
244     <td><a href="?user=%s">%s</a></td>
245     <td>%s</td>
246     <td>%s</td>
247     <td>%s/%s</td>
248     <td class="status-box"></td>
249     T;
250 rda 285
251 rda 286 // count all packages statuses
252 rda 285 $stats = array(
253     'uploaded' => 0,
254     'failure' => 0,
255     'todo' => 0,
256     'building' => 0,
257     'partial' => 0,
258     'built' => 0,
259     );
260     $total = count($pkgs);
261 rda 286
262 rda 299 // count users' packages
263     $users = array();
264    
265 rda 286 // feedback labels
266     $badges = array(
267     'uploaded' => 'Congrats %s! \o/',
268     'failure' => 'Booooo! /o\\',
269     'todo' => '',
270     'building' => '',
271     'partial' => '',
272     'built' => ''
273     );
274    
275 rda 292 if ($total > 0) {
276     foreach ($pkgs as $key => $p) {
277     $p['type'] = pkg_gettype($p);
278 rda 283
279 rda 292 $stats[$p['type']] += 1;
280 rda 299
281     if (!array_key_exists($p['user'], $users))
282     $users[$p['user']] = 1;
283     else
284     $users[$p['user']] += 1;
285    
286 rda 292 $s .= sprintf($tmpl,
287     $p['type'],
288 pterjan 314 timediff(key2timestamp($key)) . ' ago',
289 rda 292 $p['user'], $p['user'],
290     $p['package'],
291     $p['version'],
292     $p['media'], $p['section']
293     );
294 rda 283
295 rda 292 $typelink = '';
296     if ($p['type'] == 'failure') {
297     $typelink = '/uploads/' . $p['type'] . '/' . $p['path'];
298     } elseif ($p['type'] == 'rejected') {
299     $typelink = '/uploads/' . $p['type'] . '/' . $p['path'] . '.youri';
300     }
301    
302     $s .= '<td>';
303     $s .= ($typelink != '') ?
304     sprintf('<a href="%s">%s</a>', $typelink, $p['type']) :
305     $p['type'];
306    
307 rda 301 $s .= '</td><td>';
308     if ($p['type'] == 'uploaded')
309 pterjan 314 $s .= timediff($p['buildtime']['start'], $p['buildtime']['end']);
310 rda 292 $s .= '</td>';
311     //$s .= '<td>' . sprintf($badges[$p['type']], $p['user']) . '</td>';
312     $s .= '</tr>';
313 pterjan 268 }
314 rda 292 // Table
315     echo '<table>',
316     '<caption>Packages submitted in the past ', $max_modified * 24, '&nbsp;hours.</caption>',
317     '<tr><th>Submitted</th><th>User</th><th>Package</th><th>Target</th><th>Media</th><th colspan="2">Status</th></tr>',
318     $s,
319     '</table>';
320 rda 283
321 rda 292 // Stats
322     $s = '<div id="stats">';
323     $score = round($stats['uploaded']/$total * 100);
324     $s .= sprintf('<div id="score"><h3>Score: %d/100</h3>
325     <div id="score-box"><div id="score-meter" style="height: %dpx;"></div></div></div>',
326     $score, $score);
327 rda 283
328 rda 292 $s .= '<table><caption>Stats.</caption><tr><th colspan="2">Status</th><th>Count</th><th>%</th></tr>';
329     foreach ($stats as $k => $v) {
330     $s .= sprintf('<tr class="%s"><td class="status-box"></td><td>%s</td><td>%d</td><td>%d%%</td></tr>',
331     $k, $k, $v, round($v/$total*100));
332     }
333 rda 299
334     $s .= '</table><br />';
335    
336     $s .= '<table><caption>Packagers</caption><tr><th>User</th><th>Packages</th></tr>';
337     foreach ($users as $k => $v)
338     $s .= sprintf('<tr><td><a href="/?user=%s">%s</a></td><td>%d</td></tr>',
339     $k, $k, $v);
340    
341     $s .= '</table>';
342     $s .= '</div>';
343    
344 rda 292 echo $s;
345 pterjan 268 }
346 rda 292 else
347     {
348     echo sprintf('<p>No package has been submitted in the past %d&nbsp;hours.</p>',
349     $max_modified * 24);
350 rda 285 }
351    
352 pterjan 268 ?>
353 rda 292 <div class="clear"></div>
354     <hr />
355     <p>Generated at <?php echo $date_gen; ?>.</p>
356 pterjan 268 </body>
357     </html>

  ViewVC Help
Powered by ViewVC 1.1.30