Changeset 27628 for other-projects
- Timestamp:
- 2013-06-14T19:47:30+12:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
other-projects/nightly-tasks/diffcol/trunk/task.pl
r27621 r27628 6 6 # For windows, need to REMEMBER to set the correct shebangs at the top 7 7 8 package diffcoltask; 8 9 9 10 use Cwd; 11 use Switch; # for switch(val) { case: ; ...} 10 12 use File::Path; # for rmdir and mkdir type functions 11 13 use File::Copy; # for recursive copying of folders but skipping .svn 12 14 use File::Basename; 13 15 16 use strict; 17 no strict 'subs'; # allow barewords (eg STDERR) as function arguments 14 18 15 19 my $isWin = ($^O =~ m/mswin/i) ? 1 : 0; … … 27 31 $ENV{'UPLOAD_DIR'} = filename_concat($ENV{'TASK_HOME'}, "diffcol-reports"); 28 32 $ENV{'MONITOR_EMAIL'} = "greenstone_team\@cs.waikato.ac.nz"; # need to escape @ sign 33 $ENV{'GSDL_SMTP'} = ""; 29 34 ##print STDERR "@@@ email: ".$ENV{'MONITOR_EMAIL'}."\n"; 30 35 … … 35 40 #export GSDL3SRCHOME= 36 41 42 43 44 #parse arguments 45 my $action = "all"; 46 if(scalar(@ARGV) > 1) { 47 &printusage(); 48 exit 0; 49 } 50 51 if(scalar(@ARGV) == 0) { 52 $action="all"; 53 } 54 else { 55 switch ($ARGV[0]) { 56 case qr/^(-h|-help|help)$/i { &printusage; exit 0; } 57 case qr/^(setup_greenstone|run_test|summarise|upload|all)$/ { $action=$ARGV[0]; } 58 else { 59 print STDERR "Bad subcommand.\n"; 60 &printusage; 61 exit -1; 62 } 63 } 64 } 65 37 66 #check key environment vars are set 38 67 if(!defined $ENV{'UPLOAD_DIR'}) { … … 56 85 print STDOUT "DATA_DIR: ".$ENV{'DATA_DIR'}."\n"; 57 86 print STDOUT "UPLOAD_DIR: ".$ENV{'UPLOAD_DIR'}."\n"; 58 59 87 60 88 #create an id for this test … … 74 102 ##print STDERR "@@@ $jar_lib_path\n"; 75 103 my @files = <$jar_lib_path/*.jar>; # /full/path/to/diffcol/lib/*jar 76 foreach $file (@files) {104 foreach my $file (@files) { 77 105 $ENV{'CLASSPATH'}=$file.$pathsep.$ENV{'CLASSPATH'}; 78 106 } … … 101 129 ##print STDERR "GSHOME: $greenstone_home\n"; 102 130 103 #&setup_greenstone; 104 &run_test; 105 &summarise; 106 &upload; 131 #do the requested action 132 if($action eq "setup_greenstone") { 133 &setup_greenstone; 134 } 135 elsif ($action eq "run_test") { 136 &run_test; 137 } 138 elsif ($action eq "summarise") { 139 &summarise; 140 } 141 elsif ($action eq "upload") { 142 &upload; 143 &mail_with_report_attached; 144 } 145 elsif ($action eq "all") { 146 &setup_greenstone; 147 &run_test; 148 &summarise; 149 &upload; 150 &mail_with_report_attached; 151 } 107 152 108 153 ##******************************** 109 154 155 sub printusage 156 { 157 print STDERR "Run as: $0 (help|setup_greenstone|run_test|summarise|upload|all)\n"; 158 } 110 159 111 160 … … 115 164 { 116 165 #clean up from previous tests 117 print STD OUT"about to clean up any old tests (Ctrl-C to cancel)"; # no newline166 print STDERR "about to clean up any old tests (Ctrl-C to cancel)"; # no newline 118 167 for my $i ( 1..5 ) { 119 168 sleep 1; # 1 second 120 print STD OUT".";121 } 122 print STD OUT"\n";169 print STDERR "."; 170 } 171 print STDERR "\n"; 123 172 124 173 # http://perldoc.perl.org/File/Path.html … … 298 347 print STDOUT "$collection - Importing:\n"; 299 348 print $xml_fh "<import>\n"; 300 $cmd = "import.pl -OIDtype hash_on_full_filename $collection -removeold"; 301 &run_build_script($cmd); 349 # $cmd = "import.pl -OIDtype hash_on_full_filename $collection -removeold"; 350 # &run_build_script($cmd); 351 $cmd = "bash -c \"export GSDLHOME=&& source $setup_script.bash && import.pl -OIDtype hash_on_full_filename -removeold $collection\""; 352 system($cmd); 302 353 print $xml_fh "</import>\n"; 303 354 print STDOUT "done\n"; … … 306 357 print STDOUT "$collection - Building:\n"; 307 358 print $xml_fh "<build>\n"; 308 $cmd = "buildcol.pl $collection -removeold"; 309 &run_build_script($cmd); 359 # $cmd = "buildcol.pl $collection -removeold"; 360 # &run_build_script($cmd); 361 $cmd = "bash -c \"export GSDLHOME=&& source $setup_script.bash && buildcol.pl -removeold $collection\""; 362 system($cmd); 310 363 print $xml_fh "</build>\n"; 311 364 print STDOUT "done\n"; … … 370 423 return &run_and_print_cmd($cmd, $fh); 371 424 } 372 #ERROR (36096) running bash -c "export GSDLHOME=&& source setup.bash && buildcol.pl Small-HTML -removeold": Illegal seek373 425 374 426 … … 475 527 } 476 528 477 478 # TO DO:479 529 # Sending emails with perl: http://learn.perl.org/examples/email.html 480 530 # Sending email attachments with perl: http://www.perlmonks.org/?node_id=19430 481 531 # Sadly none of the packages are installed by default and use of MIME::Lite is discouraged 532 sub mail_with_report_attached 533 { 534 # email out with report attached, if the tests failed 535 print STDOUT "Checking if successful... \n"; 536 my $cmd = "java org.apache.xalan.xslt.Process -IN $xmlout -XSL $ENV{'TASK_HOME'}/xsl/passed-or-not.xsl"; 537 #my $result = system($cmd); 538 my $result = `$cmd`; 539 540 print STDOUT "result: $result\n"; 541 542 if($result ne "yes") { 543 my $msg = "$gsdl regression test for $dateid failed"; 544 my $subject = "Regression Test Failed"; #"$gsdl regression test for $dateid failed\n"; 545 my $attach_file = &filename_concat($ENV{'DATA_DIR'}, "report-$dateid.html"); 546 547 if($isWin) { 548 # http://stackoverflow.com/questions/709635/sending-mail-from-batch-file 549 #blat -to [email protected] -server smtp.example.com -f [email protected] -subject "subject" -body "body" 550 551 $cmd = "blat -to $ENV{'MONITOR_EMAIL'} -server $ENV{'GSDL_SMTP'} -f $attach_file -subject $subject -body $msg"; # need to install blat on windows 552 553 } else { 554 my $status = system("command -v mutt > /dev/null 2>&1;"); #better way of doing "which mutt" 555 556 if($status != 0) { # mutt doesn't exist, can't send attachments, so send simple email 557 $cmd="echo '$gsdl regression test for $dateid failed.' | mail -s 'Regression Test Failed' $ENV{'MONITOR_EMAIL'}"; 558 559 print STDERR "********************************************\n"; 560 print STDERR "No mutt installed, unable to mail attachment\n"; 561 print STDERR "Inspect report at: $attach_file\n"; 562 print STDERR "********************************************\n"; 563 } else { 564 #$cmd = "bash -c \"echo '$gsdl regression test for $dateid failed' | mutt -a $attach_file -s 'Regression Test Failed' -- $ENV{'MONITOR_EMAIL'}\""; 565 $cmd = "echo '$gsdl regression test for $dateid failed' | mutt -a $attach_file -s 'Regression Test Failed' -- $ENV{'MONITOR_EMAIL'}"; 566 } 567 } 568 569 # run the mail command 570 system($cmd); # &run_and_print_cmd($cmd); 571 572 print STDOUT "Sent mail with report attached.\n"; 573 } else { 574 print STDERR "********************************************\n"; 575 print STDOUT "Tests were successful. Not sending mail.\n"; 576 print STDERR "********************************************\n"; 577 } 578 } 482 579 483 580 # The old version of this program contained the following, consisting of 1 line of active code:
Note:
See TracChangeset
for help on using the changeset viewer.