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

Last change on this file was 38754, checked in by kjdon, 2 months ago

added handling for -importflag, -buildcolflag, -activateflag - use these for flag options which have to value

  • 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 [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 " If a minus option has no value, prefix it with\n";
62 print STDERR " '-importflag:', '-buildcolflag:', '-activateflag:'\n";
63 print STDERR " as in '-activateflag:skipactivation'\n";
64 print STDERR " Run '(full-)import.pl -h', '(full-)buildcol.pl -h', 'activate.pl -h' from the \n";
65 print STDERR " command line to see the specific values they take.\n";
66 print STDERR "\n";
67
68 exit(-1);
69 }
70
71 my @import_argv = ();
72 my @buildcol_argv = ();
73 my @activate_argv = ();
74
75 my $site = undef;
76 my $collect_dir = undef;
77 my $build_dir = undef;
78 my $index_dir = undef;
79 my $verbosity = 2; # same as the default in buildcol.pl
80
81 while (my $arg = shift @argv) {
82 if ($arg eq "-site") {
83 $site = shift @argv;
84 push(@import_argv,$arg,$site);
85 push(@buildcol_argv,$arg,$site);
86 push(@activate_argv,$arg,$site);
87 }
88 elsif ($arg eq "-collectdir") {
89 $collect_dir = shift @argv;
90 push(@import_argv,$arg,$collect_dir);
91 push(@buildcol_argv,$arg,$collect_dir);
92 push(@activate_argv,$arg,$collect_dir);
93 }
94 elsif ($arg eq "-importdir") {
95 # only makes sense in import.pl
96 my $import_dir = shift @argv;
97 push(@import_argv,$arg,$import_dir);
98 }
99 elsif ($arg eq "-builddir") {
100 # only makes sense in buildcol.pl and activate.pl
101 $build_dir = shift @argv;
102 push(@buildcol_argv,$arg,$build_dir);
103 push(@activate_argv,$arg,$build_dir);
104 }
105 elsif ($arg eq "-indexdir") {
106 # only makes sense in buildcol.pl and activate.pl
107 $index_dir = shift @argv;
108 push(@buildcol_argv,$arg,$index_dir);
109 push(@activate_argv,$arg,$index_dir);
110 }
111 elsif ($arg eq "-verbosity") {
112 $verbosity = shift @argv;
113 push(@import_argv,$arg,$verbosity);
114 push(@buildcol_argv,$arg,$verbosity);
115 push(@activate_argv,$arg,$verbosity);
116 }
117 elsif ($arg =~ /-import:(.*)$/) {
118 my $import_arg = "-".$1;
119 my $import_val = shift @argv;
120 push(@import_argv,$import_arg,$import_val);
121 }
122 elsif ($arg =~ /-importflag:(.*)$/) {
123 my $import_arg = "-".$1;
124 push(@import_argv, $import_arg);
125 }
126 elsif ($arg =~ /-buildcol:(.*)$/) {
127 my $buildcol_arg = "-".$1;
128 my $buildcol_val = shift @argv;
129 push(@buildcol_argv,$buildcol_arg,$buildcol_val);
130 }
131 elsif ($arg =~ /-buildcolflag:(.*)$/) {
132 my $buildcol_arg = "-".$1;
133 push(@buildcol_argv,$buildcol_arg);
134 }
135 elsif ($arg =~ /-activate:(.*)$/) {
136 my $activate_arg = "-".$1;
137 my $activate_val = shift @argv;
138 push(@activate_argv,$activate_arg,$activate_val);
139 }
140 elsif ($arg =~ /-activateflag:(.*)$/) {
141 my $activate_arg = "-".$1;
142 push(@activate_argv,$activate_arg);
143 }
144 elsif ($arg eq "-library_url" || $arg eq "-library_name") {
145 # only makes sense in buildcol.pl and activate.pl
146 # we want buildcol.pl to send it to activate if running buildcol.pl with -activate
147 # And we want activate.pl to get it if running activate.pl
148 my $library_info = shift @argv;
149 push(@buildcol_argv,$arg,$library_info);
150 push(@activate_argv,$arg,$library_info);
151 }
152 elsif ($arg =~ "-OIDtype") {
153 shift @argv; # skip OIDtype (don't pass OIDtype to buildcol.pl. It's not currently accepted.)
154 # this allows us to run full-rebuild.pl -OIDtype filename for instance
155 }
156 else {
157 push(@import_argv,$arg);
158 push(@buildcol_argv,$arg);
159 push(@activate_argv,$arg);
160 }
161 }
162
163 my $quoted_import_argv = join(" ", map { "\"$_\"" } @import_argv);
164 my $quoted_buildcol_argv = join(" ", map { "\"$_\"" } @buildcol_argv);
165 my $quoted_activate_argv = join(" ", map { "\"$_\"" } @activate_argv);
166
167 my $final_status = 0;
168
169 # need to ensure that the path to perl is quoted (in case there's spaces in it)
170 my $launch_cmd = "\"".&util::get_perl_exec()."\" -S ";
171
172 my $import_cmd = $launch_cmd . "full-import.pl $quoted_import_argv";
173
174 print "\n";
175 print "************************\n";
176 print "* Running Import Stage\n";
177 print "* Command: $import_cmd\n";
178 print "************************\n";
179
180 my $import_status = system($import_cmd)/256;
181
182 if ($import_status == 0) {
183 my $buildcol_cmd = $launch_cmd . "full-buildcol.pl $quoted_buildcol_argv";
184
185 print "\n";
186 print "************************\n";
187 print "* Running Buildcol Stage\n";
188 print "* Command: $buildcol_cmd\n";
189 print "************************\n";
190
191 my $buildcol_status = system($buildcol_cmd)/256;
192
193 if ($buildcol_status == 0) {
194
195 # run activate with -removeold, just like full-buildcol.pl called above runs buildcol.pl
196 my $activatecol_cmd = $launch_cmd . "activate.pl -removeold $quoted_activate_argv";
197 print "\n";
198 print "************************\n";
199 print "* Running Activate Stage\n";
200 print "* Command: $activatecol_cmd\n";
201 print "************************\n";
202
203 my $activatecol_status = system($activatecol_cmd)/256;
204 }
205 else {
206 $final_status = $buildcol_status;
207 }
208 }
209 else {
210 $final_status = $import_status;
211 }
212
213 exit($final_status);
214}
215
216&main(scalar(@ARGV),@ARGV);
217
Note: See TracBrowser for help on using the repository browser.