source: main/trunk/greenstone2/bin/script/full-rebuild.pl@ 26441

Last change on this file since 26441 was 26441, checked in by davidb, 11 years ago

Additional minus-option syntax added to allow the user to specify a command that is sent to import.pl (e.g. -import:OIDType ...) or buildcol.pl (e.g. -buildcol:mode onlyinfodb).

  • Property svn:executable set to *
File size: 7.1 KB
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 ...
31# Followed by: full-buildcol.pl -removeold ...
32# (assumming import.pl did not end with an error)
33
34BEGIN {
35 die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
36 die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};
37 unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
38}
39
40use strict;
41use util;
42
43
44# This subroutine has been replaced by a call to activate.pl in sub main
45sub full_replace
46{
47 my ($site,$collect_dir,$collect,$build_dir,$index_dir) = @_;
48
49
50 if (!defined $build_dir) {
51 if (defined $collect_dir) {
52 $build_dir = &util::filename_cat($collect_dir,$collect, "building");
53 }
54 else {
55 if (defined $site) {
56 $build_dir = &util::filename_cat($ENV{'GSDL3HOME'},"sites",$site,"collect",$collect, "building");
57 }
58 else {
59 $build_dir = &util::filename_cat($ENV{'GSDLHOME'},"collect",$collect, "building");
60 }
61 }
62 }
63
64 if (!defined $index_dir) {
65 if (defined $collect_dir) {
66 $index_dir = &util::filename_cat($collect_dir,$collect, "index");
67 }
68 else {
69 if (defined $site) {
70 $index_dir = &util::filename_cat($ENV{'GSDL3HOME'},"sites",$site,"collect",$collect, "index");
71 }
72 else {
73 $index_dir = &util::filename_cat($ENV{'GSDLHOME'},"collect",$collect, "index");
74 }
75 }
76 }
77
78 if (-e $index_dir) {
79 print "\n";
80 print "************************\n";
81 print "* Removing \"index\"\n";
82 print "************************\n";
83
84 # An improvement would be to check on error status
85 &util::rm_r($index_dir);
86 }
87
88 print "\n";
89 print "************************\n";
90 print "* Moving \"building\" -> \"index\"\n";
91 print "************************\n";
92
93 # An improvement would be to check on error status
94 &util::mv($build_dir,$index_dir);
95}
96
97sub main
98{
99 my ($argc,@argv) = @_;
100
101 if (($argc==0) || (($argc==1) && ($argv[0] =~ m/^--?h(elp)?$/))) {
102 my ($progname) = ($0 =~ m/^.*\/(.*?)$/);
103
104 print STDERR "\n";
105 print STDERR "This program runs import.pl followed by buildcol.pl (in both cases removing any previously\n";
106 print STDERR " generated files in 'archives' or 'building'), and then replaces the content of collection's\n";
107 print STDERR " 'index' directory with 'building'.";
108 print STDERR "\n";
109 print STDERR "Usage: $progname [option shared between import.pl and buildcol.pl] collection\n";
110 print STDERR "\n";
111
112 exit(-1);
113 }
114
115
116 my $collect = pop @argv;
117
118
119 my @import_argv = ();
120 my @buildcol_argv = ();
121 my @activate_argv = ();
122
123 my $site = undef;
124 my $collect_dir = undef;
125 my $build_dir = undef;
126 my $index_dir = undef;
127 my $verbosity = 2; # same as the default in buildcol.pl
128
129 while (my $arg = shift @argv) {
130 if ($arg eq "-site") {
131 $site = shift @argv;
132 push(@import_argv,$arg,$site);
133 push(@buildcol_argv,$arg,$site);
134 push(@activate_argv,$arg,$site);
135 }
136 elsif ($arg eq "-collectdir") {
137 $collect_dir = shift @argv;
138 push(@import_argv,$arg,$collect_dir);
139 push(@buildcol_argv,$arg,$collect_dir);
140 push(@activate_argv,$arg,$collect_dir);
141 }
142 elsif ($arg eq "-importdir") {
143 # only makes sense in import.pl
144 my $import_dir = shift @argv;
145 push(@import_argv,$arg,$import_dir);
146 }
147 elsif ($arg eq "-builddir") {
148 # only makes sense in buildcol.pl and activate.pl
149 $build_dir = shift @argv;
150 push(@buildcol_argv,$arg,$build_dir);
151 push(@activate_argv,$arg,$build_dir);
152 }
153 elsif ($arg eq "-indexdir") {
154 # only makes sense in buildcol.pl and activate.pl
155 $index_dir = shift @argv;
156 push(@buildcol_argv,$arg,$index_dir);
157 push(@activate_argv,$arg,$index_dir);
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 }
165 elsif ($arg =~ /-import:(.*)$/) {
166 my $import_arg = "-".$1;
167 my $import_val = shift @argv;
168 push(@import_argv,$import_arg,$import_val);
169 }
170 elsif ($arg =~ /-buildcol:(.*)$/) {
171 my $buildcol_arg = "-".$1;
172 my $buildcol_val = shift @argv;
173 push(@buildcol_argv,$buildcol_arg,$buildcol_val);
174 }
175 elsif ($arg =~ /-activate:(.*)$/) {
176 my $activate_arg = "-".$1;
177 my $activate_val = shift @argv;
178 push(@activate_argv,$activate_arg,$activate_val);
179 }
180 else {
181 push(@import_argv,$arg);
182 push(@buildcol_argv,$arg);
183 push(@activate_argv,$arg);
184 }
185 }
186
187
188 my $quoted_import_argv = join(" ", map { "\"$_\"" } @import_argv);
189 my $quoted_buildcol_argv = join(" ", map { "\"$_\"" } @buildcol_argv);
190 my $quoted_activate_argv = join(" ", map { "\"$_\"" } @activate_argv);
191
192 my $final_status = 0;
193
194 # need to ensure that the path to perl is quoted (in case there's spaces in it)
195 my $launch_cmd = "\"".&util::get_perl_exec()."\" -S ";
196
197 print "\n";
198 print "************************\n";
199 print "* Running Import Stage\n";
200 print "************************\n";
201
202 my $import_cmd = $launch_cmd . "full-import.pl $quoted_import_argv \"$collect\"";
203
204 my $import_status = system($import_cmd)/256;
205
206 if ($import_status == 0) {
207 print "\n";
208 print "************************\n";
209 print "* Running Buildcol Stage\n";
210 print "************************\n";
211
212 my $buildcol_cmd = $launch_cmd . "full-buildcol.pl $quoted_buildcol_argv \"$collect\"";
213 my $buildcol_status = system($buildcol_cmd)/256;
214
215 if ($buildcol_status == 0) {
216
217 #full_replace($site,$collect_dir,$collect,$build_dir,$index_dir);
218
219 # run activate with -removeold, just like full-buildcol.pl called above runs buildcol.pl
220 my $activatecol_cmd = $launch_cmd . "activate.pl -removeold $quoted_activate_argv \"$collect\"";
221 my $activatecol_status = system($activatecol_cmd)/256;
222 }
223 else {
224 $final_status = $buildcol_status;
225 }
226 }
227 else {
228 $final_status = $import_status;
229 }
230
231 exit($final_status);
232}
233
234&main(scalar(@ARGV),@ARGV);
235
Note: See TracBrowser for help on using the repository browser.