Initial commit
[buildfarm-server.git] / cgi-bin / show_history.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use DBI;
5 use Template;
6 use CGI;
7
8 use vars qw($dbhost $dbname $dbuser $dbpass $dbport);
9
10
11 require "$ENV{BFConfDir}/BuildFarmWeb.pl";
12 #require "BuildFarmWeb.pl";
13
14 die "no dbname" unless $dbname;
15 die "no dbuser" unless $dbuser;
16
17 my $dsn="dbi:Pg:dbname=$dbname";
18 $dsn .= ";host=$dbhost" if $dbhost;
19 $dsn .= ";port=$dbport" if $dbport;
20
21 my $db = DBI->connect($dsn,$dbuser,$dbpass);
22
23 die $DBI::errstr unless $db;
24
25 my $query = new CGI;
26 my $member = $query->param('nm'); $member =~ s/[^a-zA-Z0-9_ -]//g;
27 my $branch = $query->param('br'); $branch =~ s/[^a-zA-Z0-9_ -]//g;
28 my $hm = $query->param('hm');  $hm =~ s/[^a-zA-Z0-9_ -]//g;
29 $hm = '240' unless $hm =~ /^\d+$/;
30
31 # we don't really need to do this join, since we only want
32 # one row from buildsystems. but it means we only have to run one
33 # query. If it gets heavy we'll split it up and run two
34
35 my $statement = <<EOS;
36
37   select (now() at time zone 'GMT')::timestamp(0) - snapshot as when_ago,
38       sysname, snapshot, b.status, stage,
39       operating_system, os_version, compiler, compiler_version, architecture,
40       owner_email
41   from buildsystems s, 
42        build_status b 
43   where name = ?
44         and branch = ?
45         and s.status = 'approved'
46         and name = sysname
47   order by snapshot desc
48   limit $hm
49
50 EOS
51 ;
52
53 my $statrows=[];
54 my $sth=$db->prepare($statement);
55 $sth->execute($member,$branch);
56 while (my $row = $sth->fetchrow_hashref)
57 {
58     $row->{owner_email} =~ s/\@/ [ a t ] /;
59         push(@$statrows,$row);
60 }
61 $sth->finish;
62
63 $db->disconnect;
64
65 my $template = new Template({EVAL_PERL => 1});
66
67 print "Content-Type: text/html\n\n";
68
69 $template->process(\*DATA,
70                    {statrows=>$statrows, 
71                     branch=>$branch, 
72                     member => $member,
73                     hm => $hm
74                     });
75
76 exit;
77
78 __DATA__
79 [%- BLOCK cl %] class="[% SWITCH bgfor -%]
80   [%- CASE 'OK' %]pass[% CASE 'ContribCheck' %]warn[% CASE [ 'Check' 'InstallCheck' ] %]warnx[% CASE %]fail[% END %]"
81 [%- END -%]
82 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
83         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
84 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
85 <head>
86         <meta http-equiv="content-type" content="text/html; charset=utf-8" />
87     <title>PostgreSQL BuildFarm History</title>
88         <link rel="icon" type="image/png" href="/elephant-icon.png" />
89     <link rel="stylesheet" rev="stylesheet" href="/inc/pgbf.css" charset="utf-8" />
90         <style type="text/css"><!--
91         li#status a { color:rgb(17,45,137); background: url(/inc/b/r.png) no-repeat 100% -20px; } 
92         li#status { background: url(/inc/b/l.png) no-repeat 0% -20px; }
93         --></style>
94 </head>
95 <body class="history">
96 <div id="wrapper">
97 <div id="banner">
98 <a href="/index.html"><img src="/inc/pgbuildfarm-banner.png" alt="PostgreSQL BuildFarm" width="800" height="73" /></a>
99 <div id="nav">
100 <ul>
101     <li id="home"><a href="/index.html" title="PostgreSQL BuildFarm Home">Home</a></li>
102     <li id="status"><a href="/cgi-bin/show_status.pl" title="Current results">Status</a></li>
103     <li id="members"><a href="/cgi-bin/show_members.pl" title="Platforms tested">Members</a></li>
104     <li id="register"><a href="/register.html" title="Join PostgreSQL BuildFarm">Register</a></li>
105     <li id="pgfoundry"><a href="http://pgfoundry.org/projects/pgbuildfarm/">PGFoundry</a></li>
106 </ul>
107 </div><!-- nav -->
108 </div><!-- banner -->
109 <div id="main">
110 <h1>PostgreSQL BuildFarm Status History</h1>
111 <table cellspacing="0">
112     <tr><th class="head" colspan="3">System Detail</th></tr>
113     <tr class="member"><th>Farm member</th><td>[% member %]</td></tr>
114     <tr><th>OS</th><td>[% statrows.0.operating_system %] [% statrows.0.os_version %]</td></tr>
115 <!--    <tr><th>OS Version</th><td>[% statrows.0.os_version %]</td></tr> -->
116     <tr><th>Compiler</th><td>[% statrows.0.compiler %] [% statrows.0.compiler_version %]</td></tr>
117 <!--    <tr><th>Compiler Version</th><td>[% statrows.0.compiler_version %]</td></tr> -->
118     <tr><th>Architecture</th><td>[% statrows.0.architecture %]</td></tr>
119     <tr><th>Owner</th><td>[% statrows.0.owner_email %]</td></tr>
120     </table>
121     <h3>Branch: [% branch %][% IF statrows.size >= hm %] (last [% hm %] entries shown)[% END %]</h3>
122 [% BLOCK stdet %]
123 <tr [% PROCESS cl bgfor=row.stage %]>
124     <td>[%- row.when_ago | replace('\s','&nbsp;') %]&nbsp;ago&nbsp;</td>
125     <td class="status">[% row.stage -%]</td>
126     <td class="status"><a href="show_log.pl?nm=
127                [%- row.sysname %]&amp;dt=
128                [%- row.snapshot | uri %]">
129                 [%- IF row.stage != 'OK' %]Details[% ELSE %]Config[% END -%]</a></td>
130
131 </tr>
132 [% END %]
133 <table border="0"> <tr>
134 [% FOREACH offset IN [0,1,2] %][% low = offset * statrows.size / 3 ; high = -1 + (offset + 1) * statrows.size / 3 %] 
135 [% TRY %][% PERL %] 
136   use POSIX qw(floor); 
137   $stash->set(low => floor($stash->get('low'))); 
138   $stash->set(high => floor($stash->get('high'))); 
139 [% END %][% CATCH %]<!-- [% error.info %] --> [% END %]
140     <td><table cellspacing="0">
141 <!--      <tr><th colspan=3>low = [% low %], high = [% high %]</th></tr> -->
142         [% FOREACH xrow IN statrows.slice(low,high) %][% PROCESS stdet row=xrow %][% END %]
143     </table></td>
144 [% END %]
145 </table>
146     </div><!-- main -->
147 <hr />
148 <p style="text-align: center;">
149 Hosting for the PostgreSQL Buildfarm is generously 
150 provided by: 
151 <a href="http://www.commandprompt.com">CommandPrompt, 
152 The PostgreSQL Company</a>
153 </p>
154     </div><!-- wrapper -->
155   </body>
156 </html>