Refactoring.
authorMattias Holmlund <mattias@sol.holmlund.se>
Fri, 1 Aug 2008 13:23:55 +0000 (15:23 +0200)
committerMattias Holmlund <mattias@sol.holmlund.se>
Fri, 1 Aug 2008 13:23:55 +0000 (15:23 +0200)
tools/mh-xmltv-add-result [new file with mode: 0755]
tools/mh-xmltv-do-cvs [new file with mode: 0755]
tools/mh-xmltv-do-release [new file with mode: 0755]
tools/mh-xmltv-test [new file with mode: 0755]
tools/mh-xmltv-testlog2html

diff --git a/tools/mh-xmltv-add-result b/tools/mh-xmltv-add-result
new file mode 100755 (executable)
index 0000000..fdaf6c9
--- /dev/null
@@ -0,0 +1,69 @@
+#!/usr/bin/perl -w
+
+use strict;
+
+use File::Path qw/rmtree/;
+use File::Copy qw/move/;
+use IO::File;
+use IO::Wrap qw/wraphandle/;
+use File::Slurp qw/read_file/;
+use Data::Dumper;
+
+my ( $newresultdir, $summarydir ) = @ARGV;
+
+rotate( $summarydir );
+move( $newresultdir, "$summarydir/0" );
+update_state( "$summarydir/state.dump", "$summarydir/0/test_grabbers.dump" );
+
+sub rotate {
+  my( $dir ) = @_;
+
+  rmtree( "$dir/9" );
+  move( "$dir/8", "$dir/9" );
+  move( "$dir/7", "$dir/8" );
+  move( "$dir/6", "$dir/7" );
+  move( "$dir/5", "$dir/6" );
+  move( "$dir/4", "$dir/5" );
+  move( "$dir/3", "$dir/4" );
+  move( "$dir/2", "$dir/3" );
+  move( "$dir/1", "$dir/2" );
+  move( "$dir/0", "$dir/1" );
+}
+
+sub update_state {
+  my( $statefile, $lateststate ) = @_;
+
+  my $state;
+
+  if( -e $statefile ) {
+    my $statedata = read_file( $statefile );
+    $state = eval $statedata;
+  }
+  
+  my $latestdata = read_file( $lateststate );
+  my $latest = eval $latestdata;
+  
+  foreach my $grabber (keys %{$latest}) {
+    next if $grabber eq "t";
+    if( not defined( $state->{$grabber} ) ) {
+      $state->{$grabber} = { 
+         last_ok => 0,
+         last_fail => 0,
+         last_fail_message => "",
+      }
+    }
+
+    if( $latest->{$grabber} eq "ok" ) {
+      $state->{$grabber}->{last_ok} = $latest->{t};
+    }
+    else {
+      $state->{$grabber}->{last_fail} = $latest->{t};
+      $state->{$grabber}->{last_fail_message} = $latest->{$grabber};
+    }
+  }
+
+  open( OUT, "> $statefile" ) or die "open failed";
+  $Data::Dumper::Terse = 1;
+  print OUT Dumper( $state );
+  close( OUT );
+}
diff --git a/tools/mh-xmltv-do-cvs b/tools/mh-xmltv-do-cvs
new file mode 100755 (executable)
index 0000000..617b9b2
--- /dev/null
@@ -0,0 +1,25 @@
+#!/bin/sh 
+
+BASE=/home/mattias/nobackup/xmltv-tester
+XT=/home/mattias/development/xmltv-tester/tools
+CVS=:pserver:anonymous@xmltv.cvs.sourceforge.net:/cvsroot/xmltv
+
+rm -rf $BASE/work/nightly
+mkdir -p $BASE/work/nightly
+
+cd $BASE/work/nightly
+# cvs -d$CVS login 
+cvs -Q -z3 -d$CVS co -P xmltv
+cp -a $BASE/config/nightly/* $BASE/work/nightly/xmltv
+
+rm -rf $BASE/result/nightly/latest
+mkdir -p $BASE/result/nightly/latest
+$XT/mh-xmltv-test "$BASE/work/nightly/xmltv" \
+              "$BASE/result/nightly/latest" 
+
+$XT/mh-xmltv-testlog2html $BASE/result/nightly/latest/test_grabbers.log \
+                      "Nightly" $BASE/result/nightly/latest
+
+$XT/mh-xmltv-add-result "$BASE/result/nightly/latest" "$BASE/result/nightly"
+$XT/mh-xmltv-generate-summary "Nightly" "$BASE/result/nightly"
+rsync -az --delete $BASE/result/nightly/* upload.www2.holmlund.se:public_html/xmltv.se/validator/nightly
diff --git a/tools/mh-xmltv-do-release b/tools/mh-xmltv-do-release
new file mode 100755 (executable)
index 0000000..dd3c205
--- /dev/null
@@ -0,0 +1,24 @@
+#!/bin/sh 
+
+RELEASE=0.5.52
+
+BASE=/home/mattias/nobackup/xmltv-tester
+XT=/home/mattias/development/xmltv-tester/tools
+
+rm -rf $BASE/work/release
+mkdir -p $BASE/work/release
+
+tar xjf $BASE/tar/xmltv-$RELEASE.tar.bz2 --directory $BASE/work/release 
+cp -a $BASE/config/release/* $BASE/work/release/xmltv-$RELEASE
+
+rm -rf $BASE/result/release/latest
+mkdir -p $BASE/result/release/latest
+$XT/mh-xmltv-test "$BASE/work/release/xmltv-$RELEASE" \
+              "$BASE/result/release/latest" 
+
+$XT/mh-xmltv-testlog2html $BASE/result/release/latest/test_grabbers.log \
+                      "Release $RELEASE" $BASE/result/release/latest
+
+$XT/mh-xmltv-add-result "$BASE/result/release/latest" "$BASE/result/release"
+$XT/mh-xmltv-generate-summary "Release $RELEASE" "$BASE/result/release"
+rsync -az --delete $BASE/result/release/* upload.www2.holmlund.se:public_html/xmltv.se/validator/release
diff --git a/tools/mh-xmltv-test b/tools/mh-xmltv-test
new file mode 100755 (executable)
index 0000000..452a0d0
--- /dev/null
@@ -0,0 +1,78 @@
+#!/usr/bin/perl -w
+
+use strict;
+
+use File::Path qw/rmtree/;
+use File::Copy qw/move/;
+use IO::File;
+use IO::Wrap qw/wraphandle/;
+use File::Slurp qw/read_file/;
+use Data::Dumper;
+
+if( scalar( @ARGV ) != 2 ) {
+  print STDERR << "EOH";
+
+mh-xmltv-test <xmltvdir> <resultdir>
+
+xmltvdir shall contain the xmltv-source code.
+resultdir shall be a non-existent directory where the result will be placed.
+
+EOH
+
+  exit 1;
+}
+
+my( $xmltvdir, $resultdir ) = @ARGV;
+
+my $stdout = wraphandle( \*STDOUT );
+my $output_fh = $stdout;
+
+set_output( "$resultdir/build.log" );
+make( $xmltvdir );
+
+set_output( "$resultdir/test_grabbers.log" );
+test_grabbers( $xmltvdir, "$resultdir" );
+set_output();
+
+remove_listings( "$resultdir" );
+
+sub make {
+  my( $dir ) = @_;
+
+  run_cmd( $dir, "perl Makefile.PL --yes" );
+  run_cmd( $dir, "make" );
+}
+
+sub test_grabbers {
+  my( $srcdir, $resultdir ) = @_;
+
+  run_cmd( $resultdir, "$srcdir/grab/test_grabbers" );
+}
+sub remove_listings {
+  my( $dir ) = @_;
+
+  unlink( glob("$dir/*.xml") );
+  unlink( glob("$dir/*cache" ) );
+}
+
+sub set_output {
+  my( $filename ) = @_;
+
+  $output_fh->close() if $output_fh != $stdout;
+  if( defined $filename ) {
+    $output_fh = new IO::File "> $filename";
+    die "Failed to write to $filename" if not defined $output_fh; 
+  }
+  else {
+#    $output_fh = new IO::File "> /dev/null";
+    $output_fh = $stdout;
+    die "Failed to write to /dev/null" if not defined $output_fh; 
+  }
+}
+
+sub run_cmd {
+  my( $dir, $cmd ) = @_;
+
+  my $output = qx/cd $dir; $cmd 2>&1/;
+  $output_fh->print( $output );
+}
index d6dc57f..a340fa1 100755 (executable)
@@ -4,6 +4,7 @@ use strict;
 use Data::Dumper;
 use Template;
 use File::Slurp;
+use FindBin;
 
 if( scalar @ARGV != 3 ) {
     print "mh-xmltv-testlog2html <logfile> <title> <outdir>\n";
@@ -14,7 +15,7 @@ my( $infile, $title, $outdir ) = @ARGV;
 
 # some useful options (see below for full list)
 my $config = {
-    INCLUDE_PATH => '/home/mattias/development/xmltv-tester/templates/',
+    INCLUDE_PATH => "$FindBin::Bin/../templates/",
     INTERPOLATE  => 1,               # expand "$var" in plain text
     POST_CHOMP   => 1,               # cleanup whitespace
 #  PRE_PROCESS  => 'header',        # prefix each template