- Timestamp:
- 2012-05-11T19:23:42+12:00 (12 years ago)
- Location:
- main/trunk/greenstone2
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/bin/script/activate.pl
r25573 r25579 60 60 use scriptutil; 61 61 use util; 62 62 #use enum; 63 64 # enumerations in perl, http://stackoverflow.com/questions/473666/does-perl-have-an-enumeration-type 65 # Unfortunately, not part of perl's core 66 #use enum qw(LEVEL_NONE LEVEL_ERROR LEVEL_INFO LEVEL_DEBUG); # debugging levels NONE == 0, ERROR=1 INFO=2 DEBUG=3 67 68 # global variables 69 #my $default_verbosity = LEVEL_ERROR; # by default we display basic error messages 70 71 my $default_verbosity = 2; # by default we display basic error and info messages 63 72 64 73 sub print_task_msg { 65 my $task_msg = shift(@_); 66 print STDERR "\n"; 67 print STDERR "************************\n"; 68 print STDERR "* $task_msg\n"; 69 print STDERR "************************\n"; 74 my ($task_msg, $verbosity_setting) = @_; 75 76 $verbosity_setting = $default_verbosity unless $verbosity_setting; 77 #$verbosity_setting = 1 unless defined $verbosity; 78 if($verbosity_setting >= 1) { 79 print STDERR "\n"; 80 print STDERR "************************\n"; 81 print STDERR "* $task_msg\n"; 82 print STDERR "************************\n"; 83 } 84 } 85 86 # Prints messages if the verbosity is right. Does not add new lines. 87 sub print_msg { 88 my ($msg, $min_verbosity, $verbosity_setting) = @_; 89 90 # only display error messages if the current 91 # verbosity setting >= the minimum verbosity level 92 # needed for that message to be displayed. 93 94 $verbosity_setting = $default_verbosity unless defined $verbosity_setting; 95 $min_verbosity = 1 unless defined $min_verbosity; 96 if($verbosity_setting >= $min_verbosity) { # by default display all 1 messages 97 print STDERR "$msg"; 98 } 70 99 } 71 100 … … 99 128 100 129 if(LWP::Simple::is_success($response_code)) {# $response_code eq RC_OK) { # LWP::Simple::is_success($response_code) 101 print STDERR "*** Command $library_url$command\n";102 print STDERR "*** HTTP Response Status: $response_code - Complete.";130 &print_msg("*** Command $library_url$command\n", 3); 131 &print_msg("*** HTTP Response Status: $response_code - Complete.", 3); 103 132 104 133 # check the page content is as expected 105 134 my $response_content = $response_obj->content; 106 135 if($response_content =~ m/$check_message_against_regex/) { 107 print STDERR " Response as expected.\n";136 &print_msg(" Response as expected.\n", 3); 108 137 return 1; 109 138 } else { 110 print STDERR "\n\t BUT: command $library_url$command response UNEXPECTED.\n";111 #print STDERR "*** Got message:\n$response_content.\n";139 &print_msg("\n\tBUT: command $library_url$command response UNEXPECTED.\n", 3); 140 &print_msg("*** Got message:\n$response_content.\n", 4); 112 141 return 0; # ping on a collection may "not succeed." 113 142 } 114 143 } 115 144 elsif(LWP::Simple::is_error($response_code)) { # method exported by LWP::Simple, along with HTTP::Status constants 116 print STDERR "*** $response_code - Failed.\n"; 145 &print_msg("*** Command $library_url$command\n"); 146 &print_msg("*** HTTP Response Status: $response_code - Failed.\n"); 117 147 return 0; 118 148 } … … 199 229 # Read in the entire contents of the file in one hit 200 230 if (!open (FIN, $llssite_cfg)) { 201 print STDERR "activate.pl::get_library_URL failed to open $llssite_cfg ($!)\n";231 &print_msg("activate.pl::get_library_URL failed to open $llssite_cfg ($!)\n"); 202 232 return undef; 203 233 } … … 276 306 close(PIN); 277 307 } else { 278 print STDERR "**** activate.pl::get_library_URL: Failed to run $perl_command to work out library URL for $gs_mode\n";308 &print_msg("activate.pl::get_library_URL: Failed to run $perl_command to work out library URL for $gs_mode\n"); 279 309 } 280 310 } … … 284 314 #print STDERR "\n@@@@@ URL still undef\n" if !$url; 285 315 return $url; 286 }287 288 ### METHODS TO MOVE TO util.pm?289 290 # Given the qualified collection name (colgroup/collection),291 # returns the collection and colgroup parts292 sub get_collection_parts {293 # http://perldoc.perl.org/File/Basename.html294 # my($filename, $directories, $suffix) = fileparse($path);295 # "$directories contains everything up to and including the last directory separator in the $path296 # including the volume (if applicable). The remainder of the $path is the $filename."297 #my ($collection, $colgroup) = &File::Basename::fileparse($qualified_collection);298 299 my $qualified_collection = shift(@_);300 301 # Since activate.pl can be launched from the command-line, including by a user,302 # best not to assume colgroup uses URL-style slashes as would be the case with GLI303 # Also allow for the accidental inclusion of multiple slashes304 my ($colgroup, $collection) = split(/[\/\\]+/, $qualified_collection); #split('/', $qualified_collection);305 306 if(!defined $collection) {307 $collection = $colgroup;308 $colgroup = "";309 }310 return ($collection, $colgroup);311 }312 313 # work out the "collectdir/collection" location314 sub resolve_collection_dir {315 my ($collect_dir, $qualified_collection, $site) = @_; #, $gs_mode316 317 my ($colgroup, $collection) = get_collection_parts($qualified_collection);318 319 if (defined $collect_dir) {320 return &util::filename_cat($collect_dir,$colgroup, $collection);321 }322 else {323 if (defined $site) {324 return &util::filename_cat($ENV{'GSDL3HOME'},"sites",$site,"collect",$colgroup, $collection);325 }326 else {327 return &util::filename_cat($ENV{'GSDLHOME'},"collect",$colgroup, $collection);328 }329 }330 316 } 331 317 … … 394 380 395 381 if (($argc==0) || (($argc==1) && ($argv[0] =~ m/^--?h(elp)?$/))) { 396 my ($progname) = ($0 =~ m/^.*[\/|\\](.*?)$/); 397 398 399 print STDERR "\n"; 400 print STDERR "Usage: $progname [-collectdir c -builddir b -indexdir i -site s -removeold -keepold -library_url URL] <[colgroup/]collection>\n"; 401 print STDERR "\n"; 402 403 exit(-1); 382 my ($progname) = ($0 =~ m/^.*[\/|\\](.*?)$/); 383 384 385 print STDERR "\n"; 386 print STDERR "Usage: $progname [-collectdir c -builddir b -indexdir i -site s -removeold -keepold -verbosity v\n"; 387 print STDERR "\t-library_url URL] <[colgroup/]collection>\n"; 388 print STDERR "\n"; 389 390 exit(-1); 404 391 } 405 392 … … 415 402 my $keepold = 0; 416 403 417 my $library_url = undef; # to be specified on the cmdline if not using a GS-included web server 418 404 my $library_url = undef; # to be specified on the cmdline if not using a GS-included web server 419 405 420 406 while (my $arg = shift @argv) { … … 440 426 $library_url = shift @argv; 441 427 } 428 elsif ($arg eq "-verbosity") { 429 $default_verbosity = shift @argv; # global variable 430 431 # ensure we're working with ints not strings (int context not str context), in case verbosity=0 432 # http://stackoverflow.com/questions/288900/how-can-i-convert-a-string-to-a-number-in-perl 433 $default_verbosity = int($default_verbosity || 0); ### is this the best way? 434 } 442 435 } 443 436 444 437 # work out the building and index dirs 445 #$build_dir = &util::filename_cat($collect_dir, $qualified_collection, "building") unless (defined $build_dir); 446 #$index_dir = &util::filename_cat($collect_dir, $qualified_collection, "index") unless (defined $index_dir); 447 my $collection_dir = &resolve_collection_dir($collect_dir, $qualified_collection, $site); 448 $build_dir = &util::filename_cat($collection_dir, "building") unless (defined $build_dir); 438 my $collection_dir = &util::resolve_collection_dir($collect_dir, $qualified_collection, $site); 439 $build_dir = &util::filename_cat($collection_dir, "building") unless (defined $build_dir); 449 440 $index_dir = &util::filename_cat($collection_dir, "index") unless (defined $index_dir); 450 441 … … 453 444 # can't do anything without a build directory with something in it to move into index 454 445 if(!&util::dir_exists($build_dir)) { 455 print STDERR "Can't move building to index: no building folder at $build_dir\n";446 &print_msg("No building folder at $build_dir to move to index.\n"); 456 447 exit -1; 457 448 } elsif (&util::is_dir_empty($build_dir)) { 458 print STDERR "Nothing in building folder at $build_dir to move to index folder\n";449 &print_msg("Nothing in building folder $build_dir to move into index folder.\n"); 459 450 exit -1; 460 451 } … … 462 453 # get and check the collection name 463 454 if ((&colcfg::use_collection($site, $qualified_collection, $collect_dir)) eq "") { 464 print STDERR "Unable to use collection \"$qualified_collection\" within \"$collect_dir\"\n";465 exit -1;455 &print_msg("Unable to use collection \"$qualified_collection\" within \"$collect_dir\"\n"); 456 exit -1; 466 457 } 467 458 … … 513 504 # and apache for GS2), we work out the library URL: 514 505 if(!$library_url) { 515 $library_url = &get_library_URL($gs_mode); 506 $library_url = &get_library_URL($gs_mode); # returns undef if no server is running 516 507 } 517 508 … … 520 511 521 512 my $is_persistent_server = undef; 522 if(&ping_library($library_url, $gs_mode, $site)) { 523 # server is running, so release the collection if the server is persistent 524 $is_persistent_server = &is_persistent($library_url, $gs_mode); 525 if($is_persistent_server) { 526 &deactivate_collection($library_url, $gs_mode, $qualified_collection, $site); 527 } 528 } 529 513 if($library_url) { # running server 514 &print_msg("Pinging $library_url\n"); 515 if($library_url && &ping_library($library_url, $gs_mode, $site)) { 516 # server is running, so release the collection if the server is persistent 517 &print_msg("Checking if Greenstone server is persistent\n"); 518 $is_persistent_server = &is_persistent($library_url, $gs_mode); 519 if($is_persistent_server) { 520 &print_msg("De-activating collection $qualified_collection\n"); 521 &deactivate_collection($library_url, $gs_mode, $qualified_collection, $site); 522 } 523 } 524 } 530 525 # 3. Do all the moving building to index stuff now 531 526 532 ### If removeold: replace index dir with building dir 533 # if keepold: move building's contents into index, where only duplicates will get deleted 534 535 #if(!$removeold && !$keepold) { 536 # $removeold = 1; 537 #} elsif($removeold && $keepold) { 538 # $keepold = 0; 539 #} 540 527 # If removeold: replace index dir with building dir. 528 # If keepold: move building's contents into index, where only duplicates will get deleted. 529 # removeold and keepold can't both be on at the same time 541 530 ($removeold, $keepold) = &scriptutil::check_removeold_and_keepold($removeold, $keepold, 542 531 0, # incremental is irrelevant to what activate.pl does, setting this = 0 … … 554 543 555 544 if (&util::dir_exists($index_dir)) { 556 print STDERR "The index directory $index_dir could not be deleted.\n"; # CollectionManager.Index_Not_Deleted545 &print_msg("The index directory $index_dir could not be deleted.\n"); # CollectionManager.Index_Not_Deleted 557 546 } 558 547 } … … 565 554 &util::mv($build_dir, $index_dir); 566 555 if(&util::dir_exists($build_dir) || !&util::dir_exists($index_dir)) { 567 print STDERR "Could not move move $build_dir to $index_dir.\n"; # CollectionManager.Build_Not_Moved556 &print_msg("Could not move $build_dir to $index_dir.\n"); # CollectionManager.Build_Not_Moved 568 557 } 569 558 } … … 580 569 # Check for success: if building does not exist OR is empty 581 570 if(!&util::dir_exists($build_dir) || &util::is_dir_empty($build_dir)) { 582 if(&ping_library($library_url, $gs_mode, $site)) { 583 # don't need to work out persistency of server more than once 584 $is_persistent_server = &is_persistent($library_url, $gs_mode) unless (defined $is_persistent_server); 585 if($is_persistent_server) { 586 &activate_collection($library_url, $gs_mode, $qualified_collection, $site); 587 } 571 if($library_url) { # undef if no server is running 572 &print_msg("Pinging $library_url\n"); 573 if(&ping_library($library_url, $gs_mode, $site)) { 574 # don't need to work out persistency of server more than once 575 if(!defined $is_persistent_server) { 576 &print_msg("Checking if Greenstone server is persistent\n"); 577 $is_persistent_server = &is_persistent($library_url, $gs_mode); 578 } 579 if($is_persistent_server) { 580 &print_msg("Activating collection $qualified_collection\n"); 581 &activate_collection($library_url, $gs_mode, $qualified_collection, $site); 582 } 583 } 588 584 } 589 585 } else { # installcollection failed 590 586 #CollectionManager.Preview_Ready_Failed 591 print STDERR "Building directory is not empty or still exists. Failed to properly move $build_dir to $index_dir.\n";587 &print_msg("Building directory is not empty or still exists. Failed to properly move $build_dir to $index_dir.\n"); 592 588 } 593 589 } -
main/trunk/greenstone2/bin/script/buildcol.pl
r25573 r25579 694 694 695 695 my @activate_argv = (); 696 push(@activate_argv,"-collectdir","$collectdir") if($collectdir); 697 push(@activate_argv,"-builddir","$builddir") if($builddir); 698 push(@activate_argv,"-site","$site") if($site); 696 push(@activate_argv,"-collectdir",$collectdir) if($collectdir); 697 push(@activate_argv,"-builddir",$builddir) if($builddir); 698 push(@activate_argv,"-site",$site) if($site); 699 push(@activate_argv,"-verbosity",$verbosity) if($verbosity); 699 700 push(@activate_argv,"-removeold") if($removeold); 700 701 push(@activate_argv,"-keepold") if($keepold); -
main/trunk/greenstone2/bin/script/full-rebuild.pl
r25573 r25579 31 31 # Followed by: full-buildcol.pl -removeold ... 32 32 # (assumming import.pl did not end with an error) 33 34 # The -keepold argument can be passed into this script since this calls activate.pl35 # And activate.pl allows the contents of a src dir to be moved into the dest_dir36 # without destroying other (uniquely-named) contents of dest_dir.37 33 38 34 BEGIN { … … 129 125 my $build_dir = undef; 130 126 my $index_dir = undef; 127 my $verbosity = 2; # same as the default in buildcol.pl 131 128 132 129 while (my $arg = shift @argv) { … … 160 157 push(@activate_argv,$arg,$index_dir); 161 158 } 159 elsif ($arg eq "-verbosity") { 160 $verbosity = shift @argv; 161 push(@import_argv,$arg,$verbosity); 162 push(@buildcol_argv,$arg,$verbosity); 163 push(@activate_argv,$arg,$verbosity); 164 } 162 165 else { 163 166 push(@import_argv,$arg); 164 167 push(@buildcol_argv,$arg); 165 168 push(@activate_argv,$arg); 166 169 } 167 170 } … … 198 201 199 202 #full_replace($site,$collect_dir,$collect,$build_dir,$index_dir); 200 my $activatecol_cmd = $launch_cmd . "activate.pl $quoted_activate_argv \"$collect\""; 203 204 # run activate with -removeold, just like full-buildcol.pl called above runs buildcol.pl 205 my $activatecol_cmd = $launch_cmd . "activate.pl -removeold $quoted_activate_argv \"$collect\""; 201 206 my $activatecol_status = system($activatecol_cmd)/256; 202 207 } -
main/trunk/greenstone2/perllib/util.pm
r25578 r25579 190 190 opendir(DIR, "$src_dir"); 191 191 my @files= readdir(DIR); 192 close(DIR); 192 close(DIR); 193 193 194 194 my @full_path_files = (); … … 197 197 unless($file eq "." || $file eq "..") { 198 198 199 my $dest_subdir = &filename_cat($dest_dir, $file); # $file stillrelative path199 my $dest_subdir = &filename_cat($dest_dir, $file); # $file is still a relative path 200 200 201 201 # construct absolute paths … … 206 206 # then a simple move operation will fail (definitely on Windows). 207 207 if(-d $file && -d $dest_subdir) { 208 print STDERR "**** $file is a directory also existing in target,to be copied to $dest_subdir\n";208 #print STDERR "**** $file is a directory also existing in target, its contents to be copied to $dest_subdir\n"; 209 209 &mv_dir_contents($file, $dest_subdir); 210 210 … … 212 212 if(&is_dir_empty($file)) { 213 213 if (!rmdir $file) { 214 print STDERR " util::mv_dir_contents couldn't remove directory $file\n";214 print STDERR "ERROR. util::mv_dir_contents couldn't remove directory $file\n"; 215 215 } 216 216 } else { # error
Note:
See TracChangeset
for help on using the changeset viewer.