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

Last change on this file since 29398 was 29398, checked in by ak19, 9 years ago
  1. There's always a deprecation warning on the switch statement used in task.pl. Replaced with plain if-else block. 2. The perl version found by diffcol is written out to the xml version of the report (not the html version). This may help in detecting new changes.
  • Property svn:executable set to *
File size: 42.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;
24#use 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
32
33my $isWin = ($^O =~ m/mswin/i) ? 1 : 0;
34my $isMac = ($^O =~ m/macos|darwin/i) ? 1 : 0;
35
36my $osversion="";
37# Need to get the correct gnome-lib-minimal for the OS
38# darwin11* Lion, darwin12* Mountain Lion, darwin9* and darwin10* are Leopard and Snow Leopard
39if ($^O eq "darwin") {
40 $osversion=`uname -r`; # e.g. 12.x.x
41 #$osversion =~ s@\..*$@@; # e.g.12
42 $osversion = ($osversion =~ m@^1[1-9](\.)?@i) ? "Lion-" : "";
43}
44
45
46my $sep = $isWin ? "\\" : "/";
47my $pathsep = $isWin ? ";" : ":";
48#my $script_ext = $isWin ? ".bat" : ".bash";
49my $setup_script = "setup"; # will become gs3-setup for GS3
50my $use_blat = 0; # if we ever get blat to send mail/attachments on Windows working, set this to 1
51
52my $install_type = "svn";
53my $install_version = "2";
54
55my $use_local_rebuild = 0; # set to 1 (true) if just diffing and so we needn't copy model-collection over to the test collection again nor rebuild it (This is useful when having built the collection locally once before)
56my $use_static_model = 0; # set to 1 (true) if working with a non-svn model-collection. Defaults to 1 if $use_local_rebuild is turned on
57
58# if use_local_rebuild is on, use_static_model should be on
59if ($use_local_rebuild && !$use_static_model) {
60 $use_static_model = 1;
61}
62
63my $test_os = $isWin ? "windows" : ($isMac ? "darwin" : "linux");
64my $model_os = "linux"; # default
65
66# TASK_HOME should be the toplevel diffcol folder
67$ENV{'TASK_HOME'} = getcwd unless defined $ENV{'TASK_HOME'};
68if($isWin) {
69 $ENV{'TASK_HOME'} =~ s@\/@\\@g;
70 # need to convert TASK_HOME path name to resolve very subtle bug when running task.pl via
71 # run-gs2-diffcol.bat which uses environment.pl's TASK_HOME setting via envi
72 # At that point TASK_HOME is already defined but ends up lowercase, so that entries in archiveinf-doc
73 # end up sorted differently when db2txt -sort is applied compared to if TASK_HOME had kept its case.
74 require Win32; # for working out Windows Long Filenames from Win 8.3 short filenames
75 $ENV{'TASK_HOME'} = &Win32::GetLongPathName($ENV{'TASK_HOME'});
76}
77## print STDERR "@@@ TASK_HOME: ".$ENV{'TASK_HOME'}."\n";
78
79
80$ENV{'BIN_DIR'} = &filename_concat($ENV{'TASK_HOME'}, "bin");
81
82# we'll be using BLAT to send mail attachments on Windows
83my $blat = $use_blat ? &filename_concat($ENV{'BIN_DIR'}, "blat", "full", "blat.exe") : 0;
84if($isWin && $use_blat && ! -e $blat) {
85 print STDERR "\n***********************************\n";
86 print STDERR "No blat.exe found in $blat.\n";
87 print STDERR "Blat needed to send mail with attachments on Windows.\n";
88 print STDERR "Extract the blat zip file found in $ENV{'BIN_DIR'}\n";
89 print STDERR "for your bit architecture and name the folder 'blat'\n";
90 print STDERR "***********************************\n\n";
91 $blat = 0;
92}
93
94
95$ENV{'DATA_DIR'} = &filename_concat($ENV{'TASK_HOME'}, "diffcol-data");
96$ENV{'UPLOAD_DIR'} = &filename_concat($ENV{'TASK_HOME'}, "diffcol-reports");
97$ENV{'MONITOR_EMAIL'} = "greenstone_team\@cs.waikato.ac.nz"; # need to escape @ sign
98$ENV{'GSDL_SMTP'} = ""; #"smtp.gmail.com";
99##print STDERR "@@@ email: ".$ENV{'MONITOR_EMAIL'}."\n";
100
101# control if an existing compiled greenstone is used
102# or, if one should be checked out, which revision to checkout from svn
103$ENV{'SVN_OPT_REV'} = "-r head";
104#$ENV{'GSDLHOME'}=
105#$ENV{'GSDL3SRCHOME'}=
106
107
108# if the first arg is a digit, it's the new envi verbosity param. Take it off the array
109my $envi_verbose = shift(@ARGV) if(exists $ARGV[0] && $ARGV[0] =~ m/^\d+$/);
110
111#parse arguments
112my $action = "all";
113my $subaction = ""; # run_test can take subactions: --just_diff and --no_svn
114my @collections = (); # list of collections that run_test should process
115
116if(scalar(@ARGV) == 0) {
117 $action="all";
118}
119
120# process any arguments that are --gs2|--gs3 and --bin|--svn, and delete them from the array
121# if none provided, it's gs2 and svn by default.
122for (my $i = $#ARGV; $i >= 0; --$i) {
123 if($ARGV[$i] =~ m/--(bin|svn)/) {
124 $install_type = $1;
125 splice @ARGV, $i, 1; # remove the element from the argument array
126 } elsif($ARGV[$i] =~ m/--gs(2|3)/) {
127 $install_version = $1;
128 $setup_script = $install_version eq "3" ? "gs3-setup" : "setup"; # needs to become gs3-setup for GS3
129 splice @ARGV, $i, 1; # remove the element from the argument array
130 }
131}
132
133
134# run_test can take any number of args
135if(scalar(@ARGV) > 1 && $ARGV[0] ne "run_test") {
136 print STDERR "**** Wrong number of arguments\n";
137 &printusage();
138 exit -1;
139}
140
141if(scalar(@ARGV) > 0) {
142 #switch ($ARGV[0]) {
143 #case qr/^(-h|--?help|help)$/i { &printusage; exit 0; }
144 #case qr/^(setup_greenstone|run_test|summarise|upload|all)$/ { $action=$ARGV[0]; }
145 #else {
146 #print STDERR "**** Bad subcommand.\n";
147 #&printusage;
148 #exit -1;
149 #}
150 #}
151
152
153 my $switch = $ARGV[0];
154 if($switch =~ m/^(-h|--?help|help)$/i) {
155 &printusage;
156 exit 0;
157 } elsif ($switch =~ m/^(setup_greenstone|run_test|summarise|upload|all)$/) {
158 $action=$ARGV[0];
159 } else {
160 print STDERR "**** Bad subcommand.\n";
161 &printusage;
162 exit -1;
163 }
164
165 # run_test action can take a subaction: nosvn|justdiff. It can also take --modelOS (windows|linux|darwin)
166 # nosvn: uses the model-collect as static and copies it over to collect, rebuilding what's currently in model-collect instead of copying
167 # it out from the svn model-collect again.
168 # 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.
169
170 if($action eq "run_test" && scalar(@ARGV) >= 2) {
171 push(@collections, @ARGV);
172 shift @collections; # remove action from array
173
174 for (my $i=0; $i < scalar(@ARGV); $i++) {
175 if($ARGV[$i] =~ m@^--@) {
176 shift @collections; # remove subaction/flag from array
177
178 $subaction = $ARGV[$i];
179 if($subaction eq "--justdiff") {
180 $use_local_rebuild = $use_static_model = 1;
181 } elsif ($subaction eq "--nosvn") {
182 $use_static_model = 1;
183 #} elsif ($subaction =~ m/\-\-testOS/i && defined $ARGV[$i+1]) {
184 # $test_os = $ARGV[$i+1];
185 # $i++;
186 # shift @collections; # remove test_os value from array
187 } elsif ($subaction =~ m/\-\-modelOS/i && defined $ARGV[$i+1] && $ARGV[$i+1] =~ m/windows|linux|darwin/i) {
188 $model_os = $ARGV[$i+1];
189 $i++;
190 shift @collections; # remove model_os value from array
191 #print STDERR "Model_os specified: $model_os\n";
192 } else {
193 print STDERR "**** Bad subaction/value: ".$ARGV[$i]."\n";
194 &printusage;
195 exit -1;
196 }
197 }
198 }
199
200# foreach my $col (@collections) {
201# print STDERR "Collection: $col\n";
202# }
203 }
204}
205
206print STDERR "Install type $install_type\n";
207print STDERR "Install version $install_version\n";
208
209#check key environment vars are set
210if(!defined $ENV{'UPLOAD_DIR'}) {
211 print STDERR "Please set a UPLOAD_DIR for the test in an environment.sh file\n";
212 #return 1;
213}
214if(!defined $ENV{'DATA_DIR'}) {
215 print STDERR "Please set a DATA_DIR for the test in an environment.sh file\n";
216 #return 1;
217}
218if(!defined $ENV{'MONITOR_EMAIL'}) {
219 print STDERR "Please set a MONITOR_EMAIL for the test in an environment.sh file\n";
220 #return 1;
221}
222
223if($ENV{'DATA_DIR'} eq "/") {
224 print STDERR "DATA_DIR should not be the fs root\n";
225 #return 1;
226}
227
228print STDERR "DATA_DIR: ".$ENV{'DATA_DIR'}."\n";
229print STDERR "UPLOAD_DIR: ".$ENV{'UPLOAD_DIR'}."\n";
230
231#create an id for this test
232my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
233$year += 1900;
234$mon += 1;
235$mon = "0$mon" if ($mon < 10);
236$mday = "0$mday" if ($mday < 10);
237my $dateid="$year.$mon.$mday"; #my $dateid=($year+1900)."-".($mon+1)."-$mday";
238
239print STDERR "Starting test '$dateid'\n";
240
241
242# http://stackoverflow.com/questions/2149368/how-can-i-loop-through-files-in-a-directory-in-perl
243$ENV{'CLASSPATH'} = "";
244my $jar_lib_path = $ENV{'TASK_HOME'}.$sep."lib";
245my @files = <$jar_lib_path/*.jar>; # /full/path/to/diffcol/lib/*jar
246foreach my $file (@files) {
247 $file =~ s@\/@\\@g if $isWin;
248 $ENV{'CLASSPATH'}=$file.$pathsep.$ENV{'CLASSPATH'};
249}
250##print STDERR "**** classpath: ".$ENV{'CLASSPATH'}."\n";
251
252
253#set the location of the full report
254my $xmlout=filename_concat($ENV{'DATA_DIR'}, "full-report-$install_version-$dateid.xml");
255##print STDERR "XML: $xmlout\n";
256
257# the toplevel folder of the greenstone installation being used
258my $greenstone3_home="";
259my $greenstone_home=""; # gs2build for gs3, toplevel install folder for gs2
260# gsdl is the checkout folder and can be greenstone2 or greenstone3
261my $gsdl="greenstone2";
262
263# Check if using existing compiled-up greenstone installation
264# and set the greenstone_home location accordingly
265
266if(defined $ENV{'GSDL3SRCHOME'} || defined $ENV{'GSDLHOME'}) {
267 print STDERR "Found existing Greenstone home, will use that instead\n";
268 $greenstone_home=$ENV{'GSDLHOME'} if defined $ENV{'GSDLHOME'};
269
270 if(defined $ENV{'GSDL3SRCHOME'}) {
271 print STDERR "*** GSDL3SRCHOME set, changing to using installed GS3\n";
272 $gsdl = "greenstone3";
273 $install_version = "3";
274 $greenstone3_home=$ENV{'GSDL3SRCHOME'};
275 $greenstone_home=filename_concat($greenstone3_home, "gs2build") unless defined $ENV{'GSDLHOME'};
276 }
277} else {
278 if($install_version eq "3") {
279 $gsdl = "greenstone3";
280 $greenstone3_home=filename_concat($ENV{'DATA_DIR'}, $gsdl);
281 $greenstone_home=filename_concat($greenstone3_home, "gs2build");
282 } else {
283 $greenstone_home=filename_concat($ENV{'DATA_DIR'}, $gsdl);
284 }
285}
286##print STDERR "GSHOME: $greenstone_home\n";
287
288#do the requested action
289if($action eq "setup_greenstone") {
290 &setup_greenstone;
291}
292elsif ($action eq "run_test") {
293 &run_test;
294}
295elsif ($action eq "summarise") {
296 &summarise;
297}
298elsif ($action eq "upload") {
299 &upload;
300 &mail_with_report_attached;
301}
302elsif ($action eq "all") {
303 &setup_greenstone;
304 &run_test;
305 &summarise;
306 &upload;
307 &mail_with_report_attached;
308}
309
310##********************************
311
312sub printusage
313{
314# print STDERR "Run as: $0 (help|setup_greenstone|run_test <--modelOS windows|darwin|linux> <--justdiff|--nosvn> <col1 col2 ...> |summarise|upload|all)\n";
315 print STDERR "Run as: $0 (help|setup_greenstone|run_test|summarise|upload|all)\n";
316 print STDERR "where run_test can further take the following optional parameters:\n";
317 print STDERR "\t--modelOS (windows|darwin|linux)\n";
318 print STDERR "\t--justdiff|--nosvn\n";
319 print STDERR "\t<col1 col2 ...>\n";
320 print STDERR "where setup_greenstone can further take the following optional parameters:\n";
321 print STDERR "\t--gs2|--gs3\n";
322 print STDERR "\t--svn|--bin\n";
323}
324
325#http://stackoverflow.com/questions/7427262/read-a-file-and-save-it-in-variable-using-shell-script
326
327sub setup_greenstone
328{
329 if($install_version eq "3" && !defined $ENV{'JAVA_HOME'}) {
330 print "*** JAVA_HOME not set. Set it and add its bin folder to the PATH\n";
331 exit 0;
332 }
333
334 #clean up from previous tests
335 print STDERR "about to clean up any old tests (Ctrl-C to cancel)"; # no newline
336 for my $i ( 1..5 ) {
337 sleep 1; # 1 second
338 print STDERR ".";
339 }
340 print STDERR "\n";
341
342 # http://perldoc.perl.org/File/Path.html
343 print STDERR "cleaning up previous tests\n";
344 #&File::Path::remove_tree($ENV{'DATA_DIR'});
345 if(-d $greenstone_home && $install_version eq "2") {
346 &File::Path::remove_tree($greenstone_home);
347 }
348 if(-d $greenstone3_home && $install_version eq "3") {
349 &File::Path::remove_tree($greenstone3_home);
350 }
351 unlink glob "$ENV{'DATA_DIR'}$sep"."*report-$install_version*";
352 unlink "$ENV{'DATA_DIR'}$sep"."compilation-errors";
353 print STDERR "creating the data dir\n";
354 #&File::Path::make_path($ENV{'DATA_DIR'}); # works like mkdir -p
355
356 chdir($ENV{'DATA_DIR'});
357
358 # use existing compiled-up greenstone installation, if a GSDLHOME set
359 if(defined $ENV{'GSDL3SRCHOME'} || defined $ENV{'GSDLHOME'}) {
360 print STDERR "Found existing Greenstone home, will use that instead\n";
361 return;
362 }
363
364 # Else checkout a GS from svn into DATA_DIR
365 if($install_type eq "svn") {
366 &checkout_gs_from_svn();
367 ##print STDERR "$ENV{'DATA_DIR'}$sep$gsdl\n";
368
369 if($install_version eq "2") {
370 &compile_gs2_svn();
371 } else {
372 &compile_gs3_svn();
373 }
374 }
375
376}
377
378sub checkout_gs_from_svn {
379
380 #svn checkout of main gsdl directory
381 print STDERR "checkout $gsdl:\n";
382 my $cmd = "svn co ".$ENV{'SVN_OPT_REV'}." http://svn.greenstone.org/main/trunk/greenstone$install_version $gsdl";
383 ##print STDERR "Checkout CMD: $cmd\n";
384
385 # # unlike backticks operator, system() will print the output of the command to the screen as it executes
386 # http://stackoverflow.com/questions/758611/how-to-flush-output-in-backticks-in-perl?rq=1
387 my $status = system "$cmd"; #my $status = `$cmd`;
388 if($status != 0) {
389 print STDERR "@@@ SVN checkout of $gsdl failed\n";
390 exit -1;
391 }
392 print STDERR "done\n";
393}
394
395sub getImageMagickBins {
396 my ($cmd, $status);
397 my $imagickzip = "";
398
399 chdir ("$greenstone_home");
400 if(!$isWin) { # if we're on linux/darwin, need gnome-lib for the correct architecture. And need imagemagick to build imgs in collections
401
402 my $bit_arch=`uname -m`;
403
404 # imagemagick binary
405 print STDERR "Getting imagemagick binary\n";
406
407 my $os = $isMac ? "darwin" : "linux";
408 $imagickzip = "imagemagick-$os";
409
410 if($isMac) {
411# $imagickzip .= "-10.5.tar.gz";
412 # at present, only the Imagemagick binaries created by Max for darwin work on the Macs
413# &File::Path::make_path("$greenstone_home$sep"."bin"."$sep$os"); # need to ensure gsdl/bin/darwin exists
414 $cmd = "svn export http://svn.greenstone.org/main/trunk/binaries/mac/intel/imagemagick bin/darwin/imagemagick";
415 $status = system($cmd);
416 if($status != 0) {
417 print STDERR "@@@ Unable to get imagemagick for darwin\n";
418 }
419
420 # need ghostscript mac binary too for pdf to img conversions on mac
421 $cmd = "svn export http://svn.greenstone.org/main/trunk/binaries/mac/intel/ghostscript bin/darwin/ghostscript";
422 $status = system($cmd);
423 if($status != 0) {
424 print STDERR "@@@ Unable to get ghostscript for darwin\n";
425 }
426
427 # the imagemagick and ghostscript binaries have been set to executable on svn trac now
428# system("chmod -R u+x $greenstone_home/bin/darwin/imagemagick/bin/*");
429# system("chmod -R u+x $greenstone_home/bin/darwin/ghostscript/bin/*");
430 } else { # linux
431 my $extension64 = ($bit_arch =~ m/64$/) ? "-x64" : "";
432 $imagickzip .= "$extension64.tar.gz";
433
434 # now these next imagemagick steps (and those near the end of this sub) are just for linux, no longer also for mac
435 $cmd = "svn export http://svn.greenstone.org/gs2-extensions/imagemagick/trunk/$imagickzip ext/$imagickzip";
436 $status = system ($cmd);
437 system("cd ext && tar -xvzf $imagickzip");
438 }
439 }
440 return $imagickzip;
441}
442
443sub getGnomeLibExt
444{
445 my ($cmd, $status);
446 my $bit_arch=`uname -m`;
447 my $os = $isMac ? "darwin" : "linux";
448
449 # gnomelib binary
450 print STDERR "setting up gnome-lib-minimal for compilation\n";
451
452 # To get gnome-lib, need to determine bit architecture of the linux/darwin
453 # http://stackoverflow.com/questions/8963400/the-correct-way-to-read-a-data-file-into-an-array
454 # $Config{'archname64'} doesn't work on the Ubuntu and the Sys::Info package seems to not be supported
455 # well on ActivePerl.
456 # But since we know we're on a Linux/Darwin machine at this point, we can just run `uname -m` and other linux cmds
457
458 # osversion will be "Lion" or ""
459 # and assuming all darwin is intel, not ppc!!
460 my $gnome_lib_file = $isMac ? "darwin-".$osversion."intel" : "linux";
461
462 $gnome_lib_file .= "-x64" if($bit_arch =~ m/64$/ && !$isMac); # linux only case
463
464 #svn checkout gnome-lib for this linux/darwin
465 chdir("$greenstone_home$sep"."ext"); #cd $DATA_DIR/$gsdl/ext
466
467 ##print STDERR "**** gnomelib: $gnome_lib_file\n";
468
469 # checkout and unpack gnome-lib-minimal
470
471 #svn export http://svn.greenstone.org/gs2-extensions/gnome-lib/trunk/gnome-lib-minimal-linux-x64.tar.gz gl.tar.gz
472 $cmd = "svn export http://svn.greenstone.org/gs2-extensions/gnome-lib/trunk/gnome-lib-minimal-".$gnome_lib_file.".tar.gz gl.tar.gz";
473 system $cmd;
474 system ("tar -xvzf gl.tar.gz");
475
476 ##print STDERR "*** ARCH: $bit_arch\n";
477}
478
479
480
481sub compile_gs3_svn() {
482 my ($cmd, $status);
483 chdir ("$greenstone3_home");
484
485 $cmd = "ant"; # creates the build.properties file from the .in template
486 $status = system $cmd;
487 if($status != 0) {
488 print STDERR "Unable to run the ant command: $status\n";
489 exit -1;
490 }
491
492 $cmd = "ant -Dproperties.ok=y -Dcheckout.gnomelib.ext=true prepare"; # pass in confirmation to ant prepare step
493 $status = system $cmd;
494 if($status != 0) {
495 print STDERR "Failed to run $cmd command: $status\n";
496 exit -1;
497 }
498
499 my $imagickzip = &getImageMagickBins();
500 chdir ("$greenstone3_home");
501
502 $cmd = "ant -Dcheckout.gnomelib.ext=true install"; # Compile with gnome-lib.
503 $status = system $cmd;
504 if($status != 0) {
505 print STDERR "Failed to run $cmd command: $status\n";
506 exit -1;
507 }
508}
509
510sub compile_gs2_svn() {
511 my $imagickzip = &getImageMagickBins();
512 &getGnomeLibExt();
513
514 my ($cmd, $status);
515 my $os = $isMac ? "darwin" : "linux";
516
517 chdir("$greenstone_home"); #chdir("$ENV{'DATA_DIR'}$sep$gsdl"); # goes into toplevel gs2 or gs3 folder
518
519 ##print STDERR "@@@ OS: $^O.|".$Config{'archname64'}."|\n";
520
521 if($isWin) {
522 print STDERR "Compiling $gsdl using makegs2.bat running in auto (silent) mode\n";
523
524 # we're now in the GS2 folder, call makegs2 with silent param
525 $cmd = "makegs2.bat silent 2>> $ENV{'DATA_DIR'}/compilation-errors"; # STDERR is sent to compilation-errors file
526 $status = system $cmd;
527 if($status != 0) {
528 print STDERR "Greenstone compilation on Windows failed\n";
529 exit -1;
530 }
531
532 } else { # if we're on linux/darwin, need gnome-lib for the correct architecture. And need imagemagick to build imgs in collections
533
534 chdir("ext$sep"."gnome-lib-minimal");
535
536 # need to run source devel.bash on gnome-lib followed by configure, make, make install
537 # in one go, in order to preserve the compile environment set up by sourcing devel.bash
538
539 # http://stackoverflow.com/questions/7369145/activating-a-virtualenv-using-a-shell-script-doesnt-seem-to-work
540 # http://ubuntuforums.org/showthread.php?t=1932504 linking /bin/sh to bash instead of dash
541
542# $cmd = "bash -c \"source ./devel.bash && cd ../.. && ./configure --enable-apache-httpd && make && make install\"";
543 $cmd = "bash -c \"";
544
545 $cmd .= "source ./devel.bash";
546 $cmd .= " && cd ../..";
547
548 #configure
549 # $cmd .= " && ./configure";
550 $cmd .= " && echo 'configure $gsdl: ' ";
551 $cmd .= " && echo '<configure>' >> $xmlout";
552 $cmd .= " && ./configure 2>> $ENV{'DATA_DIR'}/compilation-errors"; # configure
553 $cmd .= " && echo '</configure>' >> $xmlout";
554 $cmd .= " && echo 'done'";
555
556 #make
557 $cmd .= " && echo 'make $gsdl: '";
558 $cmd .= " && echo '<make>' >> $xmlout";
559 $cmd .= " && make 2>> $ENV{'DATA_DIR'}/compilation-errors"; # make
560 $cmd .= " && echo '</make>' >> $xmlout";
561 $cmd .= " && echo 'done'";
562
563 #make install
564 $cmd .= " && echo 'make install $gsdl: '";
565 $cmd .= " && echo '<make-install>' >> $xmlout";
566 $cmd .= " && make install 2>> $ENV{'DATA_DIR'}/compilation-errors"; # make install
567 $cmd .= " && echo '</make-install>' >> $xmlout";
568 $cmd .= " && echo 'done'";
569
570 $cmd .= "\""; # close off cmd to bash and run it
571 $status = system $cmd;
572
573 if(!$isMac) { # Linux
574 # Moving imagemagick after instead of before compilation, since bin/darwin and bin/linux gets overwritten during compilation
575 move("$greenstone_home$sep"."ext/imagemagick/$os", "$greenstone_home$sep"."bin/$os/imagemagick"); # http://www.perlmonks.org/?node_id=586537
576 unlink "$greenstone_home$sep"."ext$sep$imagickzip" or warn "Could not unlink ext/$imagickzip: $!";
577 &File::Path::remove_tree("$greenstone_home$sep"."ext$sep"."imagemagick"); # the untarred parent folder
578 }
579
580 }
581
582 if($status != 0) {
583 print STDERR "@@@ Compilation of Greenstone on Linux/Mac failed\n";
584 exit -1;
585 }
586
587 &getIsisGdl("$greenstone_home"); #&getIsisGdl("$ENV{'DATA_DIR'}/$gsdl");
588
589 # set the path to the greenstone_home variable
590 #$greenstone_home="$ENV{'DATA_DIR'}$sep$gsdl";
591}
592
593sub getPDFBox
594{
595 # current revision is 27763, but using "head" works
596 my $PDFBOX_TRAC_URL="http://trac.greenstone.org/export/head/gs2-extensions/pdf-box/trunk/pdf-box-java"; # both for .zip and .tar.gz extension
597 #"http://trac.greenstone.org/export/".$ENV{'SVN_OPT_REV'}."/gs2-extensions/pdf-box/trunk/pdf-box-java";
598
599 # now get the PDFBox extension for PDFBox tutorial
600 print STDERR "Getting pdfbox from $PDFBOX_TRAC_URL:\n";
601
602 chdir($greenstone_home);
603 my $cmd = "";
604 if ($isWin) {
605 $cmd = "setup.bat && cd ext && wget $PDFBOX_TRAC_URL.zip && unzip pdf-box-java.zip";
606
607 } elsif ($isMac) { # need to use curl not wget
608 $cmd = "cd ext && curl $PDFBOX_TRAC_URL.tar.gz > pdf-box-java.tar.gz && tar -xzf pdf-box-java.tar.gz";
609 }
610 else { # linux
611 $cmd = "bash -c \"export GSDLHOME=&& source setup.bash && cd ext && wget $PDFBOX_TRAC_URL.tar.gz && tar -xzf pdf-box-java.tar.gz\"";
612 }
613 my $status = system $cmd;
614 if($status != 0) {
615 print STDERR "@@@ Failed to set up PDFBox\n";
616 exit -1; # or proceed to testing other tutorials?
617 }
618}
619
620sub getOpenOfficeExt
621{
622 # current revision is 27763, but using "head" works
623 my $OOEXT_TRAC_URL="http://trac.greenstone.org/export/head/gs2-extensions/open-office/trunk/open-office-java"; # both for .zip and .tar.gz extension
624 #"http://trac.greenstone.org/export/".$ENV{'SVN_OPT_REV'}."/gs2-extensions/open-office/trunk/open-office-java";
625
626 # now get the OpenOffice extension for the AllDocTypes collection
627 print STDERR "Getting open office ext from $OOEXT_TRAC_URL:\n";
628
629 chdir($greenstone_home);
630 my $cmd = "";
631 if ($isWin) {
632 $cmd = "setup.bat && cd ext && wget $OOEXT_TRAC_URL.zip && unzip open-office-java.zip";
633
634 } elsif ($isMac) { # need to use curl not wget
635 $cmd = "cd ext && curl $OOEXT_TRAC_URL.tar.gz > open-office-java.tar.gz && tar -xzf open-office-java.tar.gz";
636 }
637 else { # linux
638 $cmd = "bash -c \"export GSDLHOME=&& source setup.bash && cd ext && wget $OOEXT_TRAC_URL.tar.gz && tar -xzf open-office-java.tar.gz\"";
639 }
640 my $status = system $cmd;
641 if($status != 0) {
642 print STDERR "@@@ Failed to set up the Open Office Extension\n";
643 exit -1; # or proceed to testing other tutorials?
644 }
645}
646
647sub getIsisGdl {
648 my $gsfolder = shift(@_);
649
650 if(!$isWin) {
651 chdir($greenstone_home);
652 my $bit_arch=`uname -m`;
653 if ($bit_arch =~ m/64$/) {
654 my $cmd = "";
655 if($isMac) {
656 $cmd = "cd $gsfolder/bin/darwin && curl http://www.greenstone.org/caveat-emptor/IsisGdl.macleopard > IsisGdl && chmod u+x IsisGdl";
657 } else { # linux
658 $cmd = "cd $gsfolder/bin/linux && wget http://www.greenstone.org/caveat-emptor/IsisGdl.bin32 && mv IsisGdl.bin32 IsisGdl && chmod u+x IsisGdl";
659 }
660 my $isis_status = system $cmd;
661 if($isis_status != 0) {
662 print STDERR "Unable to get IsisGdl from caveat page\n";
663 }
664 }
665 }
666}
667
668# http://stackoverflow.com/questions/3377879/how-do-i-receive-command-output-immediately
669sub run_test
670{
671 my $collect_parent = $greenstone_home;
672 my $model_collect = "model-collect";
673 my $build_options = "";
674 if($install_version eq "3") {
675 $collect_parent = &filename_concat($greenstone3_home,"web","sites","localsite");
676 $model_collect = "gs3-model-collect";
677 $build_options = " -site localsite ";
678 chdir($greenstone3_home);
679 } else {
680 chdir($greenstone_home);
681 }
682
683 my $num_cols = scalar(@collections); # remember the empty case
684
685 if($num_cols == 0) { # deal with all collections
686 push (@collections, "");
687 # putting the empty string in the array so that the "all collections" case
688 # can be handled similar to how the case of user-specified collections is handled
689
690 } else { # deal with user specified set of collections
691 # prefix the directory separator to each collection name
692 @collections = map { $sep.$_ } @collections;
693 }
694
695 my $pdfbox = &filename_concat($greenstone_home, "ext", "pdf-box");
696 if(!-d $pdfbox) {
697 &getPDFBox();
698 }
699
700 my $openofficeext = &filename_concat($greenstone_home, "ext", "open-office");
701 if(!-d $openofficeext) {
702 &getOpenOfficeExt();
703 }
704
705 #&getIsisGdl("$greenstone_home");
706
707 open (my $xml_fh, '>'.$xmlout) || die "Could not open xml file $xmlout for appending: $!\n";
708
709 # perform the requested subcommands, outputting xml information
710 print $xml_fh "<test time=\"$dateid\" id=\"$dateid\">\n";
711
712 my ($cmd, $status);
713 # make sure that diffcol/model-collect is up to date before copying it over to greenstone-home
714
715 if(!$use_local_rebuild) {
716 print $xml_fh "Updating $ENV{'TASK_HOME'}/$model_collect:\n";
717 for my $col (@collections) {
718 $cmd = "svn up $ENV{'TASK_HOME'}/$model_collect$col"; #chdir("$ENV{'TASK_HOME'}/$model_collect");
719 $status = system "$cmd";
720 }
721 }
722
723 # go to whichever collecthome parent we're using
724 chdir($collect_parent);
725
726 # get svn info
727 print STDERR "getting svn info: $xmlout\n";
728 print $xml_fh "<svn-info>\n";
729 &run_and_print_cmd("svn info", $xml_fh);
730 print $xml_fh "</svn-info>\n";
731 print STDERR "done\n";
732
733 if(!$use_local_rebuild) {
734
735 #make two copies of the model-collect directory in gsdl
736 #one to be rebuilt and one as the basis for comparison
737 #strip both of all .svn directories
738
739 #copy the model collections to the collect folder to be rebuilt
740 print STDERR "installing test collections and model collections to new $gsdl installation... ";
741 #clean up
742 if(-d "collect") {
743 for my $col (@collections) {
744 if(-d "collect$col") {
745 &File::Path::remove_tree("collect$col") || die "Error could not delete collect: $!";
746 }
747 }
748 }
749
750 if($use_static_model) {
751 for my $col (@collections) {
752 #copy to collect and strip .svn subfolders
753 &File::Path::make_path("collect$col"); # create the collect folder and copy contents from static model-collection across
754 &copy_recursively("model-collect$col", "collect$col", ".svn");
755 }
756
757 } else { # the default situation: where we check out the model-collect from svn
758 for my $col (@collections) {
759 &File::Path::remove_tree("model-collect$col");
760
761 #copy to collect and strip .svn subfolders
762 &File::Path::make_path("collect$col"); # create the folder and copy contents across
763 &copy_recursively(&filename_concat("$ENV{'TASK_HOME'}","$model_collect$col"), "collect$col", ".svn");
764
765 #make the model copy
766 &File::Path::make_path("model-collect$col");
767 &copy_recursively("collect$col", "model-collect$col"); # copy contents across
768 }
769 }
770
771 print STDERR "done\n";
772 }
773
774 #for each collection, import, build and diff with its model counterpart
775
776 # if working with all collections, read the list of collections from the folders in collect
777 if($num_cols == 0) {
778 @collections = (); # get rid of the empty string put in the array to represent "all collections"
779
780 opendir my($collect_handle), "collect" or die "Could not open dir $collect_parent/collect: $!";
781
782 for my $collection (readdir $collect_handle) {
783 next if ($collection eq "." || $collection eq "..");
784 next if ($collection eq "modelcol");
785 push(@collections, $collection);
786 }
787 closedir $collect_handle; # close handle to collect dir
788 }
789
790 for my $collection (@collections) {
791
792 # next if ($collection ne "Demo-Lucene"); ## TEMPORARY, FOR TESTING THIS SCRIPT
793 # next if ($collection !~ m/OAI|METS|DSpace|MGPP|Lucene/); ## TEMPORARY, FOR TESTING THIS SCRIPT
794
795 #escape the filename (in case of space)
796 $collection =~ s@ @\\ @g;
797 #getting just the basename of the collection would have been necessary had we not cd-ed into $gsdl
798
799 $collection =~ s@^[\\/]@@g; # take the dir-sep prefix away again for user-specified collection names
800
801 if (! -d "collect$sep$collection") {
802 print STDERR "Collection $collection does not exist\n";
803 next;
804 }
805
806 print STDERR "*** Found collection $collection\n";
807 print $xml_fh "<collection-test name=\"$collection\">\n";
808
809 # run the building scripts from the toplevel of the GS installation
810 if($install_version eq "3") {
811 chdir($greenstone3_home);
812 } else {
813 chdir($greenstone_home);
814 }
815
816 if(!$use_local_rebuild) {
817 #import
818 # Ensure the OIDtype for importing is hash_on_full_filename
819 # "to make document identifiers more stable across upgrades of the software,
820 # although it means that duplicate documents contained in the collection are
821 # no longer detected automatically."
822 print STDERR "$collection - Importing:\n";
823 print $xml_fh "<import>\n";
824 &run_build_script("import.pl $build_options -removeold $collection"); #-OIDtype hash_on_full_filename
825 print $xml_fh "</import>\n";
826 print STDERR "done\n";
827
828 #build
829 print STDERR "$collection - Building:\n";
830 print $xml_fh "<build>\n";
831 &run_build_script("buildcol.pl $build_options -removeold $collection");
832 print $xml_fh "</build>\n";
833 print STDERR "done\n";
834
835 #rename the intermediate 'building' directory 'index'
836 print STDERR "$collection - Move \"building\" to \"index\"... ";
837 my $index = &filename_concat($collect_parent, "collect", $collection, "index");
838 my $building = &filename_concat($collect_parent, "collect", $collection, "building");
839 &File::Path::remove_tree($index);
840 # Renaming Directories, http://www.perlmonks.org/?node_id=177421
841 move($building, $index) or die "copy failed: $!"; # File::Copy::move
842 print STDERR "done\n";
843 }
844 #diffcol
845 print STDERR "$collection - Diffing:\n";
846 my $diffcol_dir = &filename_concat($ENV{'TASK_HOME'},"diffcol");
847
848# chdir($collect_parent); # this is actually where we are
849 # help diffcol to know on what os the model cols were generated
850 # and what os this test machine is (on which the test cols will be generated)
851 $cmd = "diffcol.pl -testos $test_os -modelos $model_os -output xml -verbosity 10 $collection"; # need to run with ./diffcol.pl if bash script
852 &run_diff_script($cmd, $xml_fh, $diffcol_dir);
853
854 if($install_version eq "3") {
855 chdir($greenstone3_home); # this is actually where we are
856 } else {
857 chdir($greenstone_home); # this is actually where we are
858 }
859 print STDERR "done\n";
860 print $xml_fh "</collection-test>\n";
861 }
862
863 print $xml_fh "</test>\n";
864 close($xml_fh);
865
866 print STDERR "done\n";
867}
868
869##***************************************************************
870# runs setup in greenstone_home before running the diff command
871sub run_diff_script {
872 my ($cmd, $fh, $diffcol_dir) = @_;
873
874 my $linux_ext = ($install_version eq "3") ? "sh" : "bash";
875
876 # we're in greenstone_home now
877 if(!$isWin) {
878 $cmd = "bash -c \"export GSDL3SRCHOME=&& export GSDLHOME=&& source $setup_script.$linux_ext && cd $diffcol_dir && ./$cmd\"";
879
880 } else { # Need to prefix cmd -c/-k as necessary
881 $cmd = "cmd /c \"set GSDL3SRCHOME=&& set GSDLHOME=&& $setup_script.bat && cd $diffcol_dir && perl -S $cmd\"";
882## print STDERR "@@@@ Going to call command: $cmd\n";
883 }
884
885 return &run_and_print_cmd($cmd, $fh);
886}
887
888# runs setup in greenstone_home before running the given build command
889sub run_build_script {
890 my ($cmd, $fh) = @_;
891 my $linux_ext = ($install_version eq "3") ? "sh" : "bash";
892
893# chdir($greenstone_home);
894 # we are in $greenstone_home already, can directly run the build cmd on the collection
895 if(!$isWin) {
896 $cmd = "bash -c \"export GSDL3SRCHOME=&& export GSDLHOME=&& source $setup_script.$linux_ext && $cmd\"";
897
898 } else { # Need to prefix cmd -c/-k as necessary
899 $cmd = "cmd /c \"set GSDL3SRCHOME=&& set GSDLHOME=&& $setup_script.bat && perl -S $cmd\"";
900 }
901## print STDERR "@@@@ Going to call command: $cmd\n";
902
903 return system($cmd);
904 #return &run_and_print_cmd($cmd, $fh); # doesn't work on cmds chained with bash -c
905}
906
907
908# http://stackoverflow.com/questions/758611/how-to-flush-output-in-backticks-in-perl?rq=1activeperl%20sys::info
909# http://stackoverflow.com/questions/1477500/how-do-i-get-the-output-of-an-external-command-in-perl
910sub run_and_print_cmd {
911 my ($cmd, $fh) = @_;
912
913 open my $pin, "$cmd|" or die "unable to run cmd $cmd: $!"; # open(my $fh, '-|', 'powercfg -l') or die $!;
914
915 if(defined $fh) { # print cmd output both to the filehandle and to stdout
916 while (my $line = <$pin>) {
917 print $fh $line;
918# print STDOUT $line; # if also printing cmd output to STDOUT
919 }
920 }
921 else { # no filehandle, so just need to print to stdout
922
923 # unlike backticks operator, system() will print the output of the command to the screen as it executes
924 # http://stackoverflow.com/questions/758611/how-to-flush-output-in-backticks-in-perl?rq=1
925
926 my $status = system $cmd;
927 if($status != 0) {
928 print STDERR "ERROR ($status) running $cmd: $!\n";
929 }
930 }
931 close($pin);
932}
933
934sub filename_concat {
935 my $first_file = shift(@_);
936 my (@filenames) = @_;
937
938 # If first_file is not null or empty, then add it back into the list
939 if (defined $first_file && $first_file =~ /\S/)
940 {
941 unshift(@filenames, $first_file);
942 }
943
944 my $filename = join($sep, @filenames);
945 $filename =~ s/[\\\/]$//; # remove trailing slashes if any
946 return $filename;
947}
948
949
950# The following code is from
951# http://stackoverflow.com/questions/227613/how-can-i-copy-a-directory-recursively-and-filter-filenames-in-perl
952# It also states that "Perl's File::Copy is a bit broken (it doesn't copy permissions on Unix systems, for example)"
953sub copy_recursively {
954 my ($from_dir, $to_dir, $regex) = @_;
955 opendir my($dh), $from_dir or die "Could not open dir '$from_dir': $!";
956
957# if(-d !$to_dir) {
958# mkdir $to_dir or die "mkdir '$to_dir' failed: $!" if not -e $to_dir;
959# }
960
961 for my $entry (readdir $dh) {
962 next if ($entry eq "." || $entry eq "..");
963 next if (defined $regex && $entry =~ /$regex/);
964 my $source = "$from_dir/$entry";
965 my $destination = "$to_dir/$entry";
966 if (-d $source) {
967 mkdir $destination or die "mkdir '$destination' failed: $!" if not -e $destination;
968 copy_recursively($source, $destination, $regex);
969 } else {
970 copy($source, $destination) or die "copy failed: $!";
971 }
972 }
973 closedir $dh;
974 return;
975}
976
977sub summarise {
978
979 # make a summarised Xml report
980 print STDERR "Summarizing the xml report... ";
981 my $cmd = "java org.apache.xalan.xslt.Process -IN $xmlout -XSL $ENV{'TASK_HOME'}/xsl/xml-report.xsl -OUT $ENV{'DATA_DIR'}/report-$install_version-$dateid.xml";
982 my $status = system($cmd);
983 print STDERR "done\n";
984
985 # make a summarised HTMl report
986 print STDERR "Creating an html summary report... ";
987 $cmd = "java org.apache.xalan.xslt.Process -IN $ENV{'DATA_DIR'}/report-$install_version-$dateid.xml -XSL $ENV{'TASK_HOME'}/xsl/html-report.xsl -OUT $ENV{'DATA_DIR'}/report-$install_version-$dateid.html";
988 $status = system($cmd);
989 print STDERR "done\n";
990
991 # Print whether the tests passed or failed
992 print STDERR "*******************************************\n";
993 print STDERR "Checking if successful... \n";
994 $cmd = "java org.apache.xalan.xslt.Process -IN $xmlout -XSL $ENV{'TASK_HOME'}/xsl/passed-or-not.xsl";
995 $status = `$cmd`; #$status = system($cmd);
996 print STDERR "result: $status\n";
997 print STDERR "*******************************************\n";
998}
999
1000sub upload {
1001 # if the upload dir already existed, clear it of contents
1002 if (-d $ENV{'UPLOAD_DIR'}) { #else rm $UPLOAD_DIR/*
1003 # don't want to keep previous days reports
1004 # else we will have to manually clear them at some point
1005 # just generate the set of reports for this run of task.pl upload
1006 # and
1007 &File::Path::remove_tree($ENV{'UPLOAD_DIR'});
1008 }
1009 # recreate the upload directory
1010 &File::Path::make_path($ENV{'UPLOAD_DIR'});
1011
1012 # copy all *.xml and *.html files across to UPLOAD_DIR
1013 opendir my($dh), $ENV{'DATA_DIR'} or die "Could not open DATA_DIR: $!";
1014 for my $entry (readdir $dh) {
1015 next if ($entry !~ m/(\.xml|\.html?)$/);
1016 next if ($entry !~ m/(report-$install_version)/);
1017
1018 # copy the reports across with different names: with OS prefixed to them. And for the HTML file on Win, rename to HTM
1019 # html files uploaded from windows to nzdl are empty for no reason. Uploading as htm seems to work
1020 my $os_entry = $entry;
1021 $os_entry =~ s@\[email protected]@ if $isWin;
1022 if($isMac) {
1023 $osversion = "Leopard-" if ($osversion eq "");
1024 $os_entry = "diffcol-".$^O."-".$osversion."$os_entry"; # darwin-Lion for Lion/Mountain Lion
1025 } else {
1026 $os_entry = "diffcol-".$^O."-$os_entry";
1027 }
1028
1029 # if the test failed, prefix "failed" to the report so that it shows up with an error icon on the caveat page
1030 my $cmd = "java org.apache.xalan.xslt.Process -IN $xmlout -XSL $ENV{'TASK_HOME'}/xsl/passed-or-not.xsl";
1031 my $result = `$cmd`;
1032 if($result ne "yes") {
1033 $os_entry =~ s/diffcol-/diffcol-FAIL-/;
1034 }
1035
1036 # get the absolute path to the original files before copying them over
1037 $entry = &filename_concat($ENV{'DATA_DIR'}, $entry);
1038
1039 # copy them over with their new names
1040## print STDERR "@@@@ copying across $entry to $ENV{'UPLOAD_DIR'} as $os_entry\n";
1041 copy($entry, "$ENV{'UPLOAD_DIR'}$sep$os_entry"); #copy($entry, "$ENV{'UPLOAD_DIR'}");
1042 }
1043 closedir $dh;
1044
1045
1046 # Upload the html file to puka
1047 #default identity dir
1048 if ( ! exists $ENV{'IDENTITY_DIR'} ) {
1049 $ENV{'IDENTITY_DIR'} = "$ENV{'HOME'}${sep}.ssh"; # "C:\\Research\\Nightly\\tools\\keys" on windows, see environment.pl
1050 }
1051 if (! exists $ENV{'SNAPSHOT_MODE'} ) {
1052 $ENV{'SNAPSHOT_MODE'} = "caveat";
1053 }
1054
1055 #use the correct key for uploading
1056 $ENV{'IDENTITY_FILE'} = "$ENV{'IDENTITY_DIR'}${sep}upload-" . $ENV{'SNAPSHOT_MODE'} . ($^O eq "MSWin32" ? ".ppk" : "");
1057 if(-f $ENV{'IDENTITY_FILE'}) {
1058 # if you need to touch the file on windows: http://stackoverflow.com/questions/51435/windows-version-of-the-unix-touch-command
1059
1060 # the report we want to upload is actually just os-diffcol-report-$install_version-$dateid.html
1061 my $command = "cd \"$ENV{'UPLOAD_DIR'}\" && tar -c *.htm* | "; #&& cat *.html | "; # && tar -c * |
1062 $command .= ($^O eq "MSWin32" ? "plink" : "ssh");
1063 $command .= " -T -i \"$ENV{'IDENTITY_FILE'}\" nzdl\@puka.cs.waikato.ac.nz";
1064 #print "$command\n";
1065 my $status = system("$command");
1066 if($status != 0) {
1067 print STDERR "*** Failed to upload test report to nzdl $status\n";
1068 }
1069 } else {
1070 print STDERR "*** Cannot upload the test report to nzdl from this machine\n";
1071 }
1072
1073 print STDERR "Finished uploading\n";
1074}
1075
1076# Sending emails with perl: http://learn.perl.org/examples/email.html
1077# Sending email attachments with perl: http://www.perlmonks.org/?node_id=19430
1078# Sadly none of the packages are installed by default and use of MIME::Lite is discouraged
1079sub mail_with_report_attached
1080{
1081 # email out with report attached, if the tests failed
1082 print STDERR "Checking if successful... \n";
1083 my $cmd = "java org.apache.xalan.xslt.Process -IN $xmlout -XSL $ENV{'TASK_HOME'}/xsl/passed-or-not.xsl";
1084 #my $result = system($cmd);
1085 my $result = `$cmd`;
1086
1087 print STDERR "result: $result\n";
1088
1089 if($result ne "yes") {
1090 my $msg = "$gsdl regression test for $dateid failed";
1091 my $subject = "Regression Test Failed"; #"$gsdl regression test for $dateid failed\n";
1092 my $attach_file = &filename_concat($ENV{'DATA_DIR'}, "report-$install_version-$dateid.html");
1093
1094 if($isWin) {
1095 if($use_blat && $blat && $ENV{'GSDL_SMTP'}) {
1096 # http://stackoverflow.com/questions/709635/sending-mail-from-batch-file
1097 #blat -to [email protected] -server smtp.example.com -f [email protected] -subject "subject" -body "body"
1098
1099 # need to install blat on windows
1100 $cmd = "$blat -to $ENV{'MONITOR_EMAIL'} -server $ENV{'GSDL_SMTP'} -f $ENV{'MONITOR_EMAIL'} -attach $attach_file -subject \"$subject\" -body \"$msg\"";
1101 $result = system($cmd);
1102 }
1103 else {
1104 $result = 1; # status from running mail command is 0 if success, 1 if fail
1105 print STDERR "********************************************\n";
1106 if ($use_blat) {
1107 print STDERR "Need blat and SMTP set to send mail attachment\n" ;
1108 } else {
1109 print STDERR "Not set up to send mail on Windows\n";
1110 }
1111 print STDERR "Inspect report at: $attach_file\n";
1112 print STDERR "********************************************\n";
1113 }
1114 } else { # linux
1115 my $status = system("command -v mutt > /dev/null 2>&1;"); #better way of doing "which mutt"
1116
1117 if($status != 0) { # mutt doesn't exist, can't send attachments, so send simple email
1118 $cmd="echo '$gsdl regression test for $dateid failed.' | mail -s 'Regression Test Failed' $ENV{'MONITOR_EMAIL'}";
1119
1120 print STDERR "********************************************\n";
1121 print STDERR "No mutt installed, unable to mail attachment\n";
1122 print STDERR "Inspect report at: $attach_file\n";
1123 print STDERR "********************************************\n";
1124 } else {
1125 #$cmd = "bash -c \"echo '$gsdl regression test for $dateid failed' | mutt -a $attach_file -s 'Regression Test Failed' -- $ENV{'MONITOR_EMAIL'}\"";
1126 $cmd = "echo '$gsdl regression test for $dateid failed' | mutt -a $attach_file -s 'Regression Test Failed' -- $ENV{'MONITOR_EMAIL'}";
1127 }
1128
1129 # run the mail command
1130 $result = system($cmd); #&run_and_print_cmd($cmd);
1131 }
1132
1133
1134 if($result != 0) {
1135 print STDERR "*** Unable to send email: $?\n";
1136 }
1137 else {
1138 print STDERR "Sent mail with report attached.\n";
1139 }
1140 } else {
1141 print STDERR "********************************************\n";
1142 print STDERR "Tests were successful. Not sending mail.\n";
1143 print STDERR "********************************************\n";
1144 }
1145}
1146
1147# The old version of this program contained the following, consisting of 1 line of active code:
1148
1149 # Invoke as: sjmc@br:/research/sjm84/envi/bin$ ./envi diffcol summarise
1150 # Doing so will call this pl file and pass in "summarise" in ARGV
1151 # This pl file will in turn call the task executable in this folder
1152 # passing in "summarise" as a parameter.
1153#system("/bin/bash -c \"../etc/tasks/diffcol/task @ARGV\"");
1154
1155 ##system("/bin/bash -c \"./task @ARGV\"");
1156 ##print STDERR "/bin/bash -c ../etc/tasks/diffcol/task @ARGV"
1157
Note: See TracBrowser for help on using the repository browser.