New server, FileBin instead of $ENV{BFConfDir}, and custom Captcha
[buildfarm-server.git] / cgi-bin / typedefs.pl
1 #!/usr/bin/perl
2
3 =comment
4
5 Copyright (c) 2003-2010, Andrew Dunstan
6
7 See accompanying License file for license details
8
9 =cut 
10
11 use strict;
12 use DBI;
13 use CGI;
14
15 my $query = new CGI;
16
17 use vars qw($dbhost $dbname $dbuser $dbpass $dbport);
18
19 use FindBin qw($RealBin);
20 require "$RealBin/../BuildFarmWeb.pl";
21
22 my $dsn="dbi:Pg:dbname=$dbname";
23 $dsn .= ";host=$dbhost" if $dbhost;
24 $dsn .= ";port=$dbport" if $dbport;
25
26 my $dbh = DBI->connect($dsn,$dbuser,$dbpass) or die("$dsn,$dbuser,$dbpass,$!");
27
28 my %words;
29
30 my $sql = q{
31     select sysname, max(snapshot) as snapshot 
32     from build_status_log 
33     where branch = 'HEAD' and 
34         log_stage = 'typedefs.log' and 
35         snapshot > current_date::timestamp - interval '30 days' 
36     group by sysname
37 };
38 my $builds = $dbh->selectall_arrayref($sql, { Slice => {} });
39
40
41 if ($query->param('show_list'))
42 {
43     print "Content-Type: text/html\n\n",
44     "<head><title>Typedefs URLs</title></head>\n",
45     "<body><h1>Typdefs URLs</h1>\n",
46     "<table border='1'><tr><th>member</th></tr>\n";
47
48     foreach my $build (@$builds)
49     {
50         print "<tr><td><a href='http://www.pgbuildfarm.org/cgi-bin/show_stage_log.pl?nm=$build->{sysname}\&amp;dt=$build->{snapshot}\&amp;stg=typedefs'>$build->{sysname}</a></td></tr>\n";
51     }
52     print "</table></body></html>\n";
53     exit;
54 }
55
56 $sql = q{
57    select log_text
58    from build_status_log
59    where sysname = ?
60      and snapshot = ?
61      and log_stage = 'typedefs.log'
62      and branch = 'HEAD'
63  };
64
65 my $sth = $dbh->prepare($sql);
66
67 foreach my $build (@$builds)
68 {
69     $sth->execute($build->{sysname},$build->{snapshot});
70     my @row = $sth->fetchrow;
71     my @typedefs = split(/\s+/,$row[0]);
72     @words{@typedefs} = 1 x @typedefs;
73 }
74
75 print "Content-Type: text/plain\n\n",
76     join("\n",sort keys %words),
77     "\n";