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