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

Annotation of /build_system/web/index.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 288 - (hide annotations) (download)
Thu Jan 13 15:48:16 2011 UTC (13 years, 3 months ago) by rda
File size: 7888 byte(s)
move feedback string at the end of the line; show stats on top
1 pterjan 268 <?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 rda 284 $g_user = isset($_GET['user']) ? htmlentities(strip_tags($_GET['user'])) : null;
14    
15 rda 283 $upload_dir = '/home/schedbot/uploads';
16 pterjan 268 $max_modified = 2;
17 rda 283 $title = '<a href="http://mageia.org/">Mageia</a> build system status';
18 rda 284 $robots = 'index,nofollow,nosnippet,noarchive';
19     if ($g_user) {
20     $title .= ' for ' . $g_user . "'s packages";
21     $robots = 'no' . $robots;
22     }
23 rda 283 $tz = new DateTimeZone('UTC');
24 pterjan 268
25 pterjan 269 # Temporary until initial mirror is ready
26 pterjan 270 chdir("data");
27 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');
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 pterjan 268 chdir($upload_dir);
33    
34 pterjan 269 $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 pterjan 268
36 pterjan 269 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 pterjan 268 $pkgs = array();
39     foreach ($matches as $val) {
40 rda 283
41     if ($_GET['user'] && ($_GET['user'] != $val[7])) {
42     continue;
43 pterjan 269 }
44     $key = $val[6] . $val[7];
45 pterjan 268 if (!is_array($pkgs[$key])) {
46 rda 283
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 pterjan 268 }
58    
59     $status = $val[1];
60     $data = $val[10];
61 rda 283 $pkgs[$key]['status'][$status] = 1;
62 pterjan 268 $ext = $val[11];
63 rda 283 if ($ext == '.src.rpm.info') {
64 pterjan 268 preg_match("!^(?:@\d+:)?(.*)!", $data, $name);
65 rda 283 $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 pterjan 268 // parse build bot from $data
72 rda 283 $pkgs[$key]['status']['build'] = 1;
73 pterjan 268 }
74     }
75     // sort by key in reverse order to have more recent pkgs first
76     krsort($pkgs);
77 rda 283
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 pterjan 268 ?>
135 rda 284 <!DOCTYPE html>
136 rda 281 <html lang="en">
137 pterjan 268 <head>
138 rda 284 <meta charset="utf-8">
139     <title><?php echo $title ?></title>
140     <meta name="robots" content="<?php echo $robots; ?>">
141     <style type="text/css">
142 rda 288 .clear { clear: both; }
143 rda 281 table {
144     border-spacing: 0;
145     font-family: Helvetica; font-size: 80%;
146     border: 1px solid #ccc;
147 rda 288 float: left;
148 rda 281 }
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 pterjan 269
153 rda 281 tr { background: transparent; }
154 rda 282 tr.uploaded { background: #bbffbb; }
155     tr.failure, tr.rejected { background: #ffbbbb; }
156 rda 281 tr.todo { background: white; }
157 rda 282 tr.building { background: #ffff99; }
158     tr.partial { background: #bbbbff; }
159     tr.built { background: #cceeff; }
160     tr.youri { background: #aacc66; }
161 rda 281
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 rda 282 tr.built td.status-box { background: #00ccff; }
169 rda 281 tr.youri td.status-box { background: olive; }
170 rda 285
171     #stats { float: right; }
172 rda 284 </style>
173 pterjan 268 </head>
174     <body>
175 rda 281 <h1><?php echo $title ?></h1>
176 pterjan 268
177 rda 281 <?php
178 pterjan 268
179 pterjan 269 # Temporary until initial mirror is ready
180 rda 281 echo sprintf(
181     '<p><a href="%s">%d src.rpm</a> rebuilt for Mageia out of <a href="%s">%d</a>
182 rda 283 (<a href="%s">list of Mandriva packages still present</a>).</p>',
183 rda 281
184     'data/src.mga.txt', $nb_rpm_mga,
185     'data/src.txt', $nb_rpm,
186     'data/src.mdv.txt'
187     );
188    
189 pterjan 269 #########################################
190 rda 281 echo '<table>',
191 rda 287 '<caption>Packages submitted in the past ', $max_modified * 24, '&nbsp;hours.</caption>',
192 rda 281 '<tr><th>Submitted</th><th>User</th><th>Package</th><th>Target</th><th>Media</th><th colspan="2">Status</th></tr>';
193 pterjan 269
194 rda 283 $s = '';
195     $tmpl = <<<T
196     <tr class="%s">
197     <td>%s</td>
198     <td><a href="?user=%s">%s</a></td>
199     <td>%s</td>
200     <td>%s</td>
201     <td>%s/%s</td>
202     <td class="status-box"></td>
203     T;
204 rda 285
205 rda 286 // count all packages statuses
206 rda 285 $stats = array(
207     'uploaded' => 0,
208     'failure' => 0,
209     'todo' => 0,
210     'building' => 0,
211     'partial' => 0,
212     'built' => 0,
213     );
214     $total = count($pkgs);
215 rda 286
216     // feedback labels
217     $badges = array(
218     'uploaded' => 'Congrats %s! \o/',
219     'failure' => 'Booooo! /o\\',
220     'todo' => '',
221     'building' => '',
222     'partial' => '',
223     'built' => ''
224     );
225    
226 pterjan 268 foreach ($pkgs as $key => $p) {
227 rda 283 $p['type'] = pkg_gettype($p);
228    
229 rda 285 $stats[$p['type']] += 1;
230 rda 283 $s .= sprintf($tmpl,
231     $p['type'],
232     key2date($key),
233     $p['user'], $p['user'],
234     $p['package'],
235     $p['version'],
236 rda 288 $p['media'], $p['section']
237 rda 283 );
238    
239     $typelink = '';
240     if ($p['type'] == 'failure') {
241     $typelink = '/uploads/' . $p['type'] . '/' . $p['path'];
242     } elseif ($p['type'] == 'rejected') {
243     $typelink = '/uploads/' . $p['type'] . '/' . $p['path'] . '.youri';
244 pterjan 268 }
245 rda 283
246     $s .= '<td>';
247     $s .= ($typelink != '') ?
248     sprintf('<a href="%s">%s</a>', $typelink, $p['type']) :
249     $p['type'];
250    
251 rda 288 $s .= '</td>';
252     $s .= '<td>' . sprintf($badges[$p['type']], $p['user']) . '</td>';
253     $s .= '</tr>';
254 pterjan 268 }
255 rda 285 echo $s, '</table>';
256    
257     $s = '<div id="stats"><table><tr><th>Status</th><th>Count</th><th>%</th></tr>';
258     foreach ($stats as $k => $v) {
259     $s .= sprintf('<tr><th>%s</th><td>%d</td><td>%d%%</td></tr>',
260     $k, $v, round($v/$total*100));
261     }
262     $s .= '</table></div>';
263 rda 288 $s .= '<div class="clear"></div>';
264 rda 285
265 rda 283 echo $s;
266 rda 285
267 pterjan 268 ?>
268     </body>
269     </html>

  ViewVC Help
Powered by ViewVC 1.1.30