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

Last change on this file was 38178, checked in by anupama, 7 months ago

Handier to sort the collections on Mac so that I can see them processed alphabetically and know when I'm getting to the end of diffcol

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