c3ef40713eab5cbee060f6faa6d77924ca0f88c5
[buildfarm-server.git] / cgi-bin / show_stage_log2.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use DBI;
5 use Template;
6 use CGI;
7 use File::Temp qw(tempfile);
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');
25 my $logdate = $query->param('dt');
26 my $stage = $query->param('stg');
27
28 use vars qw($tgz $output);
29
30 if ($stage && $system && $logdate)
31 {
32     
33 }
34
35 if ($system && $logdate)
36 {
37
38     my $db = DBI->connect($dsn,$dbuser,$dbpass);
39
40     die $DBI::errstr unless $db;
41
42     if ($stage)
43     {
44         my $lst = q(
45                     select log_text
46                     from build_status_log
47                     where sysname = ?
48                        and snapshot = ?
49                        and log_file_name = ?
50                     );
51         
52     }
53
54     my $statement = q(
55
56                 select log_archive
57                 from build_status
58                 where sysname = ? and snapshot = ?
59
60                 );
61
62
63     
64     my $sth=$db->prepare($statement);
65     $sth->execute($system,$logdate);
66     my $row=$sth->fetchrow_arrayref;
67     $tgz=$row->[0];
68     $sth->finish;
69     $db->disconnect;
70     $output = `tar -z -O -xf $filename $stage.log 2>&1`
71         if $stage;;
72
73
74
75 }
76
77 unless ($stage)
78 {
79
80     print 
81         "Content-Type: application/x-gzip\n", 
82         "Content-Disposition: attachment; filename=buildfarmlog.tgz\n",
83         "\n",
84         $tgz;
85     exit;
86 }
87
88 my $template = "buildlogXXXXXX";
89 my ($fh, $filename) = tempfile($template, UNLINK => 1);
90 print $fh $tgz;
91 close($fh);
92
93 print "Content-Type: text/plain\n\n", $output,
94
95     "-------------------------------------------------\n\n",
96     "Hosting for the PostgreSQL Buildfarm is generously ",
97     "provided by: CommandPrompt, The PostgreSQL Company";
98
99 ; exit;
100
101 # using <pre> like this on huge files can make browsers choke
102
103 print "Content-Type: text/html\n\n";
104
105 print <<EOHTML;
106 <html>
107 <body>
108 <pre>
109 $output
110 </pre>
111 </body>
112 </html>
113
114 EOHTML