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

Last change on this file since 26913 was 26913, checked in by davidb, 8 years ago

More detailed usage statement added

  • Property svn:executable set to *
File size: 7.7 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'.\n";
108 print STDERR "\n";
109 print STDERR "Usage: $progname [options]| collection\n";
110 print STDERR " If a minus option is shared between import.pl and buildcol.pl then it can appear\n";
111 print STDERR " as is, such as -verbosity 5. This value will be passed to both programs.\n";
112 print STDERR " If a minus option is specific to one of the programs in particular, then prefix\n";
113 print STDERR " it with 'import:' or 'buildcol:' respectively, as in '-import:OIDtype hash_on_full_filename'\n";
114 print STDERR " Run 'import.pl' or 'buildcol.pl' from the command line with no arguments to see the\n";
115 print STDERR " specific values they take.\n";
116 print STDERR "\n";
117
118 exit(-1);
119 }
120
121
122 my $collect = pop @argv;
123
124
125 my @import_argv = ();
126 my @buildcol_argv = ();
127 my @activate_argv = ();
128
129 my $site = undef;
130 my $collect_dir = undef;
131 my $build_dir = undef;
132 my $index_dir = undef;
133 my $verbosity = 2; # same as the default in buildcol.pl
134
135 while (my $arg = shift @argv) {
136 if ($arg eq "-site") {
137 $site = shift @argv;
138 push(@import_argv,$arg,$site);
139 push(@buildcol_argv,$arg,$site);
140 push(@activate_argv,$arg,$site);
141 }
142 elsif ($arg eq "-collectdir") {
143 $collect_dir = shift @argv;
144 push(@import_argv,$arg,$collect_dir);
145 push(@buildcol_argv,$arg,$collect_dir);
146 push(@activate_argv,$arg,$collect_dir);
147 }
148 elsif ($arg eq "-importdir") {
149 # only makes sense in import.pl
150 my $import_dir = shift @argv;
151 push(@import_argv,$arg,$import_dir);
152 }
153 elsif ($arg eq "-builddir") {
154 # only makes sense in buildcol.pl and activate.pl
155 $build_dir = shift @argv;
156 push(@buildcol_argv,$arg,$build_dir);
157 push(@activate_argv,$arg,$build_dir);
158 }
159 elsif ($arg eq "-indexdir") {
160 # only makes sense in buildcol.pl and activate.pl
161 $index_dir = shift @argv;
162 push(@buildcol_argv,$arg,$index_dir);
163 push(@activate_argv,$arg,$index_dir);
164 }
165 elsif ($arg eq "-verbosity") {
166 $verbosity = shift @argv;
167 push(@import_argv,$arg,$verbosity);
168 push(@buildcol_argv,$arg,$verbosity);
169 push(@activate_argv,$arg,$verbosity);
170 }
171 elsif ($arg =~ /-import:(.*)$/) {
172 my $import_arg = "-".$1;
173 my $import_val = shift @argv;
174 push(@import_argv,$import_arg,$import_val);
175 }
176 elsif ($arg =~ /-buildcol:(.*)$/) {
177 my $buildcol_arg = "-".$1;
178 my $buildcol_val = shift @argv;
179 push(@buildcol_argv,$buildcol_arg,$buildcol_val);
180 }
181 elsif ($arg =~ /-activate:(.*)$/) {
182 my $activate_arg = "-".$1;
183 my $activate_val = shift @argv;
184 push(@activate_argv,$activate_arg,$activate_val);
185 }
186 else {
187 push(@import_argv,$arg);
188 push(@buildcol_argv,$arg);
189 push(@activate_argv,$arg);
190 }
191 }
192
193
194 my $quoted_import_argv = join(" ", map { "\"$_\"" } @import_argv);
195 my $quoted_buildcol_argv = join(" ", map { "\"$_\"" } @buildcol_argv);
196 my $quoted_activate_argv = join(" ", map { "\"$_\"" } @activate_argv);
197
198 my $final_status = 0;
199
200 # need to ensure that the path to perl is quoted (in case there's spaces in it)
201 my $launch_cmd = "\"".&util::get_perl_exec()."\" -S ";
202
203 print "\n";
204 print "************************\n";
205 print "* Running Import Stage\n";
206 print "************************\n";
207
208 my $import_cmd = $launch_cmd . "full-import.pl $quoted_import_argv \"$collect\"";
209
210 my $import_status = system($import_cmd)/256;
211
212 if ($import_status == 0) {
213 print "\n";
214 print "************************\n";
215 print "* Running Buildcol Stage\n";
216 print "************************\n";
217
218 my $buildcol_cmd = $launch_cmd . "full-buildcol.pl $quoted_buildcol_argv \"$collect\"";
219 my $buildcol_status = system($buildcol_cmd)/256;
220
221 if ($buildcol_status == 0) {
222
223 #full_replace($site,$collect_dir,$collect,$build_dir,$index_dir);
224
225 # run activate with -removeold, just like full-buildcol.pl called above runs buildcol.pl
226 my $activatecol_cmd = $launch_cmd . "activate.pl -removeold $quoted_activate_argv \"$collect\"";
227 my $activatecol_status = system($activatecol_cmd)/256;
228 }
229 else {
230 $final_status = $buildcol_status;
231 }
232 }
233 else {
234 $final_status = $import_status;
235 }
236
237 exit($final_status);
238}
239
240&main(scalar(@ARGV),@ARGV);
241
Note: See TracBrowser for help on using the repository browser.