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

Contents of /build_system/web/index.php

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.30