remove redundant file
[buildfarm-server.git] / cgi-bin / show_log.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use DBI;
5 use Template;
6 use CGI;
7 use URI::Escape;
8
9 use vars qw($dbhost $dbname $dbuser $dbpass $dbport $template_dir @log_file_names);
10
11
12 require "$ENV{BFConfDir}/BuildFarmWeb.pl";
13 #require "BuildFarmWeb.pl";
14
15 my $template_opts = { INCLUDE_PATH => $template_dir};
16 my $template = new Template($template_opts);
17
18 die "no dbname" unless $dbname;
19 die "no dbuser" unless $dbuser;
20
21 my $dsn="dbi:Pg:dbname=$dbname";
22 $dsn .= ";host=$dbhost" if $dbhost;
23 $dsn .= ";port=$dbport" if $dbport;
24
25 my $query = new CGI;
26
27 my $system = $query->param('nm'); $system =~ s/[^a-zA-Z0-9_ -]//g;
28 my $logdate = $query->param('dt'); $logdate =~ s/[^a-zA-Z0-9_ -]//g;
29
30 my $log = "";
31 my $conf = "";
32 my ($stage,$changed_this_run,$changed_since_success,$sysinfo,$branch,$scmurl);
33 my $scm;
34
35 use vars qw($info_row);
36
37 if ($system && $logdate)
38 {
39
40         my $db = DBI->connect($dsn,$dbuser,$dbpass);
41
42         die $DBI::errstr unless $db;
43
44         my $statement = <<EOS;
45
46   select log,conf_sum,stage, changed_this_run, changed_since_success,branch,
47       log_archive_filenames, scm, scmurl
48   from build_status
49   where sysname = ? and snapshot = ?
50
51 EOS
52 ;
53         my $sth=$db->prepare($statement);
54         $sth->execute($system,$logdate);
55         my $row=$sth->fetchrow_arrayref;
56         $log=$row->[0];
57         $conf=$row->[1] || "not recorded" ;
58         $stage=$row->[2] || "unknown";
59         $changed_this_run = $row->[3];
60         $changed_since_success = $row->[4];
61         $branch = $row->[5];
62         my $log_file_names = $row->[6];
63         $scm = $row->[7];
64         $scm ||= 'cvs'; # legacy scripts
65         $scmurl = $row->[8];
66         $log_file_names =~ s/^\{(.*)\}$/$1/;
67         @log_file_names=split(',',$log_file_names)
68             if $log_file_names;
69         $sth->finish;
70
71         $statement = <<EOS;
72
73           select operating_system, os_version, 
74                  compiler, compiler_version, 
75                  architecture,
76                  replace(owner_email,'\@',' [ a t ] ') as owner_email,
77                  sys_notes_ts::date AS sys_notes_date, sys_notes
78           from buildsystems 
79           where status = 'approved'
80                 and name = ?
81
82 EOS
83 ;
84         $sth=$db->prepare($statement);
85         $sth->execute($system);
86         $info_row=$sth->fetchrow_hashref;
87         # $sysinfo = join(" ",@$row);
88         $sth->finish;
89         $db->disconnect;
90 }
91
92 foreach my $chgd ($changed_this_run,$changed_since_success)
93 {
94         my $cvsurl = 'http://anoncvs.postgresql.org/cvsweb.cgi';
95         my $giturl = $scmurl || 'http://git.postgresql.org/gitweb?p=postgresql.git;a=commit;h=';
96     my @lines = split(/!/,$chgd);
97     foreach (@lines)
98     {
99                 if ($scm eq 'git')
100                 {
101                         s!(^\S+)(\s+)(\S+)!<a href="$giturl$3">$1</a>!;
102                 }
103                 elsif ($scm eq 'cvs')
104                 {
105                         next unless m!^(pgsql|master|REL\d_\d_STABLE)/!;
106                         s!(^\S+)(\s+)(\S+)!<a href="$cvsurl/$1?rev=$3">$1$2$3</a>!;
107                 }
108     }
109     $chgd = join("\n",@lines);
110     $chgd ||= 'not recorded';
111         
112 }
113
114 $conf =~ s/\@/ [ a t ] /g;
115 map {s/&/&amp;/g; s/</&lt;/g; s/>/&gt;/g; s/\"/&quot;/g;} ($log,$conf);
116 # map {s/!/\n/g} ($changed_this_run,$changed_since_success);
117
118
119 use POSIX qw(ceil);
120 my $lrfactor = 6;
121 my $logrows = ceil(scalar(@log_file_names)/$lrfactor);
122 my $logcells = $lrfactor * $logrows;
123
124 my $heading_done;
125 my $urldt = uri_escape($logdate);
126
127 my $cell = 0;
128
129
130
131 print "Content-Type: text/html\n\n";
132
133 if ($stage eq 'OK')
134 {
135         print <<EOHTML;
136 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
137         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
138 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
139 <head>
140         <meta http-equiv="content-type" content="text/html; charset=utf-8" />
141     <title>PostgreSQL BuildFarm | Configuration summary for system "$system"</title>
142         <link rel="icon" type="image/png" href="/elephant-icon.png" />
143     <link rel="stylesheet" rev="stylesheet" href="/inc/pgbf.css" charset="utf-8" />
144 </head>
145 <body>
146 <div id="wrapper">
147 <div id="banner">
148 <a href="/index.html"><img src="/inc/pgbuildfarm-banner.png" alt="PostgreSQL BuildFarm" width="800" height="73" /></a>
149 <div id="nav">
150 <ul>
151     <li id="home"><a href="/index.html" title="PostgreSQL BuildFarm Home">Home</a></li>
152     <li id="status"><a href="/cgi-bin/show_status.pl" title="Current results">Status</a></li>
153     <li id="members"><a href="/cgi-bin/show_members.pl" title="Platforms tested">Members</a></li>
154     <li id="register"><a href="/cgi-bin/register-form.pl" title="Join PostgreSQL BuildFarm">Register</a></li>
155     <li id="pgfoundry"><a href="http://pgfoundry.org/projects/pgbuildfarm/">PGFoundry</a></li>
156 </ul>
157 </div><!-- nav -->
158 </div><!-- banner -->
159 <div id="main">
160 <h1>PostgreSQL Build Farm Log</h1>
161 <table align="top" cellspacing="0">
162     <tr>
163         <th class="head" rowspan="2">System Information</th>
164         <th>Farm member</th>
165         <th>Branch</th>
166         <th>OS</th>
167         <th>Compiler</th>
168         <th>Architecture</th>
169         <th>Owner</th>
170     </tr>
171     <tr>
172         <td>$system</td>
173         <td><a href="/cgi-bin/show_history.pl?nm=$system&amp;br=$branch">$branch</a></td>
174         <td>$info_row->{operating_system} $info_row->{os_version}</td>
175         <td>$info_row->{compiler} $info_row->{compiler_version}</td>
176         <td>$info_row->{architecture}</td>
177         <td>$info_row->{owner_email}</td>
178     </tr>
179     </table>
180 EOHTML
181
182     if ($info_row->{sys_notes})
183     {
184         print <<EOHTML;
185     <br />
186     <table>
187      <tr>
188        <th class="head" rowspan="2">System Notes</th>
189        <th>Date</th>
190        <th>Notes</th>
191      </tr>
192      <tr>
193       <td>$info_row->{sys_notes_date}</td>
194       <td>$info_row->{sys_notes}</td>
195      </tr>
196    </table>
197 EOHTML
198
199     }
200
201 for my $logstage (@log_file_names)
202 {
203     print "<br /> <table><tr><th class='head' rowspan='$logrows'>Stage Logs</th>\n"
204         unless $heading_done;
205     $heading_done = 1;
206     $cell++;
207     $logstage =~ s/\.log$//;
208     print "<tr>\n" if ($cell > 1 && $cell % $lrfactor == 1);
209     print "<td><a href='show_stage_log.pl?nm=$system&amp;dt=$urldt&amp;stg=$logstage'>$logstage</a></td>\n";
210     print "</tr>\n" if ($cell % $lrfactor == 0);
211 }
212
213 if ($cell)
214 {
215     foreach my $rcell ($cell+1 .. $logcells)
216     {
217         print "<tr>\n" if ($rcell > 1 && $rcell % $lrfactor == 1);
218         print "<td>&nbsp;</td>\n";
219         print "</tr>\n" if ($rcell % $lrfactor == 0);
220     }
221     print "</table>\n";
222 }
223
224 print <<EOHTML;
225 </table>
226 <h2>Configuration summary for system "$system"</h2>
227 <h3>Status 'OK' on snapshot taken $logdate</h3>
228 <pre>
229 $conf
230 </pre>
231 <h3>Files changed this run</h3>
232 <pre>
233 $changed_this_run
234 </pre>
235 EOHTML
236 print <<EOHTML if ($log);
237 <h3>Log</h3>
238 <pre>
239 $log
240 </pre>
241 EOHTML
242     print <<EOHTML;
243 </div><!-- main -->
244 <hr />
245 <p style="text-align: center;">
246 Hosting for the PostgreSQL Buildfarm is generously 
247 provided by: 
248 <a href="http://www.commandprompt.com">CommandPrompt, 
249 The PostgreSQL Company</a>
250 </p>
251 </div><!-- wrapper -->
252 </body>
253 </html>
254 EOHTML
255 ;
256
257         exit;
258 }
259
260 print <<EOHTML;
261 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
262         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
263 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
264 <head>
265         <meta http-equiv="content-type" content="text/html; charset=utf-8" />
266     <title>PostgreSQL BuildFarm | Log for system "$system" failure on snapshot taken $logdate</title>
267     <link rel="stylesheet" rev="stylesheet" href="/inc/pgbf.css" charset="utf-8" />
268 </head>
269 <body>
270 <div id="wrapper">
271 <div id="banner">
272 <a href="/index.html"><img src="/inc/pgbuildfarm-banner.png" alt="PostgreSQL BuildFarm" width="800" height="73" /></a>
273 <div id="nav">
274 <ul>
275     <li id="home"><a href="/index.html" title="PostgreSQL BuildFarm Home">Home</a></li>
276     <li id="status"><a href="/cgi-bin/show_status.pl" title="Status Page">Status</a></li>
277     <li id="members"><a href="/cgi-bin/show_members.pl" title="Status Page">Members</a></li>
278     <li id="register"><a href="/cgi-bin/register-form.pl" title="Register">Register</a></li>
279     <li id="pgfoundry"><a href="http://pgfoundry.org/projects/pgbuildfarm/">PGFoundry</a></li>
280 </ul>
281 </div><!-- nav -->
282 </div><!-- banner -->
283 <div id="main">
284     <h1>PostgreSQL Build Farm Log</h1>
285 <h1>Details for system "$system" failure at stage $stage on snapshot taken $logdate</h1>
286 <table cellspacing="0">
287     <tr>
288         <th class="head" rowspan="2">System Information</th>
289         <th>Farm member</th>
290         <th>Branch</th>
291         <th>OS</th>
292         <th>Compiler</th>
293         <th>Architecture</th>
294         <th>Owner</th>
295     </tr>
296     <tr>
297         <td>$system</td>
298         <td><a href="/cgi-bin/show_history.pl?nm=$system&amp;br=$branch">$branch</a></td>
299         <td>$info_row->{operating_system} $info_row->{os_version}</td>
300         <td>$info_row->{compiler} $info_row->{compiler_version}</td>
301         <td>$info_row->{architecture}</td>
302         <td>$info_row->{owner_email}</td>
303     </tr>
304   </table>
305 EOHTML
306
307     if ($info_row->{sys_notes})
308     {
309         print <<EOHTML;
310     <br />
311     <table>
312      <tr>
313        <th class="head" rowspan="2">System Notes</th>
314        <th>Date</th>
315        <th>Notes</th>
316      </tr>
317      <tr>
318       <td>$info_row->{sys_notes_date}</td>
319       <td>$info_row->{sys_notes}</td>
320      </tr>
321    </table>
322 EOHTML
323
324     }
325
326 for my $logstage (@log_file_names)
327 {
328     print "<br /> <table><tr><th class='head' rowspan='4'>Stage Logs</th>\n"
329         unless $heading_done;
330     $heading_done = 1;
331     $cell++;
332     $logstage =~ s/\.log$//;
333     print "<tr>\n" if ($cell > 1 && $cell % $lrfactor == 1);
334     print "<td><a href='show_stage_log.pl?nm=$system&amp;dt=$urldt&amp;stg=$logstage'>$logstage</a></td>\n";
335     print "</tr>\n" if ($cell % $lrfactor == 0);
336 }
337
338 if ($cell)
339 {
340     foreach my $rcell ($cell+1 .. $logcells)
341     {
342         print "<tr>\n" if ($rcell > 1 && $rcell % $lrfactor == 1);
343         print "<td>&nbsp;</td>\n";
344         print "</tr>\n" if ($rcell % $lrfactor == 0);
345     }
346     print "</table>\n";
347 }
348
349 print <<EOHTML;
350 <h3>Configuration summary</h3>
351 <pre>
352 $conf
353 </pre>
354 <h3>Files changed this run</h3>
355 <pre>
356 $changed_this_run
357 </pre>
358 <h3>Files changed since last success</h3>
359 <pre>
360 $changed_since_success
361 </pre>
362 <h3>Log</h3>
363 <pre>
364 $log
365 </pre>
366 </div><!-- main -->
367 <hr />
368 <p style="text-align: center;">
369 Hosting for the PostgreSQL Buildfarm is generously 
370 provided by: 
371 <a href="http://www.commandprompt.com">CommandPrompt, 
372 The PostgreSQL Company</a>
373 </p>
374 </div><!-- wrapper -->
375 </body>
376 </html>
377 EOHTML
378 ;
379
380
381
382