generalize for non-openSUSE projects
[os-autoinst:opensuse.git] / www / cgi-bin / currentresults
1 #!/usr/bin/perl -w
2 use strict;
3 use CGI ":standard";
4 use lib "/srv/www/cgi-bin/modules";
5 use awstandard;
6 use sort_table;
7 use openqa;
8
9 my $defaulthoursfresh=4*24;
10
11
12 my %options;
13 for my $p (qw'sort hours ib match') {
14    $options{$p}=param($p);
15 }
16 if($options{ib}) {
17         require boring;
18 }
19 if($options{match}) {
20         $options{match}=~s/[^\w\[\]\{\}\(\),:.+*?\\|-]//g; # sanitize
21 }
22 #if(!defined $options{sort}){$options{sort}="-5.3.4.-7";} # default sort by Build# descending
23 if(!defined $options{sort}){$options{sort}="-7"; param("sort",$options{sort})} # default sort by Time descending
24 if(!defined($options{hours}) || $options{hours}=~m/\D/) {$options{hours}=$defaulthoursfresh}
25 my $hoursfresh=($options{hours}+0);
26 if($hoursfresh<1 || $hoursfresh>900) {$hoursfresh=$defaulthoursfresh}
27 my $maxage=3600*$hoursfresh;
28
29 my $resultdir="$basedir/$prj/video";
30 my @list=();
31 my $now=time();
32 my $maxmtime=(stat($ENV{SCRIPT_FILENAME}))[9];
33 for my $r (<$resultdir/*.autoinst.txt>) {
34         my @s=stat($r);
35         my ($logsize,$mtime)=@s[7,9];
36         if($mtime>$maxmtime){$maxmtime=$mtime}
37         next if $mtime < $now - $maxage; # skip old
38         next if($options{match} && $r!~m/$options{match}/);
39         my ($link, $distri, $type, $arch, $build, $extrainfo)=split_filename($r);
40         my @lines=parse_log($r);
41         my $parsed=parse_log_to_stats(\@lines);
42         my $result=parse_log_to_hash(\@lines);
43         if($logsize==0) {
44                 $link="testing";
45                 $parsed->{OK}=" ";
46         }
47 #       next if $logsize<100; # too small => bug somewhere
48         if($options{ib}) {
49                 next if(boring::is_boring($r, $result));
50         }
51         push(@list, [$link, $distri, $type, $arch, $build, $extrainfo, 
52             $mtime, $parsed->{OK}||0, $parsed->{unknown}||"", $parsed->{fail}||"", $result->{overall}
53             ]);
54 }
55
56 # gets arrayref to current row
57 sub qarowfunc($) {
58         my $overall=$_[0]->[10];
59         $overall=!defined($overall) || ($overall eq "OK"); # not defined while test in progress
60         if(!$overall) {
61                 for my $i (4,5) {
62                         $_[0]->[$i]=~s{.*}{<span class="overviewfail">$&</span>};
63                 }
64         }
65 }
66
67 sub resultspan($$) {my ($status,$value)=@_;if($value eq ""){return ""} qq'<span class="overview$_[0]">&nbsp;$_[1]&nbsp;</span>'}
68
69 my $table=sort_table(
70   [qw(link distri type arch build extra 
71       testtime OK unk fail)],
72   [\&display_string, undef, \&display_string, \&display_string, \&display_string, \&display_string, 
73       \&display_time, sub{resultspan("ok",$_[0])}, sub{resultspan("unknown",$_[0])}, sub{resultspan("fail",$_[0])}],
74   [undef, undef, \&sort_string, \&sort_string, \&sort_num, \&sort_string, 
75       \&sort_num, \&sort_num, \&sort_num, \&sort_num],
76   sort_param_to_keys($options{sort}), \@list, \&qarowfunc
77 );
78
79 my @hoursoptions=(24,96,200,300);
80 my %hoursoptionslabels=map {($_,"$_ h")} @hoursoptions;
81 my $hoursselect=qq{<form method="get" action="" class="cutofftimeform">}.
82         hidden(-name=>'sort').
83         popup_menu(-name=>'hours', -values=>\@hoursoptions, -labels=>\%hoursoptionslabels).
84         textfield(-name=>"match")." filter ".
85         checkbox(-name=>"ib", -label=>"ignore boring results")." ".
86         qq{<input value="change" class="smbutton" type="submit" /></form>\n};
87 my $knownissues=file_content("/srv/www/htdocs/includes/knownissues.html");
88 my $numresults=@list;
89
90 my $note="Note: times are UTC ; tests without an 'extra' string just use default desktop+settings - which means KDE, except on GNOME-LiveCD";
91
92 my ($header,$footer)=get_header_footer("Results");
93 print header(-type=>"text/html", -Last_Modified=>awstandard::HTTPdate($maxmtime));
94 print $header.
95 qq{
96   <!-- Start: Main Content Area -->
97 <div id="content" class="container_16 content-wrapper">
98
99           <div class="grid_5 box box-shadow alpha" id="top_features_box">
100             <div class="box-header aligncenter">
101                Recent issues in Factory
102             </div>
103 $knownissues
104           </div>
105  <div class="grid_11 box box-shadow omega">
106 <h2>Test result overview</h2>
107 <p>This page lists $numresults automated test-results from the last $hoursfresh hours.
108 </p>
109 $hoursselect
110 <p></p>
111 $table
112 <p>
113 $note
114 </p>
115  </div>
116 </div>
117
118 $footer};
119