Add testcases detail column to status page
[buildfarm-server.git] / cgi-bin / show_status.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 use FindBin qw($RealBin);
19 require "$RealBin/../BuildFarmWeb.pl";
20
21 my $query = new CGI;
22 my @members = $query->param('member');
23 map { s/[^a-zA-Z0-9_ -]//g; } @members;
24
25 my $dsn="dbi:Pg:dbname=$dbname";
26 $dsn .= ";host=$dbhost" if $dbhost;
27 $dsn .= ";port=$dbport" if $dbport;
28
29
30 my $sort_clause = "";
31 my $sortby = $query->param('sortby') || 'nosort';
32 if ($sortby eq 'name')
33 {
34         $sort_clause = 'lower(sysname),';
35 }
36 elsif ($sortby eq 'os')
37 {
38         $sort_clause = 'lower(operating_system), os_version desc,'; 
39 }
40 elsif ($sortby eq 'compiler')
41 {
42         $sort_clause = "lower(compiler), compiler_version,";
43 }
44
45 my $db = DBI->connect($dsn,$dbuser,$dbpass,{pg_expand_array => 0}) 
46     or die("$dsn,$dbuser,$dbpass,$!");
47
48 my $statement =<<EOS;
49
50
51   SELECT timezone('GMT'::text, now())::timestamp(0) without time zone - b.snapshot AS when_ago,
52         b.*,
53         s.log_text
54   FROM dashboard_mat b LEFT JOIN build_status_log s
55   ON b.snapshot = s.snapshot AND s.log_stage = 'test-results.log'
56   ORDER BY b.branch = 'master' desc,
57         b.branch desc, $sort_clause 
58         b.snapshot desc
59
60 EOS
61 ;
62
63 my $statrows=[];
64 my $sth=$db->prepare($statement);
65 $sth->execute;
66 while (my $row = $sth->fetchrow_hashref)
67 {
68     next if (@members && ! grep {$_ eq $row->{sysname} } @members);
69     $row->{build_flags}  =~ s/^\{(.*)\}$/$1/;
70     $row->{build_flags}  =~ s/,/ /g;
71     $row->{build_flags}  =~ s/_PC\b//g;
72     $row->{build_flags} = lc($row->{build_flags});
73     if (defined($row->{log_text}))
74       {         # convert to a hash
75       $row->{log_text} = { split /\s+/, $row->{log_text} };
76       }
77     push(@$statrows,$row);
78 }
79 $sth->finish;
80
81
82 $db->disconnect;
83
84
85 my $template_opts = { INCLUDE_PATH => $template_dir };
86 my $template = new Template($template_opts);
87
88 print "Content-Type: text/html\n\n";
89
90 $template->process('status.tt',
91                 {statrows=>$statrows});
92
93 exit;
94