From 684f5456cad92a4690fa4e67cb40ea8d2cd4d0dc Mon Sep 17 00:00:00 2001 From: Andrew Dunstan Date: Tue, 12 Oct 2010 12:03:41 +0000 Subject: [PATCH] templatize show_log --- cgi-bin/show_log.pl | 321 +++++--------------------------------------- templates/log.tt | 131 ++++++++++++++++++ 2 files changed, 161 insertions(+), 291 deletions(-) create mode 100644 templates/log.tt diff --git a/cgi-bin/show_log.pl b/cgi-bin/show_log.pl index bd1a608..b462cc7 100755 --- a/cgi-bin/show_log.pl +++ b/cgi-bin/show_log.pl @@ -4,15 +4,12 @@ use strict; use DBI; use Template; use CGI; -use URI::Escape; use vars qw($dbhost $dbname $dbuser $dbpass $dbport $template_dir @log_file_names); - require "$ENV{BFConfDir}/BuildFarmWeb.pl"; -#require "BuildFarmWeb.pl"; -my $template_opts = { INCLUDE_PATH => $template_dir}; +my $template_opts = { INCLUDE_PATH => $template_dir, EVAL_PERL => 1}; my $template = new Template($template_opts); die "no dbname" unless $dbname; @@ -25,7 +22,7 @@ $dsn .= ";port=$dbport" if $dbport; my $query = new CGI; my $system = $query->param('nm'); $system =~ s/[^a-zA-Z0-9_ -]//g; -my $logdate = $query->param('dt'); $logdate =~ s/[^a-zA-Z0-9_ -]//g; +my $logdate = $query->param('dt'); $logdate =~ s/[^a-zA-Z0-9_ :-]//g; my $log = ""; my $conf = ""; @@ -41,15 +38,14 @@ if ($system && $logdate) die $DBI::errstr unless $db; - my $statement = <prepare($statement); $sth->execute($system,$logdate); my $row=$sth->fetchrow_arrayref; @@ -68,7 +64,7 @@ EOS if $log_file_names; $sth->finish; - $statement = <prepare($statement); $sth->execute($system); $info_row=$sth->fetchrow_hashref; @@ -94,289 +89,33 @@ foreach my $chgd ($changed_this_run,$changed_since_success) my $cvsurl = 'http://anoncvs.postgresql.org/cvsweb.cgi'; my $giturl = $scmurl || 'http://git.postgresql.org/gitweb?p=postgresql.git;a=commit;h='; my @lines = split(/!/,$chgd); + my $changed_rows = []; foreach (@lines) { - if ($scm eq 'git') - { - s!(^\S+)(\s+)(\S+)!$1!; - } - elsif ($scm eq 'cvs') - { - next unless m!^(pgsql|master|REL\d_\d_STABLE)/!; - s!(^\S+)(\s+)(\S+)!$1$2$3!; - } + next if ($scm eq 'cvs' and ! m!^(pgsql|master|REL\d_\d_STABLE)/!); + push(@$changed_rows,[$1,$3]) if (m!(^\S+)(\s+)(\S+)!); } - $chgd = join("\n",@lines); - $chgd ||= 'not recorded'; - + $chgd = $changed_rows; } $conf =~ s/\@/ [ a t ] /g; -map {s/&/&/g; s//>/g; s/\"/"/g;} ($log,$conf); -# map {s/!/\n/g} ($changed_this_run,$changed_since_success); - - -use POSIX qw(ceil); -my $lrfactor = 6; -my $logrows = ceil(scalar(@log_file_names)/$lrfactor); -my $logcells = $lrfactor * $logrows; - -my $heading_done; -my $urldt = uri_escape($logdate); - -my $cell = 0; - - print "Content-Type: text/html\n\n"; -if ($stage eq 'OK') -{ - print < - - - - PostgreSQL BuildFarm | Configuration summary for system "$system" - - - - -
- -
-

PostgreSQL Build Farm Log

- - - - - - - - - - - - - - - - - - -
System InformationFarm memberBranchOSCompilerArchitectureOwner
$system$branch$info_row->{operating_system} $info_row->{os_version}$info_row->{compiler} $info_row->{compiler_version}$info_row->{architecture}$info_row->{owner_email}
-EOHTML - - if ($info_row->{sys_notes}) - { - print < - - - - - - - - - - -
System NotesDateNotes
$info_row->{sys_notes_date}$info_row->{sys_notes}
-EOHTML - - } - -for my $logstage (@log_file_names) -{ - print "
\n" - unless $heading_done; - $heading_done = 1; - $cell++; - $logstage =~ s/\.log$//; - print "\n" if ($cell > 1 && $cell % $lrfactor == 1); - print "\n"; - print "\n" if ($cell % $lrfactor == 0); -} - -if ($cell) -{ - foreach my $rcell ($cell+1 .. $logcells) - { - print "\n" if ($rcell > 1 && $rcell % $lrfactor == 1); - print "\n"; - print "\n" if ($rcell % $lrfactor == 0); - } - print "
Stage Logs
$logstage
 
\n"; -} - -print < -

Configuration summary for system "$system"

-

Status 'OK' on snapshot taken $logdate

-
-$conf
-
-

Files changed this run

-
-$changed_this_run
-
-EOHTML -print <Log -
-$log
-
-EOHTML - print < -
-

-Hosting for the PostgreSQL Buildfarm is generously -provided by: -CommandPrompt, -The PostgreSQL Company -

-
- - -EOHTML -; - - exit; -} - -print < - - - - PostgreSQL BuildFarm | Log for system "$system" failure on snapshot taken $logdate - - - -
- -
-

PostgreSQL Build Farm Log

-

Details for system "$system" failure at stage $stage on snapshot taken $logdate

- - - - - - - - - - - - - - - - - - -
System InformationFarm memberBranchOSCompilerArchitectureOwner
$system$branch$info_row->{operating_system} $info_row->{os_version}$info_row->{compiler} $info_row->{compiler_version}$info_row->{architecture}$info_row->{owner_email}
-EOHTML - - if ($info_row->{sys_notes}) - { - print < - - - - - - - - - - -
System NotesDateNotes
$info_row->{sys_notes_date}$info_row->{sys_notes}
-EOHTML - - } - -for my $logstage (@log_file_names) -{ - print "
\n" - unless $heading_done; - $heading_done = 1; - $cell++; - $logstage =~ s/\.log$//; - print "\n" if ($cell > 1 && $cell % $lrfactor == 1); - print "\n"; - print "\n" if ($cell % $lrfactor == 0); -} - -if ($cell) -{ - foreach my $rcell ($cell+1 .. $logcells) - { - print "\n" if ($rcell > 1 && $rcell % $lrfactor == 1); - print "\n"; - print "\n" if ($rcell % $lrfactor == 0); - } - print "
Stage Logs
$logstage
 
\n"; -} - -print <Configuration summary -
-$conf
-
-

Files changed this run

-
-$changed_this_run
-
-

Files changed since last success

-
-$changed_since_success
-
-

Log

-
-$log
-
-
-
-

-Hosting for the PostgreSQL Buildfarm is generously -provided by: -CommandPrompt, -The PostgreSQL Company -

-
- - -EOHTML -; - - - +$template->process('log.tt', + { + scm => $scm, + scmurl => $scmurl, + system => $system, + branch => $branch, + stage => $stage, + urldt => $logdate, + log_file_names => \@log_file_names, + conf => $conf, + log => $log, + changed_this_run => $changed_this_run, + changed_since_success => $changed_since_success, + info_row => $info_row, + + }); diff --git a/templates/log.tt b/templates/log.tt new file mode 100644 index 0000000..291cbdb --- /dev/null +++ b/templates/log.tt @@ -0,0 +1,131 @@ +[% PERL %] + use POSIX qw(ceil); + my $lrfactor = 6; + $stash->set(lrfactor => $lrfactor); + my $rows = $stash->get('log_file_names'); + my $logrows = ceil(scalar(@$rows)/$lrfactor); + my $logcells = $lrfactor * $logrows; + $stash->set( logcells => $logcells); + $stash->set( logrows => $logrows ); +[% END -%] +[% + cvsurl = 'http://anoncvs.postgresql.org/cvsweb.cgi'; + giturl = scmurl || 'http://git.postgresql.org/gitweb?p=postgresql.git;a=commit;h='; +-%] + + + + + PostgreSQL BuildFarm | [% IF stage != 'OK' %]Log for system "[% system %]" failure on snapshot taken [% urldt ; ELSE %]Configuration summary for system "[% system %]" snapshot taken [% urldt ; END %] + + + + +
+ +
+

PostgreSQL Build Farm Log

+

Details for system "[% system %]"[% IF stage != 'OK' %] failure at stage [% stage ; ELSE %], status 'OK'[% END %], snapshot taken [% urldt %]

+ + + + + + + + + + + + + + + + + + +
System InformationFarm memberBranchOSCompilerArchitectureOwner
[% system %][% branch %][% info_row.operating_system %] [% info_row.os_version %][% info_row.compiler %] [% info_row.compiler_version %][% info_row.architecture %][% info_row.owner_email %]
+[% IF info_row.sys_notes %] +
+ + + + + + + + + + +
System NotesDateNotes
[% info_row.sys_notes_date %][% info_row.sys_notes %]
+[% END %] +[% cell = 0; FOREACH logstage IN log_file_names ; striplog = logstage.replace('\.log$','') ; cell = loop.count %] + [% IF loop.first %] +
+ [% END %] + [% IF loop.count > 1 and loop.count % lrfactor == 1 %][% END %] + + [% IF loop.count % lrfactor == 0 %][% END %] +[% END %] + +[% IF cell > 0 ; nrcell = cell + 1; ncells = [ nrcell .. logcells ] ; FOREACH rcell IN ncells %] + [% IF rcell > 1 and rcell % lrfactor == 1 %][% END %] + + [% IF rcell % lrfactor == 0 %][% END %] + [% END %] +
Stage Logs
[% striplog %]
 
+[% END %] + +

Configuration summary

+
+[% conf | html %]
+
+

Files changed this run

+
+[%- IF changed_this_run.0 -%]
+[%- FOREACH changed IN changed_this_run %]
+[% changed.0 ; IF scm == 'cvs'; ' '; changed.1; END %]
+[%- END -%]
+[%- ELSE %]
+not recorded
+[% END -%]
+
+[% IF stage != 'OK' %] +

Files changed since last success

+
+[%- IF changed_since_success.0 %]
+[%- FOREACH changed IN changed_since_success %]
+[% changed.0 ; IF scm == 'cvs'; ' '; changed.1; END %]
+[%- END -%]
+[%- ELSE %]
+not recorded
+[% END -%]
+
+[% END %] +

Log

+
+[% log | html %]
+
+
+
+

+Hosting for the PostgreSQL Buildfarm is generously +provided by: +CommandPrompt, +The PostgreSQL Company +

+
+ + -- 2.30.2