source: other-projects/nightly-tasks/diffcol/trunk/task.pl@ 27667

Last change on this file since 27667 was 27667, checked in by ak19, 11 years ago

Another change to not be linux/mac specific, so that the diffcol task will support windows

  • Property svn:executable set to *
File size: 22.3 KB
Line 
1#!/usr/bin/perl -w
2
3# This program is meant to run the nightly diffcol
4# It is meant to be an equivalent for the existing task bash script
5# But it is intended to be expanded to work for Windows and GS3
6# For windows, need to REMEMBER to set the correct shebangs at the top
7
8
9# TODO:
10# Have a caveat mode and a stable mode (as in snapshot/task.pl)
11#
12#} elsif ( $ENV{'TASK_NAME'} =~ "gs2-diffcol-(caveat|stable)" ) {
13# $major_version = 2;
14# $prefix="2t";
15# $rk="tk2"; # test kit
16#} elsif ( $ENV{'TASK_NAME'} =~ "gs3-diffcol-(caveat|stable)" ) {
17# $major_version = 3;
18# $prefix="3t";
19# $rk="tk3"; # test kit
20
21package diffcoltask;
22
23use Cwd;
24use Switch; # for switch(val) { case: ; ...}
25use File::Path; # for rmdir and mkdir type functions
26use File::Copy; # for recursive copying of folders but skipping .svn
27use File::Basename;
28
29use strict;
30no strict 'subs'; # allow barewords (eg STDERR) as function arguments
31
32my $isWin = ($^O =~ m/mswin/i) ? 1 : 0;
33my $sep = $isWin ? "\\" : "/";
34my $pathsep = $isWin ? ";" : ":";
35#my $script_ext = $isWin ? ".bat" : ".bash";
36my $setup_script = "setup"; # needs to become gs3-setup for GS3
37
38# TASK_HOME should be the toplevel diffcol folder
39$ENV{'TASK_HOME'} = getcwd unless defined $ENV{'TASK_HOME'};
40## print STDERR "@@@ TASK_HOME: ".$ENV{'TASK_HOME'}."\n";
41
42
43$ENV{'DATA_DIR'} = filename_concat($ENV{'TASK_HOME'}, "diffcol-data");
44$ENV{'UPLOAD_DIR'} = filename_concat($ENV{'TASK_HOME'}, "diffcol-reports");
45$ENV{'MONITOR_EMAIL'} = "greenstone_team\@cs.waikato.ac.nz"; # need to escape @ sign
46$ENV{'GSDL_SMTP'} = "";
47##print STDERR "@@@ email: ".$ENV{'MONITOR_EMAIL'}."\n";
48
49# control if an existing compiled greenstone is used
50# or, if one should be checked out, which revision to checkout from svn
51$ENV{'SVN_OPT_REV'} = "-r head";
52#$ENV{'GSDLHOME'}=
53#$ENV{'GSDL3SRCHOME'}=
54
55
56
57#parse arguments
58my $action = "all";
59if(scalar(@ARGV) > 1) {
60 &printusage();
61 exit 0;
62}
63
64if(scalar(@ARGV) == 0) {
65 $action="all";
66}
67else {
68 switch ($ARGV[0]) {
69 case qr/^(-h|-help|help)$/i { &printusage; exit 0; }
70 case qr/^(setup_greenstone|run_test|summarise|upload|all)$/ { $action=$ARGV[0]; }
71 else {
72 print STDERR "Bad subcommand.\n";
73 &printusage;
74 exit -1;
75 }
76 }
77}
78
79#check key environment vars are set
80if(!defined $ENV{'UPLOAD_DIR'}) {
81 print STDERR "Please set a UPLOAD_DIR for the test in an environment.sh file\n";
82 #return 1;
83}
84if(!defined $ENV{'DATA_DIR'}) {
85 print STDERR "Please set a DATA_DIR for the test in an environment.sh file\n";
86 #return 1;
87}
88if(!defined $ENV{'MONITOR_EMAIL'}) {
89 print STDERR "Please set a MONITOR_EMAIL for the test in an environment.sh file\n";
90 #return 1;
91}
92
93if($ENV{'DATA_DIR'} eq "/") {
94 print STDERR "DATA_DIR should not be the fs root\n";
95 #return 1;
96}
97
98print STDERR "DATA_DIR: ".$ENV{'DATA_DIR'}."\n";
99print STDERR "UPLOAD_DIR: ".$ENV{'UPLOAD_DIR'}."\n";
100
101#create an id for this test
102my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
103$year += 1900;
104$mon += 1;
105$mon = "0$mon" if ($mon < 10);
106$mday = "0$mday" if ($mday < 10);
107my $dateid="$year-$mon-$mday"; #my $dateid=($year+1900)."-".($mon+1)."-$mday";
108
109print STDERR "Starting test '$dateid'\n";
110
111
112# http://stackoverflow.com/questions/2149368/how-can-i-loop-through-files-in-a-directory-in-perl
113$ENV{'CLASSPATH'} = "";
114my $jar_lib_path = $ENV{'TASK_HOME'}.$sep."lib";
115my @files = <$jar_lib_path/*.jar>; # /full/path/to/diffcol/lib/*jar
116foreach my $file (@files) {
117 $ENV{'CLASSPATH'}=$file.$pathsep.$ENV{'CLASSPATH'};
118}
119##print STDERR "**** classpath: ".$ENV{'CLASSPATH'}."\n";
120
121
122#set the location of the full report
123my $xmlout=filename_concat($ENV{'DATA_DIR'}, "full-report-$dateid.xml");
124##print STDERR "XML: $xmlout\n";
125
126# the toplevel folder of the greenstone installation being used
127my $greenstone_home="";
128# gsdl is the checkout folder and can be greenstone2 or greenstone3
129my $gsdl="greenstone2";
130
131
132# Check if using existing compiled-up greenstone installation
133# and set the greenstone_home location accordingly
134
135if(defined $ENV{'GSDL3SRCHOME'} || defined $ENV{'GSDLHOME'}) {
136 print STDERR "Found existing Greenstone home, will use that instead\n";
137 $greenstone_home=$ENV{'GSDLHOME'};
138} else {
139 $greenstone_home=filename_concat($ENV{'DATA_DIR'}, $gsdl);
140}
141##print STDERR "GSHOME: $greenstone_home\n";
142
143#do the requested action
144if($action eq "setup_greenstone") {
145 &setup_greenstone;
146}
147elsif ($action eq "run_test") {
148 &run_test;
149}
150elsif ($action eq "summarise") {
151 &summarise;
152}
153elsif ($action eq "upload") {
154 &upload;
155 &mail_with_report_attached;
156}
157elsif ($action eq "all") {
158 &setup_greenstone;
159 &run_test;
160 &summarise;
161 &upload;
162 &mail_with_report_attached;
163}
164
165##********************************
166
167sub printusage
168{
169 print STDERR "Run as: $0 (help|setup_greenstone|run_test|summarise|upload|all)\n";
170}
171
172
173#http://stackoverflow.com/questions/7427262/read-a-file-and-save-it-in-variable-using-shell-script
174
175sub setup_greenstone
176{
177 #clean up from previous tests
178 print STDERR "about to clean up any old tests (Ctrl-C to cancel)"; # no newline
179 for my $i ( 1..5 ) {
180 sleep 1; # 1 second
181 print STDERR ".";
182 }
183 print STDERR "\n";
184
185 # http://perldoc.perl.org/File/Path.html
186 print STDERR "cleaning up previous tests\n";
187 &File::Path::remove_tree($ENV{'DATA_DIR'});
188
189 print STDERR "creating the data dir\n";
190 &File::Path::make_path($ENV{'DATA_DIR'}); # works like mkdir -p
191
192 chdir($ENV{'DATA_DIR'});
193
194 # use existing compiled-up greenstone installation, if a GSDLHOME set
195 if(defined $ENV{'GSDL3SRCHOME'} || defined $ENV{'GSDLHOME'}) {
196 print STDERR "Found existing Greenstone home, will use that instead";
197 return;
198 }
199
200 # Else checkout a GS from svn into DATA_DIR
201
202 #svn checkout of main gsdl directory
203 print STDERR "checkout $gsdl:\n";
204 my $cmd = "svn co ".$ENV{'SVN_OPT_REV'}." http://svn.greenstone.org/main/trunk/greenstone2 $gsdl";
205 ##print STDERR "Checkout CMD: $cmd\n";
206
207 # # unlike backticks operator, system() will print the output of the command to the screen as it executes
208 # http://stackoverflow.com/questions/758611/how-to-flush-output-in-backticks-in-perl?rq=1
209 my $status = system "$cmd"; #my $status = `$cmd`;
210 print STDERR "done\n";
211
212 ##print STDERR "$ENV{'DATA_DIR'}$sep$gsdl\n";
213
214 chdir("$ENV{'DATA_DIR'}$sep$gsdl");
215
216 ##print STDERR "@@@ OS: $^O.|".$Config{'archname64'}."|\n";
217
218 # if we're on linux/darwin, need gnome-lib for the correct architecture.
219 if(!$isWin) {
220
221 print STDERR "setting up gnome-lib-minimal for compilation\n";
222
223 # To get gnome-lib, need to determine bit architecture of the linux/darwin
224 # http://stackoverflow.com/questions/8963400/the-correct-way-to-read-a-data-file-into-an-array
225 # $Config{'archname64'} doesn't work on the Ubuntu and the Sys::Info package seems to not be supported
226 # well on ActivePerl.
227 # But since we know we're on a Linux/Darwin machine at this point, wecan just run `uname -m` and other linux cmds
228
229 my $gnome_lib_file = ($^O =~ m/macos/i) ? "darwin-intel" : "linux"; # assuming all darwin is intel, not ppc!!
230
231 my $bit_arch=`uname -m`;
232 $gnome_lib_file .= "-x64" if($bit_arch =~ m/64$/);
233
234 #svn checkout gnome-lib for this linux/darwin
235 chdir("$ENV{'DATA_DIR'}$sep$gsdl$sep"."ext"); #cd $DATA_DIR/$gsdl/ext
236
237 ##print STDERR "**** gnomelib: $gnome_lib_file\n";
238
239 # checkout and unpack gnome-lib-minimal
240
241 #svn export http://svn.greenstone.org/gs2-extensions/gnome-lib/trunk/gnome-lib-minimal-linux-x64.tar.gz gl.tar.gz
242 $cmd = "svn export http://svn.greenstone.org/gs2-extensions/gnome-lib/trunk/gnome-lib-minimal-".$gnome_lib_file.".tar.gz gl.tar.gz";
243 system $cmd;
244 system ("tar -xvzf gl.tar.gz");
245
246 chdir("gnome-lib-minimal");
247 ##print STDERR "*** ARCH: $bit_arch\n";
248
249 # need to run source devel.bash on gnome-lib followed by configure, make, make install
250 # in one go, in order to preserve the compile environment set up by sourcing devel.bash
251
252 # http://stackoverflow.com/questions/7369145/activating-a-virtualenv-using-a-shell-script-doesnt-seem-to-work
253 # http://ubuntuforums.org/showthread.php?t=1932504 linking /bin/sh to bash instead of dash
254
255# $cmd = "bash -c \"source ./devel.bash && cd ../.. && ./configure --enable-apache-httpd && make && make install\"";
256 $cmd = "bash -c \"";
257
258 $cmd .= "source ./devel.bash";
259 $cmd .= " && cd ../..";
260
261 #configure
262 # $cmd .= " && ./configure";
263 $cmd .= " && echo 'configure $gsdl: ' ";
264 $cmd .= " && echo '<configure>' >> $xmlout";
265 $cmd .= " && ./configure 2>> $ENV{'DATA_DIR'}/compilation-errors"; # configure
266 $cmd .= " && echo '</configure>' >> $xmlout";
267 $cmd .= " && echo 'done'";
268
269 #make
270 $cmd .= " && echo 'make $gsdl: '";
271 $cmd .= " && echo '<make>' >> $xmlout";
272 $cmd .= " && make 2>> $ENV{'DATA_DIR'}/compilation-errors"; # make
273 $cmd .= " && echo '</make>' >> $xmlout";
274 $cmd .= " && echo 'done'";
275
276 #make install
277 $cmd .= " && echo 'make install $gsdl: '";
278 $cmd .= " && echo '<make-install>' >> $xmlout";
279 $cmd .= " && make install 2>> $ENV{'DATA_DIR'}/compilation-errors"; # make install
280 $cmd .= " && echo '</make-install>' >> $xmlout";
281 $cmd .= " && echo 'done'";
282
283 $cmd .= "\""; # close off cmd to bash and run it
284 system $cmd;
285 }
286
287 # set the path to the greenstone_home variable
288 $greenstone_home="$ENV{'DATA_DIR'}$sep$gsdl";
289
290}
291
292# http://stackoverflow.com/questions/3377879/how-do-i-receive-command-output-immediately
293sub run_test
294{
295 open (my $xml_fh, '>'.$xmlout) || die "Could not open xml file $xmlout for appending: $!\n";
296
297 # perform the requested subcommands, outputting xml information
298 print $xml_fh "<test time=\"$dateid\" id=\"$dateid\">\n";
299
300 # make sure that diffcol/model-collect is up to date before copying it over to greenstone-home
301 print $xml_fh "Updating $ENV{'TASK_HOME'}/model-collect:\n";
302 my $cmd = "svn up $ENV{'TASK_HOME'}/model-collect"; #chdir("$ENV{'TASK_HOME'}/model-collect");
303 my $status = system "$cmd";
304
305 # go to whichever greenstone_home we're using
306 chdir($greenstone_home);
307
308 # get svn info
309 print STDERR "getting svn info: $xmlout\n";
310 print $xml_fh "<svn-info>\n";
311 run_and_print_cmd("svn info", $xml_fh);
312 print $xml_fh "</svn-info>\n";
313 print STDERR "done\n";
314
315 #make two copies of the model-collect directory in gsdl
316 #one to be rebuilt and one as the basis for comparison
317 #strip both of all .svn directories
318
319 #copy the model collections to the collect folder to be rebuilt
320 print STDERR "installing test collections and model collections to new $gsdl installation... ";
321
322 #clean up
323 if(-d "collect") {
324 &File::Path::remove_tree("collect") || die "Error could not delete collect: $!";
325 }
326 &File::Path::remove_tree("model-collect");
327
328 #copy to collect and strip .svn subfolders
329 &File::Path::make_path("collect"); # create the folder and copy contents across
330 &copy_recursively(&filename_concat("$ENV{'TASK_HOME'}","model-collect"), "collect", ".svn");
331
332 #make the model copy
333 &File::Path::make_path("model-collect");
334 &copy_recursively("collect", "model-collect"); # copy contents across
335
336 print STDERR "done\n";
337
338
339 #for each collection, import, build and diff with its model counterpart
340 opendir my($collect_handle), "collect" or die "Could not open dir $greenstone_home/collect: $!";
341 for my $collection (readdir $collect_handle) {
342 next if ($collection eq "." || $collection eq "..");
343 ##next if ($collection ne "Small-HTML"); ## TEMPORARY, FOR TESTING THIS SCRIPT
344
345 #escape the filename (in case of space)
346 $collection =~ s@ @\\ @g;
347 #getting just the basename of the collection would have been necessary had we not cd-ed into $gsdl
348
349 print STDERR "*** Found collection $collection\n";
350 print $xml_fh "<collection-test name=\"$collection\">\n";
351
352 #import
353# Ensure the OIDtype for importing is hash_on_full_filename
354# "to make document identifiers more stable across upgrades of the software,
355# although it means that duplicate documents contained in the collection are
356# no longer detected automatically."
357 print STDERR "$collection - Importing:\n";
358 print $xml_fh "<import>\n";
359 &run_build_script("import.pl -OIDtype hash_on_full_filename $collection -removeold");
360 print $xml_fh "</import>\n";
361 print STDERR "done\n";
362
363 #build
364 print STDERR "$collection - Building:\n";
365 print $xml_fh "<build>\n";
366 &run_build_script("buildcol.pl $collection -removeold");
367 print $xml_fh "</build>\n";
368 print STDERR "done\n";
369
370 #rename the intermediate 'building' directory 'index'
371 print STDERR "$collection - Move \"building\" to \"index\"... ";
372 my $index = &filename_concat("collect", $collection, "index");
373 my $building = &filename_concat("collect", $collection, "building");
374 &File::Path::remove_tree($index);
375 # Renaming Directories, http://www.perlmonks.org/?node_id=177421
376 move($building, $index) or die "copy failed: $!"; # File::Copy::move
377 print STDERR "done\n";
378
379 #diffcol
380 print STDERR "$collection - Diffing:\n";
381 my $diffcol_dir = &filename_concat($ENV{'TASK_HOME'},"diffcol");
382 $cmd = "diffcol.pl -output xml -verbosity 10 $collection"; # need to run with ./diffcol.pl if bash script
383 &run_diff_script($cmd, $xml_fh, $diffcol_dir);
384
385 chdir($greenstone_home); # this is actually where we are
386 print STDERR "done\n";
387 print $xml_fh "</collection-test>\n";
388 }
389 closedir $collect_handle; # close handle to collect dir
390
391 print $xml_fh "</test>\n";
392 close($xml_fh);
393
394 print STDERR "done\n";
395}
396
397##***************************************************************
398# runs setup in greenstone_home before running the diff command
399sub run_diff_script {
400 my ($cmd, $fh, $diffcol_dir) = @_;
401
402 # we're in greenstone_home now
403 if(!$isWin) {
404 $cmd = "bash -c \"export GSDLHOME=&& source $setup_script.bash && cd $diffcol_dir && ./$cmd\"";
405
406 } else { # Need to prefix cmd -c/-k as necessary
407 $cmd = "cd $greenstone_home && set GSDLHOME=&& source $setup_script.bat && cd $diffcol_dir && $cmd";
408 }
409
410 return &run_and_print_cmd($cmd, $fh);
411}
412
413# runs setup in greenstone_home before running the given build command
414sub run_build_script {
415 my ($cmd, $fh) = @_;
416
417# chdir($greenstone_home);
418
419 # we are in $greenstone_home, can directly run the build cmd on the collection
420 if(!$isWin) {
421 $cmd = "bash -c \"export GSDLHOME=&& source $setup_script.bash && $cmd\"";
422
423 } else { # Need to prefix cmd -c/-k as necessary
424 $cmd = "set GSDLHOME=&& source $setup_script.bat && $cmd";
425 }
426
427 return system($cmd);
428 #return &run_and_print_cmd($cmd, $fh); # doesn't work on cmds chained with bash -c
429}
430
431
432# http://stackoverflow.com/questions/758611/how-to-flush-output-in-backticks-in-perl?rq=1activeperl%20sys::info
433# http://stackoverflow.com/questions/1477500/how-do-i-get-the-output-of-an-external-command-in-perl
434sub run_and_print_cmd {
435 my ($cmd, $fh) = @_;
436
437 open my $pin, "$cmd|" or die "unable to run cmd $cmd: $!"; # open(my $fh, '-|', 'powercfg -l') or die $!;
438
439 if(defined $fh) { # print cmd output both to the filehandle and to stdout
440 while (my $line = <$pin>) {
441 print $fh $line;
442# print STDOUT $line; # if also printing cmd output to STDOUT
443 }
444 }
445 else { # no filehandle, so just need to print to stdout
446
447 # unlike backticks operator, system() will print the output of the command to the screen as it executes
448 # http://stackoverflow.com/questions/758611/how-to-flush-output-in-backticks-in-perl?rq=1
449
450 my $status = system $cmd;
451 if($status != 0) {
452 print STDERR "ERROR ($status) running $cmd: $!\n";
453 }
454 }
455 close($pin);
456}
457
458sub filename_concat {
459 my $first_file = shift(@_);
460 my (@filenames) = @_;
461
462 # If first_file is not null or empty, then add it back into the list
463 if (defined $first_file && $first_file =~ /\S/)
464 {
465 unshift(@filenames, $first_file);
466 }
467
468 my $filename = join($sep, @filenames);
469 $filename =~ s/[\\\/]$//; # remove trailing slashes if any
470 return $filename;
471}
472
473
474# The following code is from
475# http://stackoverflow.com/questions/227613/how-can-i-copy-a-directory-recursively-and-filter-filenames-in-perl
476# It also states that "Perl's File::Copy is a bit broken (it doesn't copy permissions on Unix systems, for example)"
477sub copy_recursively {
478 my ($from_dir, $to_dir, $regex) = @_;
479 opendir my($dh), $from_dir or die "Could not open dir '$from_dir': $!";
480
481# if(-d !$to_dir) {
482# mkdir $to_dir or die "mkdir '$to_dir' failed: $!" if not -e $to_dir;
483# }
484
485 for my $entry (readdir $dh) {
486 next if ($entry eq "." || $entry eq "..");
487 next if (defined $regex && $entry =~ /$regex/);
488 my $source = "$from_dir/$entry";
489 my $destination = "$to_dir/$entry";
490 if (-d $source) {
491 mkdir $destination or die "mkdir '$destination' failed: $!" if not -e $destination;
492 copy_recursively($source, $destination, $regex);
493 } else {
494 copy($source, $destination) or die "copy failed: $!";
495 }
496 }
497 closedir $dh;
498 return;
499}
500
501sub summarise {
502
503 # make a summarised Xml report
504 print STDERR "Summarizing the xml report... ";
505 my $cmd = "java org.apache.xalan.xslt.Process -IN $xmlout -XSL $ENV{'TASK_HOME'}/xsl/xml-report.xsl -OUT $ENV{'DATA_DIR'}/report-$dateid.xml";
506 my $status = system($cmd);
507 print STDERR "done\n";
508
509 # make a summarised HTMl report
510 print STDERR "Creating an html summary report... ";
511 $cmd = "java org.apache.xalan.xslt.Process -IN $ENV{'DATA_DIR'}/report-$dateid.xml -XSL $ENV{'TASK_HOME'}/xsl/html-report.xsl -OUT $ENV{'DATA_DIR'}/report-$dateid.html";
512 $status = system($cmd);
513 print STDERR "done\n";
514}
515
516sub upload {
517 # if the upload dir already existed, clear it of contents
518 if (-d $ENV{'UPLOAD_DIR'}) { #else rm $UPLOAD_DIR/*
519 # don't want to keep previous days reports
520 # else we will have to manually clear them at some point
521 # just generate the set of reports for this run of task.pl upload
522 # and
523 &File::Path::remove_tree($ENV{'UPLOAD_DIR'});
524 }
525 # recreate the upload directory
526 &File::Path::make_path($ENV{'UPLOAD_DIR'});
527
528 # copy all *.xml and *.html files across to UPLOAD_DIR
529 opendir my($dh), $ENV{'DATA_DIR'} or die "Could not open DATA_DIR: $!";
530 for my $entry (readdir $dh) {
531 next if ($entry !~ m/(\.xml|\.html)$/);
532 # get the absolute path to the files before copying them over
533 $entry = &filename_concat($ENV{'DATA_DIR'}, $entry);
534 copy($entry, $ENV{'UPLOAD_DIR'});
535 }
536 closedir $dh;
537
538
539 # Upload the html file to puka
540 #default identity dir
541 if ( ! exists $ENV{'IDENTITY_DIR'} ) {
542 $ENV{'IDENTITY_DIR'} = "$ENV{'HOME'}${sep}.ssh";
543 }
544 if (! exists $ENV{'SNAPSHOT_MODE'} ) {
545 $ENV{'SNAPSHOT_MODE'} = "caveat";
546 }
547
548 #use the correct key for uploading
549 $ENV{'IDENTITY_FILE'} = "$ENV{'IDENTITY_DIR'}${sep}upload-" . $ENV{'SNAPSHOT_MODE'} . ($^O eq "MSWin32" ? ".ppk" : "");
550 if(-f $ENV{'IDENTITY_FILE'}) {
551 # the report we want to upload is actually just report-$dateid.html
552 my $command = "cd \"$ENV{'UPLOAD_DIR'}\" && tar -c *.html | "; #&& cat *.html | "; # && tar -c * |
553 $command .= ($^O eq "MSWin32" ? "plink" : "ssh");
554 $command .= " -T -i \"$ENV{'IDENTITY_FILE'}\" nzdl\@puka.cs.waikato.ac.nz";
555 #print "$command\n";
556 my $status = system("$command");
557 if($status != 0) {
558 print STDERR "*** Failed to upload test report to nzdl\n";
559 }
560 } else {
561 print STDERR "*** Cannot upload the test report to nzdl from this machine\n";
562 }
563
564 print STDERR "Finished uploading\n";
565}
566
567# Sending emails with perl: http://learn.perl.org/examples/email.html
568# Sending email attachments with perl: http://www.perlmonks.org/?node_id=19430
569# Sadly none of the packages are installed by default and use of MIME::Lite is discouraged
570sub mail_with_report_attached
571{
572 # email out with report attached, if the tests failed
573 print STDERR "Checking if successful... \n";
574 my $cmd = "java org.apache.xalan.xslt.Process -IN $xmlout -XSL $ENV{'TASK_HOME'}/xsl/passed-or-not.xsl";
575 #my $result = system($cmd);
576 my $result = `$cmd`;
577
578 print STDERR "result: $result\n";
579
580 if($result ne "yes") {
581 my $msg = "$gsdl regression test for $dateid failed";
582 my $subject = "Regression Test Failed"; #"$gsdl regression test for $dateid failed\n";
583 my $attach_file = &filename_concat($ENV{'DATA_DIR'}, "report-$dateid.html");
584
585 if($isWin) {
586 # http://stackoverflow.com/questions/709635/sending-mail-from-batch-file
587 #blat -to [email protected] -server smtp.example.com -f [email protected] -subject "subject" -body "body"
588
589 $cmd = "blat -to $ENV{'MONITOR_EMAIL'} -server $ENV{'GSDL_SMTP'} -f $attach_file -subject $subject -body $msg"; # need to install blat on windows
590
591 } else {
592 my $status = system("command -v mutt > /dev/null 2>&1;"); #better way of doing "which mutt"
593
594 if($status != 0) { # mutt doesn't exist, can't send attachments, so send simple email
595 $cmd="echo '$gsdl regression test for $dateid failed.' | mail -s 'Regression Test Failed' $ENV{'MONITOR_EMAIL'}";
596
597 print STDERR "********************************************\n";
598 print STDERR "No mutt installed, unable to mail attachment\n";
599 print STDERR "Inspect report at: $attach_file\n";
600 print STDERR "********************************************\n";
601 } else {
602 #$cmd = "bash -c \"echo '$gsdl regression test for $dateid failed' | mutt -a $attach_file -s 'Regression Test Failed' -- $ENV{'MONITOR_EMAIL'}\"";
603 $cmd = "echo '$gsdl regression test for $dateid failed' | mutt -a $attach_file -s 'Regression Test Failed' -- $ENV{'MONITOR_EMAIL'}";
604 }
605 }
606
607 # run the mail command
608 $result = system($cmd); #&run_and_print_cmd($cmd);
609 if($result != 0) {
610 print STDERR "*** Unable to send email: $?\n";
611 }
612 else {
613 print STDERR "Sent mail with report attached.\n";
614 }
615 } else {
616 print STDERR "********************************************\n";
617 print STDERR "Tests were successful. Not sending mail.\n";
618 print STDERR "********************************************\n";
619 }
620}
621
622# The old version of this program contained the following, consisting of 1 line of active code:
623
624 # Invoke as: sjmc@br:/research/sjm84/envi/bin$ ./envi diffcol summarise
625 # Doing so will call this pl file and pass in "summarise" in ARGV
626 # This pl file will in turn call the task executable in this folder
627 # passing in "summarise" as a parameter.
628#system("/bin/bash -c \"../etc/tasks/diffcol/task @ARGV\"");
629
630 ##system("/bin/bash -c \"./task @ARGV\"");
631 ##print STDERR "/bin/bash -c ../etc/tasks/diffcol/task @ARGV"
Note: See TracBrowser for help on using the repository browser.