diff --git a/mozilla/webtools/tinderbox3/scripts/showlog.pl b/mozilla/webtools/tinderbox3/scripts/showlog.pl index 8ad933402e1..32aeda273f6 100755 --- a/mozilla/webtools/tinderbox3/scripts/showlog.pl +++ b/mozilla/webtools/tinderbox3/scripts/showlog.pl @@ -1,9 +1,13 @@ #!/usr/bin/perl -wT -I. use strict; +use Fcntl qw/:seek/; use CGI; use CGI::Carp qw(fatalsToBrowser); use Tinderbox3::Log; +use Tinderbox3::Header; +use Tinderbox3::Login; +use Tinderbox3::DB; my $p = new CGI; my $machine_id = $p->param('machine_id') || ""; @@ -23,8 +27,140 @@ if (!defined($log_fh)) { die "No such log found!"; } -print $p->header("text/plain"); -while (<$log_fh>) { - print; +if ($p->param('format') && $p->param('format') eq 'raw') { + print $p->header("text/plain"); + while (<$log_fh>) { + print; + } + close $log_fh; +} else { + if (!$p->param('page') && !$p->param('format')) { + $p->param('format', 'summary'); + } + my $dbh = get_dbh(); + my ($login, $cookie) = check_session($p, $dbh); + my $bytes_per_page = 100 * 1024; + my @log_stat = stat($log_fh); + my $log_size = $log_stat[7]; + my $num_pages = int($log_size / $bytes_per_page) + 1; + my $page; + if (!$p->param('format') || $p->param('format') ne 'summary') { + $page = $p->param('page'); + } + if (!$page || $p->param('page') !~ /^\d+$/ || $page > $num_pages) { + $page = $num_pages; + } + my $title; + if ($p->param('format') && $p->param('format') eq 'summary') { + $title = "Summary"; + } else { + $title = "Page $page"; + } + + # + # Print the header + # + my $machine_info = $dbh->selectrow_arrayref("SELECT tree_name, machine_name FROM tbox_machine WHERE machine_id = ?", undef, $machine_id); + my ($tree, $machine_name) = @{$machine_info}; + header($p, $login, $cookie, "Log $logfile - $title", $tree, $machine_id, $machine_name); + + # Print the header links + my $pages_per_line = 15; + { + my $num_kbytes = int($log_size / 1024) + 1; + my $q = new CGI($p); + $q->delete('page'); + $q->param('format', 'raw'); + my $q2 = new CGI($p); + $q2->delete('page'); + $q2->param('format', 'summary'); + print "\n"; + } + + # Print the page links + foreach my $i (1..$num_pages) { + if (($i % $pages_per_line) == 1) { + print "\n"; + } + print "\n"; + if (($i % $pages_per_line) == 0) { + print "\n"; + } + } + print "
$title
Summary - Raw Log (${num_kbytes}K)
"; + if ($title eq "Summary" || $i ne $page) { + $p->delete('format'); + $p->param('page', $i); + print ""; + } + print $i; + if ($title eq "Summary" || $i ne $page) { + print ""; + } + print "

\n"; + + # + # Print the log summary + # + if ($title eq "Summary") { + print "

Event Summary

\n"; + print "
\n";
+    my $tab = 0;
+    my $pos;
+    my $max_page_size = length($num_pages);
+    my $last_page = -1;
+    while (($pos = tell($log_fh)) != -1 && ($_ = readline($log_fh))) {
+      if (/^<---/) {
+        $tab--;
+      }
+      if (/^--->/ || /^<---/) {
+        my $text_page = int($pos / $bytes_per_page) + 1;
+        if ($text_page != $last_page) {
+          $last_page = $text_page;
+          my $q = new CGI($p);
+          $q->delete('format');
+          $q->param('page', $text_page);
+          my $query_string = $q->query_string();
+
+          print "p.", sprintf("%-${max_page_size}s", $text_page), " ";
+        } else {
+          print " " x ($max_page_size+3);
+        }
+        print " " x ($tab*5);
+        print;
+      }
+      if (/^--->/) {
+        $tab++;
+      }
+    }
+    print "
\n"; + print "

Last Page - Page $page

\n"; + } + + # + # Print the log + # + + # Go to the right place in the log + seek($log_fh, ($page - 1) * $bytes_per_page, SEEK_SET); + # Go to the end of the line for page > 0 + if ($page > 1) { + my $buf; + while (1) { + last if !read($log_fh,$buf,1); + last if $buf eq "\n"; + } + } + + # Print the page + print "
";
+  my $pos = tell($log_fh);
+  my $buf;
+  while ($pos <= $page * $bytes_per_page && ($buf = readline($log_fh))) {
+    print $buf;
+    $pos = tell($log_fh);
+  }
+  print "
\n"; + footer($p); + $dbh->disconnect(); } -close $log_fh; diff --git a/mozilla/webtools/tinderbox3/server/showlog.pl b/mozilla/webtools/tinderbox3/server/showlog.pl index 8ad933402e1..32aeda273f6 100755 --- a/mozilla/webtools/tinderbox3/server/showlog.pl +++ b/mozilla/webtools/tinderbox3/server/showlog.pl @@ -1,9 +1,13 @@ #!/usr/bin/perl -wT -I. use strict; +use Fcntl qw/:seek/; use CGI; use CGI::Carp qw(fatalsToBrowser); use Tinderbox3::Log; +use Tinderbox3::Header; +use Tinderbox3::Login; +use Tinderbox3::DB; my $p = new CGI; my $machine_id = $p->param('machine_id') || ""; @@ -23,8 +27,140 @@ if (!defined($log_fh)) { die "No such log found!"; } -print $p->header("text/plain"); -while (<$log_fh>) { - print; +if ($p->param('format') && $p->param('format') eq 'raw') { + print $p->header("text/plain"); + while (<$log_fh>) { + print; + } + close $log_fh; +} else { + if (!$p->param('page') && !$p->param('format')) { + $p->param('format', 'summary'); + } + my $dbh = get_dbh(); + my ($login, $cookie) = check_session($p, $dbh); + my $bytes_per_page = 100 * 1024; + my @log_stat = stat($log_fh); + my $log_size = $log_stat[7]; + my $num_pages = int($log_size / $bytes_per_page) + 1; + my $page; + if (!$p->param('format') || $p->param('format') ne 'summary') { + $page = $p->param('page'); + } + if (!$page || $p->param('page') !~ /^\d+$/ || $page > $num_pages) { + $page = $num_pages; + } + my $title; + if ($p->param('format') && $p->param('format') eq 'summary') { + $title = "Summary"; + } else { + $title = "Page $page"; + } + + # + # Print the header + # + my $machine_info = $dbh->selectrow_arrayref("SELECT tree_name, machine_name FROM tbox_machine WHERE machine_id = ?", undef, $machine_id); + my ($tree, $machine_name) = @{$machine_info}; + header($p, $login, $cookie, "Log $logfile - $title", $tree, $machine_id, $machine_name); + + # Print the header links + my $pages_per_line = 15; + { + my $num_kbytes = int($log_size / 1024) + 1; + my $q = new CGI($p); + $q->delete('page'); + $q->param('format', 'raw'); + my $q2 = new CGI($p); + $q2->delete('page'); + $q2->param('format', 'summary'); + print "\n"; + } + + # Print the page links + foreach my $i (1..$num_pages) { + if (($i % $pages_per_line) == 1) { + print "\n"; + } + print "\n"; + if (($i % $pages_per_line) == 0) { + print "\n"; + } + } + print "
$title
Summary - Raw Log (${num_kbytes}K)
"; + if ($title eq "Summary" || $i ne $page) { + $p->delete('format'); + $p->param('page', $i); + print ""; + } + print $i; + if ($title eq "Summary" || $i ne $page) { + print ""; + } + print "

\n"; + + # + # Print the log summary + # + if ($title eq "Summary") { + print "

Event Summary

\n"; + print "
\n";
+    my $tab = 0;
+    my $pos;
+    my $max_page_size = length($num_pages);
+    my $last_page = -1;
+    while (($pos = tell($log_fh)) != -1 && ($_ = readline($log_fh))) {
+      if (/^<---/) {
+        $tab--;
+      }
+      if (/^--->/ || /^<---/) {
+        my $text_page = int($pos / $bytes_per_page) + 1;
+        if ($text_page != $last_page) {
+          $last_page = $text_page;
+          my $q = new CGI($p);
+          $q->delete('format');
+          $q->param('page', $text_page);
+          my $query_string = $q->query_string();
+
+          print "p.", sprintf("%-${max_page_size}s", $text_page), " ";
+        } else {
+          print " " x ($max_page_size+3);
+        }
+        print " " x ($tab*5);
+        print;
+      }
+      if (/^--->/) {
+        $tab++;
+      }
+    }
+    print "
\n"; + print "

Last Page - Page $page

\n"; + } + + # + # Print the log + # + + # Go to the right place in the log + seek($log_fh, ($page - 1) * $bytes_per_page, SEEK_SET); + # Go to the end of the line for page > 0 + if ($page > 1) { + my $buf; + while (1) { + last if !read($log_fh,$buf,1); + last if $buf eq "\n"; + } + } + + # Print the page + print "
";
+  my $pos = tell($log_fh);
+  my $buf;
+  while ($pos <= $page * $bytes_per_page && ($buf = readline($log_fh))) {
+    print $buf;
+    $pos = tell($log_fh);
+  }
+  print "
\n"; + footer($p); + $dbh->disconnect(); } -close $log_fh;