Changeset 28114

Show
Ignore:
Timestamp:
21.08.2013 19:58:39 (6 years ago)
Author:
ak19
Message:

The run_test actions takes additional cmdline parameters. The first is nosvn, to reduce copying over time, especially useful on windows. The second is justdiff, which assumes the collections have already been built and you just want to diff them, which is handy when testing the diffing process. Further commandline parameters that work with run_test are any number of specific collections to run the test on, with or without one of nosvn and justdiff specified alongside. This then reduces the svn checkout and file copying and collection building to just the specified collections.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • other-projects/nightly-tasks/diffcol/trunk/task.pl

    r28106 r28114  
    9595#parse arguments 
    9696my $action = "all"; 
    97 if(scalar(@ARGV) > 1) { 
    98     &printusage(); 
    99     exit 0; 
     97my $subaction = ""; # run_test can take subactions: --just_diff and --no_svn 
     98my @collections = (); 
     99 
     100if(scalar(@ARGV) > 1 && $ARGV[0] ne "run_test") { 
     101    &printusage(); 
     102    exit -1; 
    100103} 
    101104 
     
    105108else {     
    106109    switch ($ARGV[0]) { 
    107     case qr/^(-h|-help|help)$/i { &printusage; exit 0; } 
     110    case qr/^(-h|--?help|help)$/i { &printusage; exit 0; } 
    108111    case qr/^(setup_greenstone|run_test|summarise|upload|all)$/ { $action=$ARGV[0]; } 
    109112    else {  
     
    113116    } 
    114117    } 
    115 } 
     118     
     119    # run_test action can take a subaction: nosvn|justdiff.  
     120    # nosvn: uses the model-collect as static and copies it over to collect, rebuilding what's currently in model-collect instead of copying  
     121    # it out from the svn model-collect again. 
     122    # justdiff: same as nosvn, but doesn't copy over model-collection to collect, and doesn't rebuild either of them. Just does the diff part. 
     123    if($action eq "run_test" && scalar(@ARGV) >= 2) { 
     124        push(@collections, @ARGV); 
     125        shift @collections; # remove action from array 
     126         
     127        if($ARGV[1] =~ m@^--@) { 
     128            shift @collections; # remove subaction from array 
     129             
     130            $subaction = $ARGV[1];           
     131            if($subaction eq "--justdiff") { 
     132                $use_local_rebuild = $use_static_model = 1; 
     133            } elsif ($subaction eq "--nosvn") { 
     134                $use_static_model = 1; 
     135            } else { 
     136                print STDERR "Bad subaction.\n";  
     137                &printusage;  
     138                exit -1; 
     139            }            
     140        } 
     141         
     142#       foreach my $col (@collections) { 
     143#           print STDERR "Collection: $col\n"; 
     144#       } 
     145    } 
     146} 
     147 
    116148 
    117149#check key environment vars are set 
     
    206238sub printusage 
    207239{ 
    208     print STDERR "Run as: $0 (help|setup_greenstone|run_test|summarise|upload|all)\n"; 
     240    print STDERR "Run as: $0 (help|setup_greenstone|run_test <--justdiff|--nosvn> <col1 col2 ...> |summarise|upload|all)\n"; 
    209241} 
    210242 
     
    422454# http://stackoverflow.com/questions/3377879/how-do-i-receive-command-output-immediately 
    423455sub run_test 
    424 { 
     456{    
     457    my $num_cols = scalar(@collections); # remember the empty case 
     458     
     459    if($num_cols == 0) { # deal with all collections 
     460        push (@collections, "");  
     461            # putting the empty string in the array so that the "all colleections" case  
     462            # can be handled similarl to how the case of user-specified collections is handled 
     463         
     464    } else { # deal with user specified set of collections 
     465        # prefix the directory separator to each collection name 
     466        @collections = map { $sep.$_ } @collections; 
     467    } 
     468 
    425469    my $pdfbox = &filename_concat($greenstone_home, "ext", "pdf-box"); 
    426470    if(!-d $pdfbox) { 
     
    433477    print $xml_fh "<test time=\"$dateid\" id=\"$dateid\">\n"; 
    434478     
    435     my $cmd; 
     479    my ($cmd, $status); 
    436480    # make sure that diffcol/model-collect is up to date before copying it over to greenstone-home 
    437481     
    438482    if(!$use_local_rebuild) {    
    439483        print $xml_fh "Updating $ENV{'TASK_HOME'}/model-collect:\n"; 
    440         $cmd = "svn up $ENV{'TASK_HOME'}/model-collect"; #chdir("$ENV{'TASK_HOME'}/model-collect"); 
    441         my $status = system "$cmd"; 
     484        for my $col (@collections) { 
     485            $cmd = "svn up $ENV{'TASK_HOME'}/model-collect$col"; #chdir("$ENV{'TASK_HOME'}/model-collect"); 
     486            $status = system "$cmd"; 
     487        } 
    442488    } 
    443489 
     
    452498    print STDERR "done\n"; 
    453499 
    454     #make two copies of the model-collect directory in gsdl 
    455     #one to be rebuilt and one as the basis for comparison 
    456     #strip both of all .svn directories 
    457      
    458     #copy the model collections to the collect folder to be rebuilt 
    459     print STDERR "installing test collections and model collections to new $gsdl installation... "; 
    460  
    461     if(!$use_local_rebuild) {    
     500    if(!$use_local_rebuild) { 
     501         
     502        #make two copies of the model-collect directory in gsdl 
     503        #one to be rebuilt and one as the basis for comparison 
     504        #strip both of all .svn directories 
     505     
     506        #copy the model collections to the collect folder to be rebuilt 
     507        print STDERR "installing test collections and model collections to new $gsdl installation... "; 
     508     
    462509        #clean up 
    463510        if(-d "collect") { 
    464         &File::Path::remove_tree("collect") || die "Error could not delete collect: $!"; 
     511            for my $col (@collections) { 
     512                &File::Path::remove_tree("collect$col") || die "Error could not delete collect: $!";             
     513            }    
    465514        } 
    466515 
    467516        if($use_static_model) {      
    468         #copy to collect and strip .svn subfolders 
    469         &File::Path::make_path("collect"); # create the collect folder and copy contents from static model-collection across 
    470         &copy_recursively("model-collect", "collect", ".svn"); 
     517            for my $col (@collections) {         
     518                #copy to collect and strip .svn subfolders 
     519                &File::Path::make_path("collect$col"); # create the collect folder and copy contents from static model-collection across 
     520                &copy_recursively("model-collect$col", "collect$col", ".svn"); 
     521            }    
    471522 
    472523        } else { # the default situation: where we check out the model-collect from svn 
    473         &File::Path::remove_tree("model-collect"); 
    474          
    475         #copy to collect and strip .svn subfolders 
    476         &File::Path::make_path("collect"); # create the folder and copy contents across 
    477         &copy_recursively(&filename_concat("$ENV{'TASK_HOME'}","model-collect"), "collect", ".svn"); 
    478          
    479         #make the model copy 
    480         &File::Path::make_path("model-collect");  
    481         &copy_recursively("collect", "model-collect"); # copy contents across 
     524            for my $col (@collections) { 
     525                &File::Path::remove_tree("model-collect$col"); 
     526                 
     527                #copy to collect and strip .svn subfolders 
     528                &File::Path::make_path("collect$col"); # create the folder and copy contents across 
     529                &copy_recursively(&filename_concat("$ENV{'TASK_HOME'}","model-collect$col"), "collect$col", ".svn"); 
     530                 
     531                #make the model copy 
     532                &File::Path::make_path("model-collect$col");  
     533                &copy_recursively("collect$col", "model-collect$col"); # copy contents across 
     534            } 
    482535        } 
    483536 
     
    485538    }    
    486539 
    487     #for each collection, import, build and diff with its model counterpart 
    488     opendir my($collect_handle), "collect" or die "Could not open dir $greenstone_home/collect: $!"; 
    489     for my $collection (readdir $collect_handle) { 
    490     next if ($collection eq "." || $collection eq ".."); 
    491     next if ($collection eq "modelcol"); 
    492 #   next if ($collection ne "Section-Tagging"); ## TEMPORARY, FOR TESTING THIS SCRIPT 
    493 #   next if ($collection !~ m/MARC/); ## TEMPORARY, FOR TESTING THIS SCRIPT 
     540    #for each collection, import, build and diff with its model counterpart     
     541     
     542    # if working with all collections, read the list of collections from the folders in collect 
     543    if($num_cols == 0) { 
     544        @collections = (); # get rid of the empty string put in the array to represent "all collections" 
     545         
     546        opendir my($collect_handle), "collect" or die "Could not open dir $greenstone_home/collect: $!"; 
     547     
     548        for my $collection (readdir $collect_handle) { 
     549            next if ($collection eq "." || $collection eq ".."); 
     550            next if ($collection eq "modelcol"); 
     551            push(@collections, $collection);             
     552        } 
     553        closedir $collect_handle; # close handle to collect dir 
     554    } 
     555     
     556    for my $collection (@collections) { 
     557 
     558    #   next if ($collection ne "Demo-Lucene"); ## TEMPORARY, FOR TESTING THIS SCRIPT 
     559    #   next if ($collection !~ m/OAI|METS|DSpace|MGPP|Lucene/); ## TEMPORARY, FOR TESTING THIS SCRIPT 
    494560 
    495561    #escape the filename (in case of space) 
    496562    $collection =~ s@ @\\ @g; 
    497563    #getting just the basename of the collection would have been necessary had we not cd-ed into $gsdl 
    498  
     564     
     565    $collection =~ s@^[\\/]@@g; # take the dir-sep prefix away again for user-specified collection names 
     566     
     567    if (! -d "collect$sep$collection") { 
     568        print STDERR "Collection $collection does not exist\n"; 
     569        next; 
     570    } 
     571     
    499572    print STDERR "*** Found collection $collection\n"; 
    500573    print $xml_fh "<collection-test name=\"$collection\">\n"; 
     
    538611    print $xml_fh "</collection-test>\n"; 
    539612    } 
    540     closedir $collect_handle; # close handle to collect dir 
    541613 
    542614    print $xml_fh "</test>\n";