63c0fc56bf86d6cc9fd087da07375066c000bd2a
[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 require "$ENV{BFConfDir}/BuildFarmWeb.pl";
20
21 my $dsn="dbi:Pg:dbname=$dbname";
22 $dsn .= ";host=$dbhost" if $dbhost;
23 $dsn .= ";port=$dbport" if $dbport;
24
25 my $dbh = DBI->connect($dsn,$dbuser,$dbpass) or die("$dsn,$dbuser,$dbpass,$!");
26
27 my %words;
28
29 my $sql = q{
30     select sysname, max(snapshot) as snapshot 
31     from build_status_log 
32     where branch = 'HEAD' and 
33         log_stage = 'typedefs.log' and 
34         snapshot > current_date::timestamp - interval '30 days' 
35     group by sysname
36 };
37 my $builds = $dbh->selectall_arrayref($sql, { Slice => {} });
38
39
40 if ($query->param('show_list'))
41 {
42     print "Content-Type: text/html\n\n",
43     "<head><title>Typedefs URLs</title></head>\n",
44     "<body><h1>Typdefs URLs</h1>\n",
45     "<table border='1'><tr><th>member</th></tr>\n";
46
47     foreach my $build (@$builds)
48     {
49         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";
50     }
51     print "</table></body></html>\n";
52     exit;
53 }
54
55 $sql = q{
56    select log_text
57    from build_status_log
58    where sysname = ?
59      and snapshot = ?
60      and log_stage = 'typedefs.log'
61      and branch = 'HEAD'
62  };
63
64 my $sth = $dbh->prepare($sql);
65
66 foreach my $build (@$builds)
67 {
68     $sth->execute($build->{sysname},$build->{snapshot});
69     my @row = $sth->fetchrow;
70     my @typedefs = split(/\s+/,$row[0]);
71     @words{@typedefs} = 1 x @typedefs;
72 }
73
74 print "Content-Type: text/plain\n\n",
75     join("\n",sort keys %words),
76     "\n";