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