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;
12 if (file_exists ("$rejecteddir/".$pkg->base
.".youri")) {
15 if (count ($pkg->failed
)) {
20 foreach ($sufficientarchs as $arch) {
21 if (array_key_exists ($arch, $pkg->done
)) {
25 if (array_key_exists ($arch, $pkg->builds
)) {
26 # The sufficient arch is still building
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
)) {
37 if ($hit == count ($requiredarchs)) {
45 if ($status == 'built') {
46 if (!file_exists ("$queuedir/".$pkg->srpm
)) {
52 $buildtime = date('YmdHis', $pkg->buildtime
);
53 $starttime = substr ($pkg->id
, 0, 14);
55 $line[] = $pkg->pkgname
;
56 $line[] = $pkg->version
;
57 $line[] = $pkg->commit
;
58 $line[] = $pkg->distro
;
59 $line[] = $pkg->repository
;
60 $line[] = $pkg->submitter
;
63 $line[] = delta_time ($starttime, $buildtime);
68 function parse_output()
70 list ($idlist, $infolist) = list_info_files();
73 foreach ($idlist as $id) {
74 $pkgs[] = new Package ($id, True, $infolist[$id]);
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');
93 function check_landed($table)
97 foreach ($table as $line) {
98 if ($line[0] != "uploaded") {
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.";
119 $new_table = array();
120 foreach ($table as $line) {
121 if ($line[0] != "uploaded") {
122 $new_table[] = $line;
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
137 $return_value = proc_close($process);
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>"
162 <table cellspacing=8>
172 <th><nobr>Finished for</nobr></th>
173 <th><nobr>Processing time</nobr></th>
177 foreach ($output as $item) {
181 $str .= "class='even'";
184 $str .= "class='odd'";
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>";
192 $str .= " <td><a href=\"http://svn.mandriva.com/cgi-bin/viewvc.cgi/packages?view=rev&revision=${item[3]}\">${item[3]}</a></td>";
195 $str .= "<td>N/A</td>";
197 $str .= " <td>${item[4]}</td>
200 <td><nobr>".delta_time($item[7])."</nobr></td>
201 <td><nobr>".$item[9]."</nobr></td>
211 function make_stats ($pkgs)
214 $overall['done'] = 0;
215 $overall['failed'] = 0;
216 $overall['excluded'] = 0;
217 $overall['total'] = 0;
223 foreach ($pkgs as $pkg) {
224 foreach (array_values ($pkg->done
) as $host) {
225 if (!array_key_exists($host, $h)) {
229 $h[$host]['total']++
;
231 foreach (array_values ($pkg->failed
) as $host) {
232 if (!array_key_exists($host, $h)) {
235 $h[$host]['failed']++
;
236 $h[$host]['total']++
;
238 foreach (array_values ($pkg->excluded
) as $host) {
239 $overall['excluded']++
;
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;
256 function make_stats_table($stats)
259 <h3>Statistics (with no filtering applied)</h3>
260 <table cellspacing=8>
271 $keys = array_keys ($stats);
273 foreach ($keys as $host) {
278 $str .= "class='even'";
281 $str .= "class='odd'";
286 <td>${h['done']}</td>
287 <td>${h['failed']}</td>\n";
288 if ($host == "Total") {
289 $str .= " <td>${h['excluded']}</td>\n";
292 $str .= " <td>-</td>\n";
294 $str .= " <td>${h['total']}</td>\n";
296 $str .= "</table>\n";
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);