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

Last change on this file since 27668 was 27668, checked in by kjdon, 11 years ago

task.pl works for windows now, except for the upload/emailing function. Diffcol still has several issues.

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