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

Contents of /build_system/web/index.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 292 - (show annotations) (download)
Thu Jan 13 17:13:01 2011 UTC (13 years, 2 months ago) by rda
File size: 8839 byte(s)
properly handle empty queue; remove feedback labels; try a "score" for this list of packages
1 <?php
2
3 /* Copyright (C) 2011 Oliver Blin *\
4 /**************************************************************************\
5 * This program is free software; you can redistribute it and/or modify it *
6 * under the terms of the GNU General Public License aspublished by the *
7 * Free Software Foundation; either version 2 of the License, or (at your *
8 * option) any later version. *
9 \**************************************************************************/
10
11 error_reporting(E_ALL);
12
13 $g_user = isset($_GET['user']) ? htmlentities(strip_tags($_GET['user'])) : null;
14
15 $upload_dir = '/home/schedbot/uploads';
16 $max_modified = 2;
17 $title = '<a href="http://mageia.org/">Mageia</a> build system status';
18 $robots = 'index,nofollow,nosnippet,noarchive';
19 if ($g_user) {
20 $title .= ' for ' . $g_user . "'s packages";
21 $robots = 'no' . $robots;
22 }
23 $tz = new DateTimeZone('UTC');
24 $date_gen = date('c');
25
26 # Temporary until initial mirror is ready
27 chdir("data");
28 $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');
29 $nb_rpm_mga = shell_exec('grep mga src.txt | tee src.mga.txt | wc -l');
30 shell_exec('grep -v mga src.txt > src.mdv.txt');
31 #########################################
32
33 chdir($upload_dir);
34
35 $all_files = shell_exec("find \( -name '*.rpm' -o -name '*.src.rpm.info' -o -name '*.youri' -o -name '*.lock' -o -name '*.done' \) ! -ctime $max_modified");
36
37 preg_match_all("!^\./(\w+)/((\w+)/(\w+)/(\w+)/(\d+)\.(\w+)\.(\w+)\.(\d+))_?(.+)(\.src\.rpm(?:\.info)?|\.youri|\.lock|\.done)$!m", $all_files, $matches, PREG_SET_ORDER);
38
39 $pkgs = array();
40 foreach ($matches as $val) {
41
42 if ($_GET['user'] && ($_GET['user'] != $val[7])) {
43 continue;
44 }
45 $key = $val[6] . $val[7];
46 if (!is_array($pkgs[$key])) {
47
48 $pkgs[$key] = array(
49 'status' => array(),
50 'path' => $val[2],
51 'version' => $val[3],
52 'media' => $val[4],
53 'section' => $val[5],
54 'user' => $val[7],
55 'host' => $val[8],
56 'job' => $val[9]
57 );
58 }
59
60 $status = $val[1];
61 $data = $val[10];
62 $pkgs[$key]['status'][$status] = 1;
63 $ext = $val[11];
64 if ($ext == '.src.rpm.info') {
65 preg_match("!^(?:@\d+:)?(.*)!", $data, $name);
66 $pkgs[$key]['package'] = $name[1];
67 } else if ($ext == '.src') {
68 $pkgs[$key]['status']['src'] = 1;
69 } else if ($ext == '.youri') {
70 $pkgs[$key]['status']['youri'] = 1;
71 } else if ($ext == '.lock') {
72 // parse build bot from $data
73 $pkgs[$key]['status']['build'] = 1;
74 }
75 }
76 // sort by key in reverse order to have more recent pkgs first
77 krsort($pkgs);
78
79 /**
80 * @param array $pkg
81 *
82 * @return string
83 */
84 function pkg_gettype($pkg) {
85 if (array_key_exists("rejected", $pkg["status"]))
86 return "rejected";
87 if (array_key_exists("youri", $pkg["status"])) {
88 if (array_key_exists("src", $pkg["status"]))
89 return "youri";
90 else
91 return "uploaded";
92 }
93 if (array_key_exists("failure", $pkg["status"]))
94 return "failure";
95 if (array_key_exists("done", $pkg["status"]))
96 return "partial";
97 if (array_key_exists("build", $pkg["status"]))
98 return "building";
99 if (array_key_exists("todo", $pkg["status"]))
100 return "todo";
101 return "unknown";
102 }
103
104 /**
105 * @param integer $num
106 *
107 * @return string
108 */
109 function plural($num) {
110 if ($num > 1)
111 return "s";
112 }
113
114 /**
115 * @param string $key
116 *
117 * @return string
118 */
119 function key2date($key) {
120 global $tz;
121 $date = DateTime::createFromFormat("YmdHis", $key+0, $tz);
122 $diff = time() - $date->getTimestamp();
123 if ($diff<60)
124 return $diff . " second" . plural($diff) . " ago";
125 $diff = round($diff/60);
126 if ($diff<60)
127 return $diff . " minute" . plural($diff) . " ago";
128 $diff = round($diff/60);
129 if ($diff<24)
130 return $diff . " hour" . plural($diff) . " ago";
131 $diff = round($diff/24);
132
133 return $diff . " day" . plural($diff) . " ago";
134 }
135 ?>
136 <!DOCTYPE html>
137 <html lang="en">
138 <head>
139 <meta charset="utf-8">
140 <title><?php echo strip_tags($title); ?></title>
141 <meta name="robots" content="<?php echo $robots; ?>">
142 <style type="text/css">
143 .clear { clear: both; }
144 table {
145 border-spacing: 0;
146 font-family: Helvetica; font-size: 80%;
147 border: 1px solid #ccc;
148 float: left;
149 }
150 table tr { padding: 0; margin: 0; }
151 table th { padding: 0.2em 0.5em; margin: 0; border-bottom: 2px solid #ccc; border-right: 1px solid #ccc; }
152 table td { padding: 0; margin: 0; padding: 0.2em 0.5em; border-bottom: 1px solid #ccc; }
153
154 tr { background: transparent; }
155 tr.uploaded { background: #bbffbb; }
156 tr.failure, tr.rejected { background: #ffbbbb; }
157 tr.todo { background: white; }
158 tr.building { background: #ffff99; }
159 tr.partial { background: #bbbbff; }
160 tr.built { background: #cceeff; }
161 tr.youri { background: #aacc66; }
162
163 td.status-box { width: 1em; height: 1em; }
164 tr.uploaded td.status-box { background: green; }
165 tr.failure td.status-box, tr.rejected td.status-box { background: red; }
166 tr.todo td.status-box { background: white; }
167 tr.building td.status-box { background: yellow; }
168 tr.partial td.status-box { background: blue; }
169 tr.built td.status-box { background: #00ccff; }
170 tr.youri td.status-box { background: olive; }
171
172 #stats { float: right; }
173 #score {}
174 #score-box { width: 200px; height: 100px; background: #faa; }
175 #score-meter { width: 200px; background: #afa; }
176 </style>
177 </head>
178 <body>
179 <h1><?php echo $title ?></h1>
180
181 <?php
182 if (!is_null($g_user))
183 echo '<a href="/">&laquo;&nbsp;Back to full list</a>';
184
185 # Temporary until initial mirror is ready
186 echo sprintf(
187 '<p><a href="%s">%d src.rpm</a> rebuilt for Mageia out of <a href="%s">%d</a>
188 (<a href="%s">list of Mandriva packages still present</a>).</p>',
189
190 'data/src.mga.txt', $nb_rpm_mga,
191 'data/src.txt', $nb_rpm,
192 'data/src.mdv.txt'
193 );
194
195 #########################################
196
197 $s = '';
198 $tmpl = <<<T
199 <tr class="%s">
200 <td>%s</td>
201 <td><a href="?user=%s">%s</a></td>
202 <td>%s</td>
203 <td>%s</td>
204 <td>%s/%s</td>
205 <td class="status-box"></td>
206 T;
207
208 // count all packages statuses
209 $stats = array(
210 'uploaded' => 0,
211 'failure' => 0,
212 'todo' => 0,
213 'building' => 0,
214 'partial' => 0,
215 'built' => 0,
216 );
217 $total = count($pkgs);
218
219 // feedback labels
220 $badges = array(
221 'uploaded' => 'Congrats %s! \o/',
222 'failure' => 'Booooo! /o\\',
223 'todo' => '',
224 'building' => '',
225 'partial' => '',
226 'built' => ''
227 );
228
229 if ($total > 0) {
230 foreach ($pkgs as $key => $p) {
231 $p['type'] = pkg_gettype($p);
232
233 $stats[$p['type']] += 1;
234 $s .= sprintf($tmpl,
235 $p['type'],
236 key2date($key),
237 $p['user'], $p['user'],
238 $p['package'],
239 $p['version'],
240 $p['media'], $p['section']
241 );
242
243 $typelink = '';
244 if ($p['type'] == 'failure') {
245 $typelink = '/uploads/' . $p['type'] . '/' . $p['path'];
246 } elseif ($p['type'] == 'rejected') {
247 $typelink = '/uploads/' . $p['type'] . '/' . $p['path'] . '.youri';
248 }
249
250 $s .= '<td>';
251 $s .= ($typelink != '') ?
252 sprintf('<a href="%s">%s</a>', $typelink, $p['type']) :
253 $p['type'];
254
255 $s .= '</td>';
256 //$s .= '<td>' . sprintf($badges[$p['type']], $p['user']) . '</td>';
257 $s .= '</tr>';
258 }
259 // Table
260 echo '<table>',
261 '<caption>Packages submitted in the past ', $max_modified * 24, '&nbsp;hours.</caption>',
262 '<tr><th>Submitted</th><th>User</th><th>Package</th><th>Target</th><th>Media</th><th colspan="2">Status</th></tr>',
263 $s,
264 '</table>';
265
266 // Stats
267 $s = '<div id="stats">';
268 $score = round($stats['uploaded']/$total * 100);
269 $s .= sprintf('<div id="score"><h3>Score: %d/100</h3>
270 <div id="score-box"><div id="score-meter" style="height: %dpx;"></div></div></div>',
271 $score, $score);
272
273 $s .= '<table><caption>Stats.</caption><tr><th colspan="2">Status</th><th>Count</th><th>%</th></tr>';
274 foreach ($stats as $k => $v) {
275 $s .= sprintf('<tr class="%s"><td class="status-box"></td><td>%s</td><td>%d</td><td>%d%%</td></tr>',
276 $k, $k, $v, round($v/$total*100));
277 }
278 $s .= '</table></div>';
279 echo $s;
280 }
281 else
282 {
283 echo sprintf('<p>No package has been submitted in the past %d&nbsp;hours.</p>',
284 $max_modified * 24);
285 }
286
287 ?>
288 <div class="clear"></div>
289 <hr />
290 <p>Generated at <?php echo $date_gen; ?>.</p>
291 </body>
292 </html>

  ViewVC Help
Powered by ViewVC 1.1.30