Add a max_days param, default 10, to failures page.
[buildfarm-server.git] / cgi-bin / show_failures.pl
1 #!/usr/bin/perl
2
3 =comment
4
5 Copyright (c) 2003-2010, Andrew Dunstan
6
7 See accompanying License file for license details
8
9 =cut 
10
11 use strict;
12 use DBI;
13 use Template;
14 use CGI;
15
16 use vars qw($dbhost $dbname $dbuser $dbpass $dbport $template_dir);
17
18
19 require "$ENV{BFConfDir}/BuildFarmWeb.pl";
20
21 my $query = new CGI;
22 my @members = $query->param('member');
23 map { s/[^a-zA-Z0-9_ -]//g; } @members;
24 my $max_days =  $query->param('max_days') + 0 || 10;
25
26 my $dsn="dbi:Pg:dbname=$dbname";
27 $dsn .= ";host=$dbhost" if $dbhost;
28 $dsn .= ";port=$dbport" if $dbport;
29
30
31 my $sort_clause = "";
32 my $presort_clause = "";
33 my $sortby = $query->param('sortby') || 'nosort';
34 if ($sortby eq 'name')
35 {
36         $sort_clause = 'lower(b.sysname),';
37 }
38 elsif ($sortby eq 'namenobranch')
39 {
40         $presort_clause = "lower(b.sysname), b.snapshot desc,"
41 }
42
43 my $db = DBI->connect($dsn,$dbuser,$dbpass,{pg_expand_array => 0}) 
44     or die("$dsn,$dbuser,$dbpass,$!");
45
46 my $statement =<<EOS;
47
48
49   select timezone('GMT'::text, 
50         now())::timestamp(0) without time zone - b.snapshot AS when_ago, 
51         b.*,
52         d.stage as current_stage
53   from nrecent_failures_db_data b
54         left join  dashboard_mat d
55                 on (d.sysname = b.sysname and d.branch = b.branch)
56   where (now()::timestamp(0) without time zone - b.snapshot) < (? * interval '1 day')
57   order by $presort_clause 
58         b.branch = 'HEAD' desc,
59         b.branch desc, 
60         $sort_clause 
61         b.snapshot desc
62
63 EOS
64 ;
65
66 my $statrows=[];
67 my $sth=$db->prepare($statement);
68 $sth->execute($max_days);
69 while (my $row = $sth->fetchrow_hashref)
70 {
71     next if (@members && ! grep {$_ eq $row->{sysname} } @members);
72     $row->{build_flags}  =~ s/^\{(.*)\}$/$1/;
73     $row->{build_flags}  =~ s/,/ /g;
74         # enable-integer-datetimes is now the default
75         if ($row->{branch} eq 'HEAD' || $row->{branch} gt 'REL8_3_STABLE')
76         {
77                 $row->{build_flags} .= " --enable-integer-datetimes "
78                         unless ($row->{build_flags} =~ /--(en|dis)able-integer-datetimes/);
79         }
80         # enable-thread-safety is now the default
81         if ($row->{branch} eq 'HEAD' || $row->{branch} gt 'REL8_5_STABLE')
82         {
83                 $row->{build_flags} .= " --enable-thread-safety "
84                         unless ($row->{build_flags} =~ /--(en|dis)able-thread-safety/);
85         }
86     $row->{build_flags}  =~ s/--((enable|with)-)?//g;
87         $row->{build_flags} =~ s/libxml/xml/;
88     $row->{build_flags}  =~ s/\S+=\S+//g;
89     push(@$statrows,$row);
90 }
91 $sth->finish;
92
93
94 $db->disconnect;
95
96
97 my $template_opts = { INCLUDE_PATH => $template_dir };
98 my $template = new Template($template_opts);
99
100 print "Content-Type: text/html\n\n";
101
102 $template->process('fstatus.tt',
103                 {statrows=>$statrows, 
104                  sortby => $sortby,
105                  max_days => $max_days,
106                  members=> \@members} );
107
108 exit;
109