root/main/trunk/greenstone2/bin/script/full-rebuild.pl @ 29108

Revision 29108, 6.2 KB (checked in by kjdon, 5 years ago)

no longer taking collect as the last arg in the arg list. If the user has forgotten to put the collection in the command, then you get weird error messages. eg 'full-rebuild.pl -verbosity 5' gives an error about verbosity should be an int, rather than a missing collection name error. Just pass the collection arg to the scripts along with the other ones

  • Property svn:executable set to *
Line 
1#!/usr/bin/perl -w
2
3###########################################################################
4#
5# full-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 rebuild a collection from scratch
30# Runs:        full-import.pl -removeold [args]
31# Followed by: full-buildcol.pl -removeold [args]
32# Followed by: activate.pl -removeold [args]
33# (assumming import.pl/buildcol.pl did not end with an error)
34
35BEGIN {
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
41use strict;
42use util;
43
44sub main
45{
46    my ($argc,@argv) = @_;
47
48    if (($argc==0)  || (($argc==1) && ($argv[0] =~ m/^--?h(elp)?$/))) {
49    my ($progname) = ($0 =~ m/^.*\/(.*?)$/);
50
51    print STDERR "\n";
52    print STDERR "This program runs full-import.pl, full-buildcol.pl, activate.pl (in each case removing any previously generated files in 'archives', 'building','index')\n";
53    print STDERR "\n";
54    print STDERR "Usage: $progname [options]| collection\n";
55    print STDERR "\n";
56    print STDERR "       If a minus option is shared between import.pl and buildcol.pl then it can appear\n";
57        print STDERR "         as is, such as -verbosity 5.  This value will be passed to both programs.\n";
58    print STDERR "       If a minus option is specific to one of the programs in particular, then prefix\n";
59    print STDERR "         it with 'import:', 'buildcol:', or 'activate:' respectively, \n";
60    print STDERR "         as in '-import:OIDtype hash_on_full_filename'\n";
61    print STDERR "       Run '(full-)import.pl -h', '(full-)buildcol.pl -h', 'activate.pl -h' from the \n";
62    print STDERR "         command line to see the specific values they take.\n";
63    print STDERR "\n";
64
65    exit(-1);
66    }
67
68    my @import_argv = ();
69    my @buildcol_argv = ();
70    my @activate_argv = ();
71
72    my $site        = undef;
73    my $collect_dir = undef;
74    my $build_dir   = undef;
75    my $index_dir   = undef;
76    my $verbosity   = 2; # same as the default in buildcol.pl
77
78    while (my $arg = shift @argv) {
79    if ($arg eq "-site") {
80        $site = shift @argv;
81        push(@import_argv,$arg,$site);
82        push(@buildcol_argv,$arg,$site);
83        push(@activate_argv,$arg,$site);
84    }
85    elsif ($arg eq "-collectdir") {
86        $collect_dir = shift @argv;
87        push(@import_argv,$arg,$collect_dir);
88        push(@buildcol_argv,$arg,$collect_dir);
89        push(@activate_argv,$arg,$collect_dir);
90    }
91    elsif ($arg eq "-importdir") {
92        # only makes sense in import.pl
93        my $import_dir = shift @argv;
94        push(@import_argv,$arg,$import_dir);
95    }
96    elsif ($arg eq "-builddir") {
97        # only makes sense in buildcol.pl and activate.pl
98        $build_dir = shift @argv;
99        push(@buildcol_argv,$arg,$build_dir);
100        push(@activate_argv,$arg,$build_dir);
101    }
102    elsif ($arg eq "-indexdir") {
103        # only makes sense in buildcol.pl and activate.pl
104        $index_dir = shift @argv;
105        push(@buildcol_argv,$arg,$index_dir);
106        push(@activate_argv,$arg,$index_dir);
107    }
108    elsif ($arg eq "-verbosity") {     
109        $verbosity = shift @argv;
110        push(@import_argv,$arg,$verbosity);
111        push(@buildcol_argv,$arg,$verbosity);
112        push(@activate_argv,$arg,$verbosity);
113    }
114    elsif ($arg =~ /-import:(.*)$/) {       
115        my $import_arg = "-".$1;
116        my $import_val = shift @argv;
117        push(@import_argv,$import_arg,$import_val);
118    }
119    elsif ($arg =~ /-buildcol:(.*)$/) {     
120        my $buildcol_arg = "-".$1;
121        my $buildcol_val = shift @argv;
122        push(@buildcol_argv,$buildcol_arg,$buildcol_val);
123    }
124    elsif ($arg =~ /-activate:(.*)$/) {     
125        my $activate_arg = "-".$1;
126        my $activate_val = shift @argv;
127        push(@activate_argv,$activate_arg,$activate_val);
128    }
129    else {
130        push(@import_argv,$arg);
131        push(@buildcol_argv,$arg);
132        push(@activate_argv,$arg);
133    }
134    }
135   
136    my $quoted_import_argv = join(" ", map { "\"$_\"" } @import_argv);
137    my $quoted_buildcol_argv = join(" ", map { "\"$_\"" } @buildcol_argv);
138    my $quoted_activate_argv = join(" ", map { "\"$_\"" } @activate_argv);
139   
140    my $final_status = 0;
141
142    # need to ensure that the path to perl is quoted (in case there's spaces in it)
143    my $launch_cmd = "\"".&util::get_perl_exec()."\" -S ";   
144   
145    print "\n";
146    print "************************\n";
147    print "* Running  Import  Stage\n";
148    print "************************\n";
149
150    my $import_cmd = $launch_cmd . "full-import.pl $quoted_import_argv";
151
152    my $import_status = system($import_cmd)/256;
153   
154    if ($import_status == 0) {
155    print "\n";
156    print "************************\n";
157    print "* Running Buildcol Stage\n";
158    print "************************\n";
159   
160    my $buildcol_cmd = $launch_cmd . "full-buildcol.pl $quoted_buildcol_argv";
161    my $buildcol_status = system($buildcol_cmd)/256;
162
163    if ($buildcol_status == 0) {
164
165        # run activate with -removeold, just like full-buildcol.pl called above runs buildcol.pl
166        my $activatecol_cmd = $launch_cmd . "activate.pl -removeold $quoted_activate_argv";
167        my $activatecol_status = system($activatecol_cmd)/256;
168    }
169    else {
170        $final_status = $buildcol_status;
171    }
172    }
173    else {
174    $final_status = $import_status;
175    }
176   
177    exit($final_status);
178}
179
180&main(scalar(@ARGV),@ARGV);
181
Note: See TracBrowser for help on using the browser.