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