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

Annotation of /build_system/web/index.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 283 - (hide annotations) (download)
Thu Jan 13 14:19:51 2011 UTC (13 years, 3 months ago) by rda
File size: 6567 byte(s)
use single quotes when possible; build string before echo()ing them
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 283 $upload_dir = '/home/schedbot/uploads';
14 pterjan 268 $max_modified = 2;
15 rda 283 $title = '<a href="http://mageia.org/">Mageia</a> build system status';
16     $tz = new DateTimeZone('UTC');
17 pterjan 268
18 pterjan 269 # Temporary until initial mirror is ready
19 pterjan 270 chdir("data");
20 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');
21     $nb_rpm_mga = shell_exec('grep mga src.txt | tee src.mga.txt | wc -l');
22     shell_exec('grep -v mga src.txt > src.mdv.txt');
23     #########################################
24    
25 pterjan 268 chdir($upload_dir);
26    
27 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");
28 pterjan 268
29 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);
30    
31 pterjan 268 $pkgs = array();
32     foreach ($matches as $val) {
33 rda 283
34     if ($_GET['user'] && ($_GET['user'] != $val[7])) {
35     continue;
36 pterjan 269 }
37     $key = $val[6] . $val[7];
38 pterjan 268 if (!is_array($pkgs[$key])) {
39 rda 283
40     $pkgs[$key] = array(
41     'status' => array(),
42     'path' => $val[2],
43     'version' => $val[3],
44     'media' => $val[4],
45     'section' => $val[5],
46     'user' => $val[7],
47     'host' => $val[8],
48     'job' => $val[9]
49     );
50 pterjan 268 }
51    
52     $status = $val[1];
53     $data = $val[10];
54 rda 283 $pkgs[$key]['status'][$status] = 1;
55 pterjan 268 $ext = $val[11];
56 rda 283 if ($ext == '.src.rpm.info') {
57 pterjan 268 preg_match("!^(?:@\d+:)?(.*)!", $data, $name);
58 rda 283 $pkgs[$key]['package'] = $name[1];
59     } else if ($ext == '.src') {
60     $pkgs[$key]['status']['src'] = 1;
61     } else if ($ext == '.youri') {
62     $pkgs[$key]['status']['youri'] = 1;
63     } else if ($ext == '.lock') {
64 pterjan 268 // parse build bot from $data
65 rda 283 $pkgs[$key]['status']['build'] = 1;
66 pterjan 268 }
67     }
68     // sort by key in reverse order to have more recent pkgs first
69     krsort($pkgs);
70 rda 283
71     /**
72     * @param array $pkg
73     *
74     * @return string
75     */
76     function pkg_gettype($pkg) {
77     if (array_key_exists("rejected", $pkg["status"]))
78     return "rejected";
79     if (array_key_exists("youri", $pkg["status"])) {
80     if (array_key_exists("src", $pkg["status"]))
81     return "youri";
82     else
83     return "uploaded";
84     }
85     if (array_key_exists("failure", $pkg["status"]))
86     return "failure";
87     if (array_key_exists("done", $pkg["status"]))
88     return "partial";
89     if (array_key_exists("build", $pkg["status"]))
90     return "building";
91     if (array_key_exists("todo", $pkg["status"]))
92     return "todo";
93     return "unknown";
94     }
95    
96     /**
97     * @param integer $num
98     *
99     * @return string
100     */
101     function plural($num) {
102     if ($num > 1)
103     return "s";
104     }
105    
106     /**
107     * @param string $key
108     *
109     * @return string
110     */
111     function key2date($key) {
112     global $tz;
113     $date = DateTime::createFromFormat("YmdHis", $key+0, $tz);
114     $diff = time() - $date->getTimestamp();
115     if ($diff<60)
116     return $diff . " second" . plural($diff) . " ago";
117     $diff = round($diff/60);
118     if ($diff<60)
119     return $diff . " minute" . plural($diff) . " ago";
120     $diff = round($diff/60);
121     if ($diff<24)
122     return $diff . " hour" . plural($diff) . " ago";
123     $diff = round($diff/24);
124    
125     return $diff . " day" . plural($diff) . " ago";
126     }
127 pterjan 268 ?>
128 rda 281 <html lang="en">
129 pterjan 268 <head>
130 rda 281 <title><?php echo $title ?></title>
131 pterjan 268 <style type="text/css">
132 rda 281 table {
133     border-spacing: 0;
134     font-family: Helvetica; font-size: 80%;
135     border: 1px solid #ccc;
136     }
137     table tr { padding: 0; margin: 0; }
138     table th { padding: 0.2em 0.5em; margin: 0; border-bottom: 2px solid #ccc; border-right: 1px solid #ccc; }
139     table td { padding: 0; margin: 0; padding: 0.2em 0.5em; border-bottom: 1px solid #ccc; }
140 pterjan 269
141 rda 281 tr { background: transparent; }
142 rda 282 tr.uploaded { background: #bbffbb; }
143     tr.failure, tr.rejected { background: #ffbbbb; }
144 rda 281 tr.todo { background: white; }
145 rda 282 tr.building { background: #ffff99; }
146     tr.partial { background: #bbbbff; }
147     tr.built { background: #cceeff; }
148     tr.youri { background: #aacc66; }
149 rda 281
150     td.status-box { width: 1em; height: 1em; }
151     tr.uploaded td.status-box { background: green; }
152     tr.failure td.status-box, tr.rejected td.status-box { background: red; }
153     tr.todo td.status-box { background: white; }
154     tr.building td.status-box { background: yellow; }
155     tr.partial td.status-box { background: blue; }
156 rda 282 tr.built td.status-box { background: #00ccff; }
157 rda 281 tr.youri td.status-box { background: olive; }
158 pterjan 268 </style>
159     </head>
160     <body>
161 rda 281 <h1><?php echo $title ?></h1>
162 pterjan 268
163 rda 281 <?php
164 pterjan 268
165 pterjan 269 # Temporary until initial mirror is ready
166 rda 281 echo sprintf(
167     '<p><a href="%s">%d src.rpm</a> rebuilt for Mageia out of <a href="%s">%d</a>
168 rda 283 (<a href="%s">list of Mandriva packages still present</a>).</p>',
169 rda 281
170     'data/src.mga.txt', $nb_rpm_mga,
171     'data/src.txt', $nb_rpm,
172     'data/src.mdv.txt'
173     );
174    
175 pterjan 269 #########################################
176 rda 281 echo '<table>',
177     '<tr><th>Submitted</th><th>User</th><th>Package</th><th>Target</th><th>Media</th><th colspan="2">Status</th></tr>';
178 pterjan 269
179 rda 283 $s = '';
180     $tmpl = <<<T
181     <tr class="%s">
182     <td>%s</td>
183     <td><a href="?user=%s">%s</a></td>
184     <td>%s</td>
185     <td>%s</td>
186     <td>%s/%s</td>
187     <td class="status-box"></td>
188     T;
189 pterjan 268 foreach ($pkgs as $key => $p) {
190 rda 283 $p['type'] = pkg_gettype($p);
191    
192     $s .= sprintf($tmpl,
193     $p['type'],
194     key2date($key),
195     $p['user'], $p['user'],
196     $p['package'],
197     $p['version'],
198     $p['media'], $p['section']
199     );
200    
201     $typelink = '';
202     if ($p['type'] == 'failure') {
203     $typelink = '/uploads/' . $p['type'] . '/' . $p['path'];
204     } elseif ($p['type'] == 'rejected') {
205     $typelink = '/uploads/' . $p['type'] . '/' . $p['path'] . '.youri';
206 pterjan 268 }
207 rda 283
208     $s .= '<td>';
209     $s .= ($typelink != '') ?
210     sprintf('<a href="%s">%s</a>', $typelink, $p['type']) :
211     $p['type'];
212    
213     $s .= '</td></tr>';
214 pterjan 268 }
215 rda 283 echo $s;
216 pterjan 268 ?>
217     </table>
218    
219     </body>
220     </html>

  ViewVC Help
Powered by ViewVC 1.1.30