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

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

Envi passes an extra arg, the env_verbosity, to all tasks now. It's passed in as the first parameter. So the diffcol and snapshot tasks have to take it into account

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