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