cgal/Maintenance/test_handling/treat_result_collection

171 lines
4.1 KiB
Perl
Executable File

#!/usr/bin/perl
use Cwd;
use strict;
#$ENV{PATH}=
#'/sw/bin:/sbin:/usr/sbin:/usr/bsd:/bin:/usr/bin';
my $scriptsdir;
my $unpack_dir_base;
my $unpack_dir;
my $testresult_dir;
my $lockfile="cgal_testannounce.lock";
#my $announcements_dir="/private/CGAL/testannouncements";
my $announcements_dir="/u/termite/0/user/spion/CGAL/testannouncements";
my $lock_cmd= "/usr/local/bin/lockfile";
my $currentdir;
my $ftp_results_dir="/net/servers/ftp-sop/geometrica/Incoming";
my $check_file="processed_test_results";
my ($cgal_version,$tarname,@results);
$currentdir=cwd();
$testresult_dir="$currentdir/TESTRESULTS";
$scriptsdir="$currentdir";
$unpack_dir_base="$currentdir";
sub make_unpackdir()
{
my $dirno = 1;
my $TMPDIR;
$TMPDIR = "$unpack_dir_base/TMP$dirno";
while ( -f $TMPDIR or -d $TMPDIR ) {
++$dirno;
$TMPDIR = "$unpack_dir_base/TMP$dirno";
}
mkdir($TMPDIR,0770) or die "Cannot create temporary directory $TMPDIR\n";
$unpack_dir = $TMPDIR;
}
sub unpack_results{
chdir $unpack_dir or die;
system "cp $ftp_results_dir/$_[0] $_[0]";
system "chmod 644 $_[0]";
system("gunzip", "$_[0]")== 0
or die "Could not gunzip $_[0]\n";
@results=grep /tar$|tar\.gz$/, `tar tf ${tarname}`;
chomp @results;
system("tar", "xf", ${tarname}, @results);
system("$scriptsdir/to_zipped_format", "-v", $cgal_version, @results)==0
or die "to_zipped_format failed. Test collection not installed.\n";
}
sub install_results()
{
if (-d $testresult_dir) {
chdir $testresult_dir or die;
} else {
mkdir $testresult_dir or die;
chdir $testresult_dir or die;
}
if (-d $cgal_version) {
chdir $cgal_version or die;
} else {
mkdir $cgal_version or die;
chdir $cgal_version or die;
}
my $resultfile;
for $resultfile (@results) {
$resultfile =~ s/\.gz//;
system('tar','--force-local','-xf',"${unpack_dir}/${resultfile}")==0 or die;
# unlink "${unpack_dir}/$resultfile";
}
chdir ".." or die;
# system("./create_testresult_page", $cgal_version);
# clean up stuff in UNPACK_DIR
chdir $unpack_dir or die;
# unlink $tarname;
# notify();
}
#return 0 if it exists and 1 otherwise
sub exist_in_file{
chdir($currentdir);
my $contents;
if( -e $check_file){
open FILE, $check_file || die ("Could not open $check_file");
while ($contents = <FILE>){
chop $contents;
if ( "$contents" eq "$_[0]" ){
close FILE;
return 0;
}
}
close FILE;
return 1;
} else {
return 1;
}
}
#first argument is a string
sub append_to_file{
chdir($currentdir);
if ( -w $check_file ) {
open FILE, ">> $check_file" || die ("Could not open $check_file");
} else {
open FILE, "> $check_file" || die ("Could not open $check_file");
}
print FILE "$_[0]\n";
close FILE;
}
my $dir_h;
my $i;
my $is_good;
my $res;
chdir($currentdir) || die("Could not chdir to $currentdir");
opendir($dir_h, $ftp_results_dir) || die("The ftp directory could no be opened");
while( $i=readdir($dir_h)){
$is_good=1;
if ( $i =~ m/^(CGAL-\d+\.\d+-I-\d+)-/ ) {
$cgal_version=$1;
} else {
if ( $i =~ m/^(CGAL-\d+\.\d+\.\d+-I-\d+)-/ ) {
$cgal_version=$1;
} else {
if ( $i =~ m/^(CGAL-\d+\.\d+\.\d+)-/ ) {
$cgal_version=$1;
} else {
if ( $i =~ m/^(CGAL-\d+\.\d+)-/ ) {
$cgal_version=$1;
} else {
# die "$tarname is not a valid name for a testresult collection.\n";
$is_good=0;
}
}
}
}
if ( $is_good == 1 ){
if ( -s "$ftp_results_dir/$i" && exist_in_file($i) == 1 ){
system "cp $ftp_results_dir/$i $i";
system "chmod 644 $i";
$res = system "gunzip -t $i";
system "rm -rf $i";
if ( $res == 0 ){
$tarname=`basename $i .gz`;
chomp $tarname;
make_unpackdir();
eval {unpack_results($i)} && eval{install_results()};
$@ && warn $@;
chdir($unpack_dir_base);
system('rm','-rf',$unpack_dir);
system "./create_testresult_page $cgal_version";
append_to_file($i);
}
}
}
}
closedir($dir_h);