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

Last change on this file since 25579 was 25579, checked in by ak19, 9 years ago
  1. Introduced the verbosity flag into activate.pl to print out debugging statements depending on verbosity, and this is passed in from buildcol.pl and full-rebuild.pl too now. 2. Cleaned up some debugging code.
  • Property svn:executable set to *
File size: 6.6 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 else {
166 push(@import_argv,$arg);
167 push(@buildcol_argv,$arg);
168 push(@activate_argv,$arg);
169 }
170 }
171
172
173 my $quoted_import_argv = join(" ", map { "\"$_\"" } @import_argv);
174 my $quoted_buildcol_argv = join(" ", map { "\"$_\"" } @buildcol_argv);
175 my $quoted_activate_argv = join(" ", map { "\"$_\"" } @activate_argv);
176
177 my $final_status = 0;
178
179 # need to ensure that the path to perl is quoted (in case there's spaces in it)
180 my $launch_cmd = "\"".&util::get_perl_exec()."\" -S ";
181
182 print "\n";
183 print "************************\n";
184 print "* Running Import Stage\n";
185 print "************************\n";
186
187 my $import_cmd = $launch_cmd . "full-import.pl $quoted_import_argv \"$collect\"";
188
189 my $import_status = system($import_cmd)/256;
190
191 if ($import_status == 0) {
192 print "\n";
193 print "************************\n";
194 print "* Running Buildcol Stage\n";
195 print "************************\n";
196
197 my $buildcol_cmd = $launch_cmd . "full-buildcol.pl $quoted_buildcol_argv \"$collect\"";
198 my $buildcol_status = system($buildcol_cmd)/256;
199
200 if ($buildcol_status == 0) {
201
202 #full_replace($site,$collect_dir,$collect,$build_dir,$index_dir);
203
204 # run activate with -removeold, just like full-buildcol.pl called above runs buildcol.pl
205 my $activatecol_cmd = $launch_cmd . "activate.pl -removeold $quoted_activate_argv \"$collect\"";
206 my $activatecol_status = system($activatecol_cmd)/256;
207 }
208 else {
209 $final_status = $buildcol_status;
210 }
211 }
212 else {
213 $final_status = $import_status;
214 }
215
216 exit($final_status);
217}
218
219&main(scalar(@ARGV),@ARGV);
220
Note: See TracBrowser for help on using the repository browser.