[18470] | 1 | #!/usr/bin/perl -w
|
---|
| 2 |
|
---|
| 3 | ###########################################################################
|
---|
| 4 | #
|
---|
| 5 | # incremental-buildcol.pl -- runs buildcol.pl with -incremental on
|
---|
| 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 is designed to support incremental building of Greenstone
|
---|
| 30 | # Runs: buildcol.pl -incremental -builddir GSDLHOME/collect/$collect/index ...
|
---|
| 31 |
|
---|
| 32 |
|
---|
| 33 | BEGIN {
|
---|
| 34 | die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
|
---|
| 35 | die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};
|
---|
| 36 | unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 |
|
---|
| 40 | use strict;
|
---|
[19743] | 41 | no strict 'refs'; # allow filehandles to be variables and vice versa
|
---|
| 42 | no strict 'subs'; # allow barewords (eg STDERR) as function arguments
|
---|
[18470] | 43 |
|
---|
[24192] | 44 | use Config; # for getting the perlpath in the recommended way
|
---|
[18470] | 45 | use util;
|
---|
[19743] | 46 | use colcfg;
|
---|
[18470] | 47 |
|
---|
| 48 | sub main
|
---|
| 49 | {
|
---|
| 50 | my ($argc,@argv) = @_;
|
---|
| 51 |
|
---|
| 52 | if (($argc==0) || (($argc==1) && ($argv[0] =~ m/^--?h(elp)?$/))) {
|
---|
[20606] | 53 | my ($progname) = ($0 =~ m/^.*[\/|\\](.*?)$/);
|
---|
[18470] | 54 |
|
---|
| 55 |
|
---|
| 56 | print STDERR "\n";
|
---|
| 57 | print STDERR "Usage: $progname [buildcol.pl options] collection\n";
|
---|
| 58 | print STDERR "\n";
|
---|
| 59 |
|
---|
| 60 | exit(-1);
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 |
|
---|
[21733] | 64 | my $collection = pop @argv;
|
---|
[18470] | 65 |
|
---|
[18492] | 66 | my @filtered_argv = ();
|
---|
| 67 |
|
---|
| 68 | my $collect_dir = undef;
|
---|
| 69 | my $build_dir = undef;
|
---|
[19743] | 70 | my $site = undef;
|
---|
[18492] | 71 |
|
---|
| 72 | while (my $arg = shift @argv) {
|
---|
| 73 | if ($arg eq "-collectdir") {
|
---|
| 74 | $collect_dir = shift @argv;
|
---|
| 75 | push(@filtered_argv,$arg,$collect_dir);
|
---|
| 76 | }
|
---|
| 77 | elsif ($arg eq "-builddir") {
|
---|
| 78 | $build_dir = shift @argv;
|
---|
| 79 | push(@filtered_argv,$arg,$build_dir);
|
---|
| 80 | }
|
---|
[19743] | 81 | elsif ($arg eq "-site") {
|
---|
| 82 | $site = shift @argv;
|
---|
| 83 | push(@filtered_argv,$arg,$site);
|
---|
| 84 | }
|
---|
[18492] | 85 | else {
|
---|
| 86 | push(@filtered_argv,$arg);
|
---|
| 87 | }
|
---|
| 88 | }
|
---|
| 89 |
|
---|
[21733] | 90 | # get and check the collection name
|
---|
| 91 | if ((&colcfg::use_collection($site, $collection, $collect_dir)) eq "") {
|
---|
| 92 | print STDERR "Unable to use collection \"$collection\" within \"$collect_dir\"\n";
|
---|
| 93 | exit -1;
|
---|
| 94 | }
|
---|
[18492] | 95 |
|
---|
[18510] | 96 |
|
---|
[18492] | 97 | if (!defined $build_dir) {
|
---|
[18511] | 98 | # Yes this is intentional that 'build_dir' points to "index"
|
---|
[21733] | 99 | $build_dir = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'},"index");
|
---|
[18492] | 100 | push(@filtered_argv,"-builddir",$build_dir);
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 | my $quoted_argv = join(" ", map { "\"$_\"" } @filtered_argv);
|
---|
[18470] | 104 |
|
---|
[18492] | 105 | my $buildcol_cmd = "buildcol.pl";
|
---|
[20925] | 106 | if($ENV{'PERLPATH'}) {
|
---|
| 107 | # need to ensure that the path to perl is quoted (in case there's spaces in it)
|
---|
| 108 | if($ENV{'GSDLOS'} =~ m/windows/) {
|
---|
[19620] | 109 | $buildcol_cmd = "\"$ENV{'PERLPATH'}\\Perl.exe\" -S $buildcol_cmd";
|
---|
[19410] | 110 | } else {
|
---|
[20925] | 111 | $buildcol_cmd = "\"$ENV{'PERLPATH'}/perl\" -S $buildcol_cmd";
|
---|
[19410] | 112 | }
|
---|
[20925] | 113 | } else {
|
---|
[24192] | 114 | #Config{perlpath}, like $^X, is a special variable containing the full path to the current perl executable we are in
|
---|
| 115 | $buildcol_cmd = "\"$Config{perlpath}\" -S $buildcol_cmd";
|
---|
[19409] | 116 | }
|
---|
[18470] | 117 |
|
---|
[19899] | 118 | # Read in the collection configuration file.
|
---|
| 119 | my ($collect_cfg_filename, $gs_mode) = &colcfg::get_collect_cfg_name(STDERR);
|
---|
| 120 |
|
---|
| 121 | my $collectcfg = &colcfg::read_collection_cfg ($collect_cfg_filename,$gs_mode);
|
---|
| 122 |
|
---|
| 123 | # look for build.cfg/buildConfig.xml
|
---|
| 124 | my $build_cfg_filename ="";
|
---|
| 125 |
|
---|
| 126 | if ($gs_mode eq "gs2") {
|
---|
| 127 | $build_cfg_filename = &util::filename_cat($build_dir,"build.cfg");
|
---|
| 128 | } else {
|
---|
| 129 | $build_cfg_filename = &util::filename_cat($build_dir, "buildConfig.xml");
|
---|
| 130 | }
|
---|
| 131 |
|
---|
[18492] | 132 | if (-e $build_cfg_filename) {
|
---|
[19743] | 133 |
|
---|
| 134 | # figure out if there has been a change of indexer
|
---|
| 135 | # (e.g. collect.cfg now says lucene, but build.cfg says mgpp)
|
---|
| 136 |
|
---|
[20098] | 137 | my $buildcfg = &colcfg::read_building_cfg ($build_cfg_filename, $gs_mode);
|
---|
[19743] | 138 | if ($buildcfg->{'buildtype'} ne $collectcfg->{'buildtype'}) {
|
---|
| 139 | print STDERR "*****\n";
|
---|
| 140 | print STDERR "* Change of indexer detected. Switching to full buildcol.pl.\n";
|
---|
| 141 | print STDERR "*****\n";
|
---|
| 142 | $buildcol_cmd .= " -removeold";
|
---|
| 143 | }
|
---|
| 144 | else {
|
---|
| 145 |
|
---|
| 146 | $buildcol_cmd .= " -incremental";
|
---|
| 147 | }
|
---|
[18492] | 148 | }
|
---|
| 149 | else {
|
---|
[19743] | 150 | # build.cfg doesn't exit
|
---|
[18492] | 151 | print STDERR "*****\n";
|
---|
| 152 | print STDERR "* First time built. Switching to full buildcol.pl.\n";
|
---|
| 153 | print STDERR "*****\n";
|
---|
| 154 | $buildcol_cmd .= " -removeold";
|
---|
| 155 | }
|
---|
| 156 |
|
---|
[18470] | 157 |
|
---|
[21733] | 158 | $buildcol_cmd .= " $quoted_argv \"$collection\"";
|
---|
[18470] | 159 |
|
---|
| 160 | my $buildcol_status = system($buildcol_cmd)/256;
|
---|
| 161 |
|
---|
| 162 | if ($buildcol_status != 0) {
|
---|
| 163 | print STDERR "Error: Failed to run: $buildcol_cmd\n";
|
---|
| 164 | print STDERR " $!\n" if ($! ne "");
|
---|
| 165 | exit(-1);
|
---|
| 166 | }
|
---|
| 167 | }
|
---|
| 168 |
|
---|
| 169 | &main(scalar(@ARGV),@ARGV);
|
---|
| 170 |
|
---|
| 171 |
|
---|
| 172 |
|
---|
| 173 |
|
---|