[18470] | 1 | #!/usr/bin/perl -w
|
---|
| 2 |
|
---|
| 3 | ###########################################################################
|
---|
| 4 | #
|
---|
| 5 | # incremental-rebuild.pl --
|
---|
| 6 | # A component of the Greenstone digital library software
|
---|
| 7 | # from the New Zealand Digital Library Project at the
|
---|
| 8 | # University of Waikato, New Zealand.
|
---|
| 9 | #
|
---|
| 10 | # Copyright (C) 2009 New Zealand Digital Library Project
|
---|
| 11 | #
|
---|
| 12 | # This program is free software; you can redistribute it and/or modify
|
---|
| 13 | # it under the terms of the GNU General Public License as published by
|
---|
| 14 | # the Free Software Foundation; either version 2 of the License, or
|
---|
| 15 | # (at your option) any later version.
|
---|
| 16 | #
|
---|
| 17 | # This program is distributed in the hope that it will be useful,
|
---|
| 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 20 | # GNU General Public License for more details.
|
---|
| 21 | #
|
---|
| 22 | # You should have received a copy of the GNU General Public License
|
---|
| 23 | # along with this program; if not, write to the Free Software
|
---|
| 24 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 25 | #
|
---|
| 26 | ###########################################################################
|
---|
| 27 |
|
---|
| 28 |
|
---|
| 29 | # This program will incrementally rebuild a collection
|
---|
| 30 | # Runs: incremental-import.pl -incremental ...
|
---|
| 31 | # Followed by: incremental-buildcol.pl -incremental -builddir index ...
|
---|
| 32 | # (assumming import.pl did not end with an error)
|
---|
| 33 |
|
---|
| 34 |
|
---|
| 35 | BEGIN {
|
---|
| 36 | die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
|
---|
| 37 | die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};
|
---|
| 38 | unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | use strict;
|
---|
| 42 | use util;
|
---|
| 43 |
|
---|
| 44 | sub main
|
---|
| 45 | {
|
---|
| 46 | my ($argc,@argv) = @_;
|
---|
| 47 |
|
---|
| 48 | if (($argc==0) || (($argc==1) && ($argv[0] =~ m/^--?h(elp)?$/))) {
|
---|
[20606] | 49 | my ($progname) = ($0 =~ m/^.*[\/|\\](.*?)$/);
|
---|
[18470] | 50 |
|
---|
| 51 | print STDERR "\n";
|
---|
[24747] | 52 | print STDERR "This program runs -- incrementally where possible -- import.pl followed by buildcol.pl (retaining any\n";
|
---|
| 53 | print STDERR " previously generated files in 'archives' or 'index'). The import.pl script can always be run\n";
|
---|
| 54 | print STDERR " incrementally in Greenstone, however buildcol.pl will default to a full rebuild if the indexer\n";
|
---|
| 55 | print STDERR " the collection uses (such as mg, or mgpp) does not support incremental indexing.\n";
|
---|
| 56 | print STDERR "\n";
|
---|
[26913] | 57 | print STDERR "Usage: $progname [options]| collection\n";
|
---|
| 58 | print STDERR " If a minus option is shared between import.pl and buildcol.pl then it can appear\n";
|
---|
| 59 | print STDERR " as is, such as -verbosity 5. This value will be passed to both programs.\n";
|
---|
| 60 | print STDERR " If a minus option is specific to one of the programs in particular, then prefix\n";
|
---|
| 61 | print STDERR " it with 'import:' or 'buildcol:' respectively, as in '-import:OIDtype hash_on_full_filename'\n";
|
---|
| 62 | print STDERR " Run 'import.pl' or 'buildcol.pl' from the command line with no arguments to see the\n";
|
---|
| 63 | print STDERR " specific values they take.\n";
|
---|
[18470] | 64 | print STDERR "\n";
|
---|
| 65 |
|
---|
| 66 | exit(-1);
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 |
|
---|
| 70 | my $collect = pop @argv;
|
---|
| 71 |
|
---|
[20606] | 72 | my @import_argv = ();
|
---|
| 73 | my @buildcol_argv = ();
|
---|
| 74 |
|
---|
[24747] | 75 | while (my $arg = shift @argv) {
|
---|
[20606] | 76 |
|
---|
[24747] | 77 | if ($arg eq "-manifest") {
|
---|
| 78 | # only makes sense in import.pl
|
---|
| 79 | my $manifest = shift(@argv);
|
---|
| 80 | push(@import_argv,$arg,$manifest);
|
---|
[20606] | 81 | }
|
---|
[24747] | 82 | elsif ($arg eq "-importdir") {
|
---|
| 83 | # only makes sense in import.pl
|
---|
| 84 | my $import_dir = shift @argv;
|
---|
| 85 | push(@import_argv,$arg,$import_dir);
|
---|
| 86 | }
|
---|
| 87 | elsif ($arg eq "-builddir") {
|
---|
| 88 | # only makes sense in build.pl
|
---|
| 89 | my $build_dir = shift @argv;
|
---|
| 90 | push(@buildcol_argv,$arg,$build_dir);
|
---|
| 91 | }
|
---|
| 92 | elsif ($arg eq "-indexdir") {
|
---|
| 93 | # only makes sense in build.pl
|
---|
| 94 | my $index_dir = shift @argv;
|
---|
| 95 | push(@buildcol_argv,$arg,$index_dir);
|
---|
| 96 | }
|
---|
[26441] | 97 | elsif ($arg =~ /-import:(.*)$/) {
|
---|
| 98 | my $import_arg = "-".$1;
|
---|
| 99 | my $import_val = shift @argv;
|
---|
| 100 | push(@import_argv,$import_arg,$import_val);
|
---|
| 101 | }
|
---|
| 102 | elsif ($arg =~ /-buildcol:(.*)$/) {
|
---|
| 103 | my $buildcol_arg = "-".$1;
|
---|
| 104 | my $buildcol_val = shift @argv;
|
---|
| 105 | push(@buildcol_argv,$buildcol_arg,$buildcol_val);
|
---|
| 106 | }
|
---|
[20606] | 107 | else {
|
---|
[24747] | 108 | push(@import_argv,$arg);
|
---|
| 109 | push(@buildcol_argv,$arg);
|
---|
[20606] | 110 | }
|
---|
| 111 |
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | my $quoted_import_argv = join(" ", map { "\"$_\"" } @import_argv);
|
---|
| 115 | my $quoted_buildcol_argv = join(" ", map { "\"$_\"" } @buildcol_argv);
|
---|
[18470] | 116 |
|
---|
| 117 | my $final_status = 0;
|
---|
| 118 |
|
---|
[20925] | 119 | # need to ensure that the path to perl is quoted (in case there's spaces in it)
|
---|
[24362] | 120 | my $launch_cmd = "\"".&util::get_perl_exec()."\" -S ";
|
---|
[19409] | 121 |
|
---|
[23192] | 122 | print STDERR "\n";
|
---|
| 123 | print STDERR "************************\n";
|
---|
| 124 | print STDERR "* Running Import Stage\n";
|
---|
| 125 | print STDERR "************************\n";
|
---|
[18470] | 126 |
|
---|
[20606] | 127 | my $import_cmd = $launch_cmd . "incremental-import.pl $quoted_import_argv \"$collect\"";
|
---|
[23192] | 128 |
|
---|
[18470] | 129 | my $import_status = system($import_cmd)/256;
|
---|
| 130 |
|
---|
| 131 | if ($import_status == 0) {
|
---|
[23192] | 132 | print STDERR "\n";
|
---|
| 133 | print STDERR "************************\n";
|
---|
| 134 | print STDERR "* Running Buildcol Stage\n";
|
---|
| 135 | print STDERR "************************\n";
|
---|
[18470] | 136 |
|
---|
| 137 |
|
---|
[20606] | 138 | my $buildcol_cmd = $launch_cmd . "incremental-buildcol.pl $quoted_buildcol_argv \"$collect\"";
|
---|
[18470] | 139 | my $buildcol_status = system($buildcol_cmd)/256;
|
---|
| 140 | if ($buildcol_status != 0) {
|
---|
| 141 | $final_status = $buildcol_status;
|
---|
| 142 | }
|
---|
| 143 | }
|
---|
| 144 | else {
|
---|
| 145 | $final_status = $import_status;
|
---|
| 146 | }
|
---|
| 147 |
|
---|
| 148 | exit($final_status);
|
---|
| 149 | }
|
---|
| 150 |
|
---|
| 151 | &main(scalar(@ARGV),@ARGV);
|
---|
| 152 |
|
---|