New server, FileBin instead of $ENV{BFConfDir}, and custom Captcha
[buildfarm-server.git] / cgi-bin / show_failures.pl
index 104bd66b794c8b2b44c34b4bb9cea0492392140c..592ab4f6c49220aba1efa5ac00cf76aad8e07ffa 100755 (executable)
@@ -15,12 +15,17 @@ use CGI;
 
 use vars qw($dbhost $dbname $dbuser $dbpass $dbport $template_dir);
 
-
-require "$ENV{BFConfDir}/BuildFarmWeb.pl";
+use FindBin qw($RealBin);
+require "$RealBin/../BuildFarmWeb.pl";
 
 my $query = new CGI;
-my @members = $query->param('member');
+my @members = grep {$_ ne "" } $query->param('member');
 map { s/[^a-zA-Z0-9_ -]//g; } @members;
+my $max_days =  $query->param('max_days') + 0 || 10;
+my @branches = grep {$_ ne "" } $query->param('branch');
+map { s/[^a-zA-Z0-9_ -]//g; } @branches;
+my @stages = grep {$_ ne "" } $query->param('stage');
+map { s/[^a-zA-Z0-9_ :-]//g; } @stages;
 
 my $dsn="dbi:Pg:dbname=$dbname";
 $dsn .= ";host=$dbhost" if $dbhost;
@@ -32,58 +37,90 @@ my $presort_clause = "";
 my $sortby = $query->param('sortby') || 'nosort';
 if ($sortby eq 'name')
 {
-       $sort_clause = 'lower(sysname),';
-}
-elsif ($sortby eq 'os')
-{
-       $sort_clause = 'lower(operating_system), os_version desc,'; 
-}
-elsif ($sortby eq 'compiler')
-{
-       $sort_clause = "lower(compiler), compiler_version,";
+       $sort_clause = 'lower(b.sysname),';
 }
 elsif ($sortby eq 'namenobranch')
 {
-       $presort_clause = "lower(sysname), snapshot desc,"
+       $presort_clause = "lower(b.sysname), b.snapshot desc,"
 }
 
 my $db = DBI->connect($dsn,$dbuser,$dbpass,{pg_expand_array => 0}) 
     or die("$dsn,$dbuser,$dbpass,$!");
 
+my $get_all_branches = qq{
+
+  select distinct branch
+  from nrecent_failures
+  where branch <> 'HEAD'
+  order by branch desc
+
+};
+
+my $all_branches = $db->selectcol_arrayref($get_all_branches);
+unshift (@$all_branches,'HEAD');
+
+my $get_all_members = qq{
+
+  select distinct sysname
+  from nrecent_failures
+  order by sysname
+
+};
+
+my $all_members = $db->selectcol_arrayref($get_all_members);
+
+my $get_all_stages = qq{
+
+  select distinct build_status.stage 
+  from build_status 
+    join nrecent_failures using (sysname,snapshot,branch)
+
+};
+
+my $all_stages = $db->selectcol_arrayref($get_all_stages);
+
 my $statement =<<EOS;
 
 
-  select timezone('GMT'::text, now())::timestamp(0) without time zone - b.snapshot AS when_ago, b.*
+  select timezone('GMT'::text, 
+       now())::timestamp(0) without time zone - b.snapshot AS when_ago, 
+       b.*,
+       d.stage as current_stage
   from nrecent_failures_db_data b
+       left join  dashboard_mat d
+               on (d.sysname = b.sysname and d.branch = b.branch)
+  where (now()::timestamp(0) without time zone - b.snapshot) < (? * interval '1 day')
   order by $presort_clause 
-        branch = 'HEAD' desc,
-        branch desc, 
+        b.branch = 'HEAD' desc,
+        b.branch desc, 
         $sort_clause 
-        snapshot desc
+        b.snapshot desc
 
 EOS
 ;
 
 my $statrows=[];
 my $sth=$db->prepare($statement);
-$sth->execute;
+$sth->execute($max_days);
 while (my $row = $sth->fetchrow_hashref)
 {
     next if (@members && ! grep {$_ eq $row->{sysname} } @members);
+    next if (@stages && ! grep {$_ eq $row->{stage} } @stages);
+    next if (@branches && ! grep {$_ eq $row->{branch} } @branches);
     $row->{build_flags}  =~ s/^\{(.*)\}$/$1/;
     $row->{build_flags}  =~ s/,/ /g;
-       # enable-integer-datetimes is now the default
-       if ($row->{branch} eq 'HEAD' || $row->{branch} gt 'REL8_3_STABLE')
-       {
-               $row->{build_flags} .= " --enable-integer-datetimes "
-                       unless ($row->{build_flags} =~ /--(en|dis)able-integer-datetimes/);
-       }
-       # enable-thread-safety is now the default
-       if ($row->{branch} eq 'HEAD' || $row->{branch} gt 'REL8_5_STABLE')
-       {
-               $row->{build_flags} .= " --enable-thread-safety "
-                       unless ($row->{build_flags} =~ /--(en|dis)able-thread-safety/);
-       }
+##     # enable-integer-datetimes is now the default
+##     if ($row->{branch} eq 'HEAD' || $row->{branch} gt 'REL8_3_STABLE')
+##     {
+##             $row->{build_flags} .= " --enable-integer-datetimes "
+##                     unless ($row->{build_flags} =~ /--(en|dis)able-integer-datetimes/);
+##     }
+##     # enable-thread-safety is now the default
+##     if ($row->{branch} eq 'HEAD' || $row->{branch} gt 'REL8_5_STABLE')
+##     {
+##             $row->{build_flags} .= " --enable-thread-safety "
+##                     unless ($row->{build_flags} =~ /--(en|dis)able-thread-safety/);
+##     }
     $row->{build_flags}  =~ s/--((enable|with)-)?//g;
        $row->{build_flags} =~ s/libxml/xml/;
     $row->{build_flags}  =~ s/\S+=\S+//g;
@@ -103,7 +140,12 @@ print "Content-Type: text/html\n\n";
 $template->process('fstatus.tt',
                {statrows=>$statrows, 
                 sortby => $sortby,
-                members=> \@members} );
+                max_days => $max_days,
+                all_branches => $all_branches,
+                all_members => $all_members,
+                all_stages => $all_stages,
+                qmembers=> \@members,
+                qbranches => \@branches,
+                qstages => \@stages} );
 
 exit;
-