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

Contents of /build_system/web/index.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 299 - (show annotations) (download)
Fri Jan 14 15:03:40 2011 UTC (13 years, 3 months ago) by rda
File size: 9620 byte(s)
show users packages count
1 <?php
2 /**
3 * Mageia build-system quick status report script.
4 *
5 * @copyright Copyright (C) 2011 Oliver 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");
50
51 preg_match_all("!^\./(\w+)/((\w+)/(\w+)/(\w+)/(\d+)\.(\w+)\.(\w+)\.(\d+))_?(.+)(\.src\.rpm(?:\.info)?|\.youri|\.lock|\.done)$!m", $all_files, $matches, PREG_SET_ORDER);
52
53 $pkgs = array();
54 foreach ($matches as $val) {
55
56 if ($_GET['user'] && ($_GET['user'] != $val[7])) {
57 continue;
58 }
59 $key = $val[6] . $val[7];
60 if (!is_array($pkgs[$key])) {
61
62 $pkgs[$key] = array(
63 'status' => array(),
64 'path' => $val[2],
65 'version' => $val[3],
66 'media' => $val[4],
67 'section' => $val[5],
68 'user' => $val[7],
69 'host' => $val[8],
70 'job' => $val[9]
71 );
72 }
73
74 $status = $val[1];
75 $data = $val[10];
76 $pkgs[$key]['status'][$status] = 1;
77 $ext = $val[11];
78 if ($ext == '.src.rpm.info') {
79 preg_match("!^(?:@\d+:)?(.*)!", $data, $name);
80 $pkgs[$key]['package'] = $name[1];
81 } else if ($ext == '.src') {
82 $pkgs[$key]['status']['src'] = 1;
83 } else if ($ext == '.youri') {
84 $pkgs[$key]['status']['youri'] = 1;
85 } else if ($ext == '.lock') {
86 // parse build bot from $data
87 $pkgs[$key]['status']['build'] = 1;
88 }
89 }
90 // sort by key in reverse order to have more recent pkgs first
91 krsort($pkgs);
92
93 /**
94 * @param array $pkg
95 *
96 * @return string
97 */
98 function pkg_gettype($pkg) {
99 if (array_key_exists("rejected", $pkg["status"]))
100 return "rejected";
101 if (array_key_exists("youri", $pkg["status"])) {
102 if (array_key_exists("src", $pkg["status"]))
103 return "youri";
104 else
105 return "uploaded";
106 }
107 if (array_key_exists("failure", $pkg["status"]))
108 return "failure";
109 if (array_key_exists("done", $pkg["status"]))
110 return "partial";
111 if (array_key_exists("build", $pkg["status"]))
112 return "building";
113 if (array_key_exists("todo", $pkg["status"]))
114 return "todo";
115 return "unknown";
116 }
117
118 /**
119 * @param integer $num
120 *
121 * @return string
122 */
123 function plural($num) {
124 if ($num > 1)
125 return "s";
126 }
127
128 /**
129 * @param string $key
130 *
131 * @return string
132 */
133 function key2date($key) {
134 global $tz;
135 $date = DateTime::createFromFormat("YmdHis", $key+0, $tz);
136 $diff = time() - $date->getTimestamp();
137 if ($diff<60)
138 return $diff . " second" . plural($diff) . " ago";
139 $diff = round($diff/60);
140 if ($diff<60)
141 return $diff . " minute" . plural($diff) . " ago";
142 $diff = round($diff/60);
143 if ($diff<24)
144 return $diff . " hour" . plural($diff) . " ago";
145 $diff = round($diff/24);
146
147 return $diff . " day" . plural($diff) . " ago";
148 }
149 ?>
150 <!DOCTYPE html>
151 <html lang="en">
152 <head>
153 <meta charset="utf-8">
154 <title><?php echo strip_tags($title); ?></title>
155 <meta name="robots" content="<?php echo $robots; ?>">
156 <style type="text/css">
157 .clear { clear: both; }
158 table {
159 border-spacing: 0;
160 font-family: Helvetica, Verdana, Arial, sans-serif; font-size: 80%;
161 border: 1px solid #ccc;
162 float: left;
163 }
164 table tr { padding: 0; margin: 0; }
165 table th { padding: 0.2em 0.5em; margin: 0; border-bottom: 2px solid #ccc; border-right: 1px solid #ccc; }
166 table td { padding: 0; margin: 0; padding: 0.2em 0.5em; border-bottom: 1px solid #ccc; }
167
168 tr { background: transparent; }
169 tr.uploaded { background: #bbffbb; }
170 tr.failure, tr.rejected { background: #ffbbbb; }
171 tr.todo { background: white; }
172 tr.building { background: #ffff99; }
173 tr.partial { background: #bbbbff; }
174 tr.built { background: #cceeff; }
175 tr.youri { background: #aacc66; }
176
177 td.status-box { width: 1em; height: 1em; }
178 tr.uploaded td.status-box { background: green; }
179 tr.failure td.status-box, tr.rejected td.status-box { background: red; }
180 tr.todo td.status-box { background: white; }
181 tr.building td.status-box { background: yellow; }
182 tr.partial td.status-box { background: blue; }
183 tr.built td.status-box { background: #00ccff; }
184 tr.youri td.status-box { background: olive; }
185
186 #stats { float: right; }
187 #score { margin-bottom: 2em; font-family: Helvetica, Verdana, Arial, sans-serif; }
188 #score-box { width: 100px; height: 100px; background: #faa; }
189 #score-meter { width: 100px; background: #afa; }
190 </style>
191 </head>
192 <body>
193 <h1><?php echo $title ?></h1>
194
195 <?php
196 if (!is_null($g_user))
197 echo '<a href="/">&laquo;&nbsp;Back to full list</a>';
198
199 # Temporary until initial mirror is ready
200 echo sprintf(
201 '<p><a href="%s">%d src.rpm</a> rebuilt for Mageia out of <a href="%s">%d</a>
202 (<a href="%s">list of Mandriva packages still present</a>).</p>',
203
204 'data/src.mga.txt', $nb_rpm_mga,
205 'data/src.txt', $nb_rpm,
206 'data/src.mdv.txt'
207 );
208
209 #########################################
210
211 $s = '';
212 $tmpl = <<<T
213 <tr class="%s">
214 <td>%s</td>
215 <td><a href="?user=%s">%s</a></td>
216 <td>%s</td>
217 <td>%s</td>
218 <td>%s/%s</td>
219 <td class="status-box"></td>
220 T;
221
222 // count all packages statuses
223 $stats = array(
224 'uploaded' => 0,
225 'failure' => 0,
226 'todo' => 0,
227 'building' => 0,
228 'partial' => 0,
229 'built' => 0,
230 );
231 $total = count($pkgs);
232
233 // count users' packages
234 $users = array();
235
236 // feedback labels
237 $badges = array(
238 'uploaded' => 'Congrats %s! \o/',
239 'failure' => 'Booooo! /o\\',
240 'todo' => '',
241 'building' => '',
242 'partial' => '',
243 'built' => ''
244 );
245
246 if ($total > 0) {
247 foreach ($pkgs as $key => $p) {
248 $p['type'] = pkg_gettype($p);
249
250 $stats[$p['type']] += 1;
251
252 if (!array_key_exists($p['user'], $users))
253 $users[$p['user']] = 1;
254 else
255 $users[$p['user']] += 1;
256
257 $s .= sprintf($tmpl,
258 $p['type'],
259 key2date($key),
260 $p['user'], $p['user'],
261 $p['package'],
262 $p['version'],
263 $p['media'], $p['section']
264 );
265
266 $typelink = '';
267 if ($p['type'] == 'failure') {
268 $typelink = '/uploads/' . $p['type'] . '/' . $p['path'];
269 } elseif ($p['type'] == 'rejected') {
270 $typelink = '/uploads/' . $p['type'] . '/' . $p['path'] . '.youri';
271 }
272
273 $s .= '<td>';
274 $s .= ($typelink != '') ?
275 sprintf('<a href="%s">%s</a>', $typelink, $p['type']) :
276 $p['type'];
277
278 $s .= '</td>';
279 //$s .= '<td>' . sprintf($badges[$p['type']], $p['user']) . '</td>';
280 $s .= '</tr>';
281 }
282 // Table
283 echo '<table>',
284 '<caption>Packages submitted in the past ', $max_modified * 24, '&nbsp;hours.</caption>',
285 '<tr><th>Submitted</th><th>User</th><th>Package</th><th>Target</th><th>Media</th><th colspan="2">Status</th></tr>',
286 $s,
287 '</table>';
288
289 // Stats
290 $s = '<div id="stats">';
291 $score = round($stats['uploaded']/$total * 100);
292 $s .= sprintf('<div id="score"><h3>Score: %d/100</h3>
293 <div id="score-box"><div id="score-meter" style="height: %dpx;"></div></div></div>',
294 $score, $score);
295
296 $s .= '<table><caption>Stats.</caption><tr><th colspan="2">Status</th><th>Count</th><th>%</th></tr>';
297 foreach ($stats as $k => $v) {
298 $s .= sprintf('<tr class="%s"><td class="status-box"></td><td>%s</td><td>%d</td><td>%d%%</td></tr>',
299 $k, $k, $v, round($v/$total*100));
300 }
301
302 $s .= '</table><br />';
303
304 $s .= '<table><caption>Packagers</caption><tr><th>User</th><th>Packages</th></tr>';
305 foreach ($users as $k => $v)
306 $s .= sprintf('<tr><td><a href="/?user=%s">%s</a></td><td>%d</td></tr>',
307 $k, $k, $v);
308
309 $s .= '</table>';
310 $s .= '</div>';
311
312 echo $s;
313 }
314 else
315 {
316 echo sprintf('<p>No package has been submitted in the past %d&nbsp;hours.</p>',
317 $max_modified * 24);
318 }
319
320 ?>
321 <div class="clear"></div>
322 <hr />
323 <p>Generated at <?php echo $date_gen; ?>.</p>
324 </body>
325 </html>

  ViewVC Help
Powered by ViewVC 1.1.30