use standards-compliant tags php
[mdv_bs_web.git] / output.php
blobb2175f58114f41eeb0a791bfc2fddf1265aedb39
1 <?
3 require_once 'common.inc.php';
4 require_once 'package.inc.php';
6 function parse_pkg ($pkg)
8 global $queuedir, $rejecteddir;
9 global $requiredarchs, $sufficientarchs;
11 $status = '';
12 if (file_exists ("$rejecteddir/".$pkg->base.".youri")) {
13 $status = 'rejected';
15 if (count ($pkg->failed)) {
16 $status = 'failed';
18 if (!$status) {
19 $hit = 0;
20 foreach ($sufficientarchs as $arch) {
21 if (array_key_exists ($arch, $pkg->done)) {
22 $status = 'built';
23 $hit = -1;
25 if (array_key_exists ($arch, $pkg->builds)) {
26 # The sufficient arch is still building
27 $hit = -1;
30 if ($hit == 0) {
31 # Only check required archs if sufficient ones are not used
32 foreach ($requiredarchs as $arch) {
33 if (array_key_exists ($arch, $pkg->done) or in_array ($arch, $pkg->excluded)) {
34 $hit++;
37 if ($hit == count ($requiredarchs)) {
38 $status = 'built';
42 if (!$status) {
43 return;
45 if ($status == 'built') {
46 if (!file_exists ("$queuedir/".$pkg->srpm)) {
47 $status = 'uploaded';
51 $line = array();
52 $buildtime = date('YmdHis', $pkg->buildtime);
53 $starttime = substr ($pkg->id, 0, 14);
54 $line[] = $status;
55 $line[] = $pkg->pkgname;
56 $line[] = $pkg->version;
57 $line[] = $pkg->commit;
58 $line[] = $pkg->distro;
59 $line[] = $pkg->repository;
60 $line[] = $pkg->submitter;
61 $line[] = $buildtime;
62 $line[] = $pkg->id;
63 $line[] = delta_time ($starttime, $buildtime);
65 return $line;
68 function parse_output()
70 list ($idlist, $infolist) = list_info_files();
71 $pkgs = array ();
73 foreach ($idlist as $id) {
74 $pkgs[] = new Package ($id, True, $infolist[$id]);
77 return $pkgs;
80 function buildtime_sort ($pkg_a, $pkg_b)
82 return $pkg_b[7] - $pkg_a[7];
85 function parse_pkgs($pkgs)
87 $pkgs = array_map ('parse_pkg', $pkgs);
88 $pkgs = array_filter ($pkgs, 'count');
89 usort ($pkgs, 'buildtime_sort');
90 return $pkgs;
93 function check_landed($table)
95 global $script_path;
96 $pkgs = array();
97 foreach ($table as $line) {
98 if ($line[0] != "uploaded") {
99 continue;
101 $pkgs[] = $line[4].'/SRPMS/'.$line[5].'/'.$line[1].'-'.$line[2];
104 $descriptorspec = array(
105 0 => array("file", "/dev/null", "r"), // stdin is a file that the child will read from
106 1 => array("pipe", "w"), // stdout is a pipe that the child will write to
107 2 => array("file", "/dev/null", "a") // stderr is a file to write to
110 $pkgs = implode (' ', $pkgs);
111 $process = proc_open("$script_path/version.pl $pkgs", $descriptorspec, $pipes, NULL, NULL);
114 if (!is_resource($process)) {
115 echo "Failed to check repository versions.";
116 return $table;
119 $new_table = array();
120 foreach ($table as $line) {
121 if ($line[0] != "uploaded") {
122 $new_table[] = $line;
123 continue;
125 $output = fgets ($pipes[1]);
126 $output = split (' ', $output);
127 $line[0] = trim($output[1]);
128 if (!strlen($line[0])) {
129 $line[0] = "unknown";
131 $new_table[] = $line;
134 // It is important to close any pipes before calling
135 // proc_close in order to avoid a deadlock
136 fclose($pipes[1]);
137 $return_value = proc_close($process);
139 return $new_table;
143 * make_output_table()
144 * Create an html table based on a properly formated array.
146 function make_output_table($output)
148 $statustable = array (
149 "failed" => "<font color=\"red\">FAILED</font>",
150 "rejected" => "<font color=\"red\">REJECTED</font>",
151 "built" => "<font color=\"blue\">BUILT</font>",
152 "uploaded" => "<font color=\"blue\">Uploaded</font>",
153 "hdlists" => "<font color=\"blue\">hdlists</font>",
154 # Missing one is when a new package is submitted.
155 "missing" => "<font color=\"blue\">hdlists</font>",
156 "available" => "<font color=\"green\">Available</font>",
157 "obsolete" => "<font color=\"green\">Obsolete</font>",
158 "unknown" => "<font color=\"red\"><blink>Unknown</blink></font>"
160 $str = "<center>
161 <h3>Output</h3>
162 <table cellspacing=8>
163 <tr>
164 <th>&nbsp;</th>
165 <th>Status</th>
166 <th>Package</th>
167 <th>Version</th>
168 <th>Commit</th>
169 <th>Distro</th>
170 <th>Repository</th>
171 <th>Submitter</th>
172 <th><nobr>Finished for</nobr></th>
173 <th><nobr>Processing time</nobr></th>
174 </tr>
176 $pos = 0;
177 foreach ($output as $item) {
178 $pos++;
179 $str .= "<tr ";
180 if ($pos % 2 == 0) {
181 $str .= "class='even'";
183 else {
184 $str .= "class='odd'";
186 $str .= ">
187 <td>$pos.</td>
188 <td>".$statustable[$item[0]]."</td>
189 <td><a href=\"package.php?key=${item[8]}\">${item[1]}</a></td>
190 <td align='right'>${item[2]}</td>";
191 if ($item[3]) {
192 $str .= " <td><a href=\"http://svn.mandriva.com/cgi-bin/viewvc.cgi/packages?view=rev&revision=${item[3]}\">${item[3]}</a></td>";
194 else {
195 $str .= "<td>N/A</td>";
197 $str .= " <td>${item[4]}</td>
198 <td>${item[5]}</td>
199 <td>${item[6]}</td>
200 <td><nobr>".delta_time($item[7])."</nobr></td>
201 <td><nobr>".$item[9]."</nobr></td>
202 </tr>
205 $str .= "</table>
206 </center>
208 return $str;
211 function make_stats ($pkgs)
213 $overall = array ();
214 $overall['done'] = 0;
215 $overall['failed'] = 0;
216 $overall['excluded'] = 0;
217 $overall['total'] = 0;
219 $blank = $overall;
221 $h = array ();
223 foreach ($pkgs as $pkg) {
224 foreach (array_values ($pkg->done) as $host) {
225 if (!array_key_exists($host, $h)) {
226 $h[$host] = $blank;
228 $h[$host]['done']++;
229 $h[$host]['total']++;
231 foreach (array_values ($pkg->failed) as $host) {
232 if (!array_key_exists($host, $h)) {
233 $h[$host] = $blank;
235 $h[$host]['failed']++;
236 $h[$host]['total']++;
238 foreach (array_values ($pkg->excluded) as $host) {
239 $overall['excluded']++;
243 // Sum it all
244 foreach (array_values ($h) as $hits) {
245 $overall['done'] += $hits['done'];
246 $overall['failed'] += $hits['failed'];
247 $overall['total'] += $hits['total'];
250 $overall['total'] += $overall['excluded'];
251 $h['Total'] = $overall;
253 return $h;
256 function make_stats_table($stats)
258 $str = "<center>
259 <h3>Statistics (with no filtering applied)</h3>
260 <table cellspacing=8>
261 <tr>
262 <th>&nbsp;</th>
263 <th>Buildnode</th>
264 <th>Done</th>
265 <th>Failed</th>
266 <th>Excluded</th>
267 <th>Total</th>
268 </tr>
270 $pos = 0;
271 $keys = array_keys ($stats);
272 natcasesort ($keys);
273 foreach ($keys as $host) {
274 $h = $stats[$host];
275 $pos++;
276 $str .= "<tr ";
277 if ($pos % 2 == 0) {
278 $str .= "class='even'";
280 else {
281 $str .= "class='odd'";
283 $str .= ">
284 <td>$pos.</td>
285 <td>$host</td>
286 <td>${h['done']}</td>
287 <td>${h['failed']}</td>\n";
288 if ($host == "Total") {
289 $str .= " <td>${h['excluded']}</td>\n";
291 else {
292 $str .= " <td>-</td>\n";
294 $str .= " <td>${h['total']}</td>\n";
296 $str .= "</table>\n";
297 return $str;
301 // Build the page
302 page_header("output");
303 $pkgs = parse_output();
304 $stats = make_stats ($pkgs);
305 $output = parse_pkgs ($pkgs);
306 $filtered = filter ($output);
307 $filtered = check_landed ($filtered);
308 $table = make_output_table($filtered);
309 $table2 = make_stats_table($stats);
310 echo $table2;
311 echo $table;
312 page_footer();