1 | ###############################################################################
|
---|
2 | #
|
---|
3 | # buildcolutils.pm -- index and build the collection. The buildtime counterpart
|
---|
4 | # of inexport.pl
|
---|
5 | #
|
---|
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) 1999 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 | package buildcolutils;
|
---|
29 |
|
---|
30 | use File::Basename;
|
---|
31 |
|
---|
32 | use colcfg;
|
---|
33 | use dbutil;
|
---|
34 | use util;
|
---|
35 | use FileUtils;
|
---|
36 | use scriptutil;
|
---|
37 | use gsprintf;
|
---|
38 | use printusage;
|
---|
39 | use parse2;
|
---|
40 |
|
---|
41 | ## @method new()
|
---|
42 | #
|
---|
43 | # Parses up and validates the arguments to the build process before creating
|
---|
44 | # the appropriate build process to do the actual work
|
---|
45 | #
|
---|
46 | # @note Added true incremental support - John Thompson, DL Consulting Ltd.
|
---|
47 | # @note There were several bugs regarding using directories other than
|
---|
48 | # "import" or "archives" during import and build quashed. - John
|
---|
49 | # Thompson, DL Consulting Ltd.
|
---|
50 | #
|
---|
51 | # @param $incremental If true indicates this build should not regenerate all
|
---|
52 | # the index and metadata files, and should instead just
|
---|
53 | # append the information found in the archives directory
|
---|
54 | # to the existing files. If this requires some complex
|
---|
55 | # work so as to correctly insert into a classifier so be
|
---|
56 | # it. Of course none of this is done here - instead the
|
---|
57 | # incremental argument is passed to the document
|
---|
58 | # processor.
|
---|
59 | #
|
---|
60 | sub new
|
---|
61 | {
|
---|
62 | my $class = shift(@_);
|
---|
63 | my ($argv, $options, $opt_listall_options) = @_;
|
---|
64 |
|
---|
65 | my $self = {'builddir' => undef,
|
---|
66 | 'buildtype' => undef,
|
---|
67 | 'close_faillog' => 0,
|
---|
68 | 'close_out' => 0,
|
---|
69 | 'mode' => '',
|
---|
70 | 'orthogonalbuildtypes' => undef,
|
---|
71 | 'realbuilddir' => undef,
|
---|
72 | 'textindex' => '',
|
---|
73 | 'xml' => 0
|
---|
74 | };
|
---|
75 |
|
---|
76 | # general options available to all plugins
|
---|
77 | my $arguments = $options->{'args'};
|
---|
78 | my $intArgLeftinAfterParsing = &parse2::parse($argv, $arguments, $self, "allow_extra_options");
|
---|
79 | # If parse returns -1 then something has gone wrong
|
---|
80 | if ($intArgLeftinAfterParsing == -1)
|
---|
81 | {
|
---|
82 | &PrintUsage::print_txt_usage($options, "{buildcol.params}");
|
---|
83 | die "\n";
|
---|
84 | }
|
---|
85 |
|
---|
86 | # If $language has been specified, load the appropriate resource bundle
|
---|
87 | # (Otherwise, the default resource bundle will be loaded automatically)
|
---|
88 | if ($self->{'language'} && $self->{'language'} =~ /\S/)
|
---|
89 | {
|
---|
90 | &gsprintf::load_language_specific_resource_bundle($self->{'language'});
|
---|
91 | }
|
---|
92 |
|
---|
93 | # Do we need 'listall' support in buildcol? If so, copy code from inexport
|
---|
94 | # later [jmt12]
|
---|
95 |
|
---|
96 | # <insert explanation here>
|
---|
97 | if ($self->{'xml'})
|
---|
98 | {
|
---|
99 | &PrintUsage::print_xml_usage($options);
|
---|
100 | print "\n";
|
---|
101 | return bless($self, $class);
|
---|
102 | }
|
---|
103 |
|
---|
104 | # the gli wants strings to be in UTF-8
|
---|
105 | if ($gli)
|
---|
106 | {
|
---|
107 | &gsprintf::output_strings_in_UTF8;
|
---|
108 | }
|
---|
109 |
|
---|
110 | # now check that we had exactly one leftover arg, which should be
|
---|
111 | # the collection name. We don't want to do this earlier, cos
|
---|
112 | # -xml arg doesn't need a collection name
|
---|
113 | # Or if the user specified -h, then we output the usage also
|
---|
114 | if ($intArgLeftinAfterParsing != 1 || (@ARGV && $ARGV[0] =~ /^\-+h/))
|
---|
115 | {
|
---|
116 | &PrintUsage::print_txt_usage($options, "{buildcol.params}");
|
---|
117 | die "\n";
|
---|
118 | }
|
---|
119 |
|
---|
120 | my $out = $self->{'out'};
|
---|
121 | if ($out !~ /^(STDERR|STDOUT)$/i)
|
---|
122 | {
|
---|
123 | open (OUT, ">$out") || (&gsprintf::gsprintf(STDERR, "{common.cannot_open_output_file}\n", $out) && die);
|
---|
124 | $out = "buildcolutils::OUT";
|
---|
125 | $self->{'close_out'} = 1;
|
---|
126 | }
|
---|
127 | $out->autoflush(1);
|
---|
128 | $self->{'out'} = $out;
|
---|
129 |
|
---|
130 | # @ARGV should be only one item, the name of the collection
|
---|
131 | $self->{'collection'} = shift(@{$argv});
|
---|
132 |
|
---|
133 | return bless($self, $class);
|
---|
134 | }
|
---|
135 | # new()
|
---|
136 |
|
---|
137 | # newCGI()?
|
---|
138 |
|
---|
139 | # @function get_collection
|
---|
140 | #
|
---|
141 | sub get_collection
|
---|
142 | {
|
---|
143 | my $self = shift @_;
|
---|
144 | return $self->{'collection'};
|
---|
145 | }
|
---|
146 | # get_collection()
|
---|
147 |
|
---|
148 | # @function read_collection_cfg
|
---|
149 | #
|
---|
150 | sub read_collection_cfg
|
---|
151 | {
|
---|
152 | my $self = shift(@_);
|
---|
153 | my ($collection, $options) = @_;
|
---|
154 |
|
---|
155 | my $collectdir = $self->{'collectdir'};
|
---|
156 | my $site = $self->{'site'};
|
---|
157 | my $out = $self->{'out'};
|
---|
158 |
|
---|
159 | # get and check the collection
|
---|
160 | if (($collection = &colcfg::use_collection($site, $collection, $collectdir)) eq "")
|
---|
161 | {
|
---|
162 | &PrintUsage::print_txt_usage($options, "{buildcol.params}");
|
---|
163 | die "\n";
|
---|
164 | }
|
---|
165 |
|
---|
166 | # set gs_version 2/3
|
---|
167 | $self->{'gs_version'} = "2";
|
---|
168 | if ((defined $site) && ($site ne ""))
|
---|
169 | {
|
---|
170 | # gs3
|
---|
171 | $self->{'gs_version'} = "3";
|
---|
172 | }
|
---|
173 |
|
---|
174 | # add collection's perllib dir into include path in case we have collection
|
---|
175 | # specific modules
|
---|
176 | &util::augmentINC(&FileUtils::filenameConcatenate($ENV{'GSDLCOLLECTDIR'}, 'perllib'));
|
---|
177 | &util::augmentINC(&FileUtils::filenameConcatenate($ENV{'GSDLCOLLECTDIR'}, 'perllib', 'classify'));
|
---|
178 | &util::augmentINC(&FileUtils::filenameConcatenate($ENV{'GSDLCOLLECTDIR'}, 'perllib', 'plugins'));
|
---|
179 |
|
---|
180 | # check that we can open the faillog
|
---|
181 | my $faillog = $self->{'faillog'};
|
---|
182 | if ($faillog eq "")
|
---|
183 | {
|
---|
184 | $faillog = &FileUtils::filenameConcatenate($ENV{'GSDLCOLLECTDIR'}, "etc", "fail.log");
|
---|
185 | }
|
---|
186 | # note that we're appending to the faillog here (import.pl clears it each time)
|
---|
187 | # this could potentially create a situation where the faillog keeps being added
|
---|
188 | # to over multiple builds (if the import process is being skipped)
|
---|
189 | open (FAILLOG, ">>$faillog") || (&gsprintf::gsprintf(STDERR, "{common.cannot_open_fail_log}\n", $faillog) && die);
|
---|
190 | $faillog = 'buildcolutils::FAILLOG';
|
---|
191 | $faillog->autoflush(1);
|
---|
192 | $self->{'faillog'} = $faillog;
|
---|
193 | $self->{'faillogname'} = $faillog;
|
---|
194 | $self->{'close_faillog'} = 1;
|
---|
195 |
|
---|
196 | # Read in the collection configuration file.
|
---|
197 | my $gs_mode = "gs".$self->{'gs_version'}; #gs2 or gs3
|
---|
198 | my $config_filename = &colcfg::get_collect_cfg_name($out, $gs_mode);
|
---|
199 | my $collect_cfg = &colcfg::read_collection_cfg($config_filename, $gs_mode);
|
---|
200 |
|
---|
201 | return ($config_filename, $collect_cfg);
|
---|
202 | }
|
---|
203 | # read_collection_cfg()
|
---|
204 |
|
---|
205 | # @function set_collection_options
|
---|
206 | # This function copies across values for arguments from the collection
|
---|
207 | # configuration file if they are not already provided by the user, then
|
---|
208 | # sets reasonable defaults for any required arguments that remains without
|
---|
209 | # a value.
|
---|
210 | sub set_collection_options
|
---|
211 | {
|
---|
212 | my $self = shift @_;
|
---|
213 | my ($collectcfg) = @_;
|
---|
214 | my ($buildtype, $orthogonalbuildtypes);
|
---|
215 |
|
---|
216 | # If the infodbtype value wasn't defined in the collect.cfg file, use the default
|
---|
217 | if (!defined($collectcfg->{'infodbtype'}))
|
---|
218 | {
|
---|
219 | $collectcfg->{'infodbtype'} = &dbutil::get_default_infodb_type();
|
---|
220 | }
|
---|
221 | # - just so I don't have to pass collectcfg around as well
|
---|
222 | $self->{'infodbtype'} = $collectcfg->{'infodbtype'};
|
---|
223 |
|
---|
224 | if ($self->{'verbosity'} !~ /\d+/)
|
---|
225 | {
|
---|
226 | if (defined $collectcfg->{'verbosity'} && $collectcfg->{'verbosity'} =~ /\d+/)
|
---|
227 | {
|
---|
228 | $self->{'verbosity'} = $collectcfg->{'verbosity'};
|
---|
229 | }
|
---|
230 | else
|
---|
231 | {
|
---|
232 | $self->{'verbosity'} = 2; # the default
|
---|
233 | }
|
---|
234 | }
|
---|
235 |
|
---|
236 | # we use searchtype for determining buildtype, but for old versions, use buildtype
|
---|
237 | if (defined $collectcfg->{'buildtype'})
|
---|
238 | {
|
---|
239 | $self->{'buildtype'} = $collectcfg->{'buildtype'};
|
---|
240 | }
|
---|
241 | elsif (defined $collectcfg->{'searchtypes'} || defined $collectcfg->{'searchtype'})
|
---|
242 | {
|
---|
243 | $self->{'buildtype'} = "mgpp";
|
---|
244 | }
|
---|
245 | else
|
---|
246 | {
|
---|
247 | $self->{'buildtype'} = "mg"; #mg is the default
|
---|
248 | }
|
---|
249 |
|
---|
250 | if ($self->{'buildtype'} eq "mgpp" && defined $collectcfg->{'textcompress'})
|
---|
251 | {
|
---|
252 | $self->{'textindex'} = $collectcfg->{'textcompress'};
|
---|
253 | }
|
---|
254 |
|
---|
255 | # is it okay to always clobber or possible remain undefined? [jmt12]
|
---|
256 | if (defined $collectcfg->{'orthogonalbuildtypes'})
|
---|
257 | {
|
---|
258 | $self->{'orthogonalbuildtypes'} = $collectcfg->{'orthogonalbuildtypes'};
|
---|
259 | }
|
---|
260 |
|
---|
261 | # - resolve (and possibly set to default) builddir
|
---|
262 | if (defined $collectcfg->{'archivedir'} && $self->{'archivedir'} eq "")
|
---|
263 | {
|
---|
264 | $self->{'archivedir'} = $collectcfg->{'archivedir'};
|
---|
265 | }
|
---|
266 | # Modified so that the archivedir, if provided as an argument, is made
|
---|
267 | # absolute if it isn't already
|
---|
268 | if ($self->{'archivedir'} eq "")
|
---|
269 | {
|
---|
270 | $self->{'archivedir'} = &FileUtils::filenameConcatenate($ENV{'GSDLCOLLECTDIR'}, "archives");
|
---|
271 | }
|
---|
272 | else
|
---|
273 | {
|
---|
274 | $self->{'archivedir'} = &util::make_absolute($ENV{'GSDLCOLLECTDIR'}, $archivedir);
|
---|
275 | }
|
---|
276 | # End Mod
|
---|
277 | $self->{'archivedir'} = &FileUtils::sanitizePath($self->{'archivedir'});
|
---|
278 | #$self->{'archivedir'} =~ s/[\\\/]+/\//g;
|
---|
279 | #$self->{'archivedir'} =~ s/\/$//;
|
---|
280 |
|
---|
281 | # - resolve (and possibly set to default) builddir
|
---|
282 | if (defined $collectcfg->{'builddir'} && $self->{'builddir'} eq "")
|
---|
283 | {
|
---|
284 | $self->{'builddir'} = $collectcfg->{'builddir'};
|
---|
285 | }
|
---|
286 | if ($self->{'builddir'} eq "")
|
---|
287 | {
|
---|
288 | $self->{'builddir'} = &FileUtils::filenameConcatenate($ENV{'GSDLCOLLECTDIR'}, 'building');
|
---|
289 | if ($incremental)
|
---|
290 | {
|
---|
291 | &gsprintf::gsprintf($out, "{buildcol.incremental_default_builddir}\n");
|
---|
292 | }
|
---|
293 | }
|
---|
294 | # - why don't we make builddir absolute similar to archivedir?
|
---|
295 | $self->{'builddir'} = &FileUtils::sanitizePath($self->{'builddir'});
|
---|
296 | #$self->{'builddir'} =~ s/[\\\/]+/\//g;
|
---|
297 | #$self->{'builddir'} =~ s/\/$//;
|
---|
298 |
|
---|
299 | if (defined $collectcfg->{'cachedir'} && $self->{'cachedir'} eq "")
|
---|
300 | {
|
---|
301 | $self->{'cachedir'} = $collectcfg->{'cachedir'};
|
---|
302 | }
|
---|
303 |
|
---|
304 | if ($self->{'maxdocs'} !~ /\-?\d+/)
|
---|
305 | {
|
---|
306 | if (defined $collectcfg->{'maxdocs'} && $collectcfg->{'maxdocs'} =~ /\-?\d+/)
|
---|
307 | {
|
---|
308 | $self->{'maxdocs'} = $collectcfg->{'maxdocs'};
|
---|
309 | }
|
---|
310 | else
|
---|
311 | {
|
---|
312 | $self->{'maxdocs'} = -1; # the default
|
---|
313 | }
|
---|
314 | }
|
---|
315 |
|
---|
316 | # always clobbers? [jmt12]
|
---|
317 | if (defined $collectcfg->{'maxnumeric'} && $collectcfg->{'maxnumeric'} =~ /\d+/)
|
---|
318 | {
|
---|
319 | $self->{'maxnumeric'} = $collectcfg->{'maxnumeric'};
|
---|
320 | }
|
---|
321 | if ($self->{'maxnumeric'} < 4 || $self->{'maxnumeric'} > 512)
|
---|
322 | {
|
---|
323 | $self->{'maxnumeric'} = 4;
|
---|
324 | }
|
---|
325 |
|
---|
326 | if (defined $collectcfg->{'debug'} && $collectcfg->{'debug'} =~ /^true$/i)
|
---|
327 | {
|
---|
328 | $self->{'debug'} = 1;
|
---|
329 | }
|
---|
330 |
|
---|
331 | if ($self->{'mode'} !~ /^(all|compress_text|build_index|infodb)$/)
|
---|
332 | {
|
---|
333 | if (defined $collectcfg->{'mode'} && $collectcfg->{'mode'} =~ /^(all|compress_text|build_index|infodb)$/)
|
---|
334 | {
|
---|
335 | $self->{'mode'} = $collectcfg->{'mode'};
|
---|
336 | }
|
---|
337 | else
|
---|
338 | {
|
---|
339 | $self->{'mode'} = "all"; # the default
|
---|
340 | }
|
---|
341 | }
|
---|
342 |
|
---|
343 | # Presumably 'index' from the collect.cfg still works [jmt12]
|
---|
344 | if (defined $collectcfg->{'index'} && $self->{'indexname'} eq "")
|
---|
345 | {
|
---|
346 | $self->{'indexname'} = $collectcfg->{'index'};
|
---|
347 | }
|
---|
348 | # - 'index' from the command line doesn't make it through parsing so I
|
---|
349 | # renamed this option 'indexname' [jmt12]
|
---|
350 | if (defined $collectcfg->{'indexname'} && $self->{'indexname'} eq "")
|
---|
351 | {
|
---|
352 | $self->{'indexname'} = $collectcfg->{'indexname'};
|
---|
353 | }
|
---|
354 | # - we may also define the index level to build now [jmt12]
|
---|
355 | if (defined $collectcfg->{'indexlevel'} && $self->{'indexlevel'} eq "")
|
---|
356 | {
|
---|
357 | $self->{'indexlevel'} = $collectcfg->{'indexlevel'};
|
---|
358 | }
|
---|
359 |
|
---|
360 | if (defined $collectcfg->{'no_text'} && $self->{'no_text'} == 0)
|
---|
361 | {
|
---|
362 | if ($collectcfg->{'no_text'} =~ /^true$/i)
|
---|
363 | {
|
---|
364 | $self->{'no_text'} = 1;
|
---|
365 | }
|
---|
366 | }
|
---|
367 |
|
---|
368 | if (defined $collectcfg->{'no_strip_html'} && $self->{'no_strip_html'} == 0)
|
---|
369 | {
|
---|
370 | if ($collectcfg->{'no_strip_html'} =~ /^true$/i)
|
---|
371 | {
|
---|
372 | $self->{'no_strip_html'} = 1;
|
---|
373 | }
|
---|
374 | }
|
---|
375 |
|
---|
376 | if (defined $collectcfg->{'store_metadata_coverage'} && $self->{'store_metadata_coverage'} == 0)
|
---|
377 | {
|
---|
378 | if ($collectcfg->{'store_metadata_coverage'} =~ /^true$/i)
|
---|
379 | {
|
---|
380 | $self->{'store_metadata_coverage'} = 1;
|
---|
381 | }
|
---|
382 | }
|
---|
383 |
|
---|
384 | if (defined $collectcfg->{'remove_empty_classifications'} && $self->{'remove_empty_classifications'} == 0)
|
---|
385 | {
|
---|
386 | if ($collectcfg->{'remove_empty_classifications'} =~ /^true$/i)
|
---|
387 | {
|
---|
388 | $self->{'remove_empty_classifications'} = 1;
|
---|
389 | }
|
---|
390 | }
|
---|
391 |
|
---|
392 | if (defined $collectcfg->{'gli'} && $collectcfg->{'gli'} =~ /^true$/i)
|
---|
393 | {
|
---|
394 | $self->{'gli'} = 1;
|
---|
395 | }
|
---|
396 | if (!defined $self->{'gli'})
|
---|
397 | {
|
---|
398 | $self->{'gli'} = 0;
|
---|
399 | }
|
---|
400 |
|
---|
401 | if ($self->{'sections_index_document_metadata'} !~ /\S/ && defined $collectcfg->{'sections_index_document_metadata'})
|
---|
402 | {
|
---|
403 | $self->{'sections_index_document_metadata'} = $collectcfg->{'sections_index_document_metadata'};
|
---|
404 | }
|
---|
405 |
|
---|
406 | if ($self->{'sections_index_document_metadata'} !~ /^(never|always|unless_section_metadata_exists)$/) {
|
---|
407 | $self->{'sections_index_document_metadata'} = 'never';
|
---|
408 | }
|
---|
409 |
|
---|
410 | if ($self->{'sections_sort_on_document_metadata'} !~ /\S/ && defined $collectcfg->{'sections_sort_on_document_metadata'})
|
---|
411 | {
|
---|
412 | $self->{'sections_sort_on_document_metadata'} = $collectcfg->{'sections_sort_on_document_metadata'};
|
---|
413 | }
|
---|
414 |
|
---|
415 | if ($self->{'sections_sort_on_document_metadata'} !~ /^(never|always|unless_section_metadata_exists)$/) {
|
---|
416 | $self->{'sections_sort_on_document_metadata'} = 'never';
|
---|
417 | }
|
---|
418 |
|
---|
419 | my ($removeold, $keepold, $incremental, $incremental_mode)
|
---|
420 | = &scriptutil::check_removeold_and_keepold($self->{'removeold'}, $self->{'keepold'},
|
---|
421 | $self->{'incremental'}, 'building',
|
---|
422 | $collectcfg);
|
---|
423 | $self->{'removeold'} = $removeold;
|
---|
424 | $self->{'keepold'} = $keepold;
|
---|
425 | $self->{'incremental'} = $incremental;
|
---|
426 | $self->{'incremental_mode'} = $incremental_mode;
|
---|
427 |
|
---|
428 | # New argument to track whether build is incremental
|
---|
429 | if (!defined $self->{'incremental'})
|
---|
430 | {
|
---|
431 | $self->{'incremental'} = 0;
|
---|
432 | }
|
---|
433 |
|
---|
434 | #set the text index
|
---|
435 | if (($self->{'buildtype'} eq 'mgpp') || ($self->{'buildtype'} eq 'lucene') || ($self->{'buildtype'} eq 'solr'))
|
---|
436 | {
|
---|
437 | if ($self->{'textindex'} eq '')
|
---|
438 | {
|
---|
439 | $self->{'textindex'} = 'text';
|
---|
440 | }
|
---|
441 | }
|
---|
442 | else
|
---|
443 | {
|
---|
444 | $self->{'textindex'} = 'section:text';
|
---|
445 | }
|
---|
446 | }
|
---|
447 | # set_collection_options()
|
---|
448 |
|
---|
449 | # @function prepare_builders
|
---|
450 | #
|
---|
451 | sub prepare_builders
|
---|
452 | {
|
---|
453 | my $self = shift @_;
|
---|
454 | my ($config_filename,$collectcfg) = @_;
|
---|
455 |
|
---|
456 | my $archivedir = $self->{'archivedir'};
|
---|
457 | my $builddir = $self->{'builddir'};
|
---|
458 | my $buildtype = $self->{'buildtype'};
|
---|
459 | my $cachedir = $self->{'cachedir'};
|
---|
460 | my $collectdir = $self->{'collectdir'};
|
---|
461 | my $collection = $self->{'collection'};
|
---|
462 | my $debug = $self->{'debug'};
|
---|
463 | my $faillog = $self->{'faillog'};
|
---|
464 | my $gli = $self->{'gli'};
|
---|
465 | my $incremental = $self->{'incremental'};
|
---|
466 | my $incremental_mode = $self->{'incremental_mode'};
|
---|
467 | my $keepold = $self->{'keepold'};
|
---|
468 | my $maxdocs = $self->{'maxdocs'};
|
---|
469 | my $maxnumeric = $self->{'maxnumeric'};
|
---|
470 | my $no_strip_html = $self->{'no_strip_html'};
|
---|
471 | my $no_text = $self->{'no_text'};
|
---|
472 | my $orthogonalbuildtypes = $self->{'orthogonalbuildtypes'};
|
---|
473 | my $out = $self->{'out'};
|
---|
474 | my $remove_empty_classifications = $self->{'remove_empty_classifications'};
|
---|
475 | my $sections_index_document_metadata = $self->{'sections_index_document_metadata'};
|
---|
476 | my $sections_sort_on_document_metadata = $self->{'sections_sort_on_document_metadata'};
|
---|
477 | my $site = $self->{'site'};
|
---|
478 | my $store_metadata_coverage = $self->{'store_metadata_coverage'};
|
---|
479 | my $verbosity = $self->{'verbosity'};
|
---|
480 |
|
---|
481 | if ($gli)
|
---|
482 | {
|
---|
483 | print STDERR "<Build>\n";
|
---|
484 | }
|
---|
485 |
|
---|
486 | # fill in the default archives and building directories if none
|
---|
487 | # were supplied, turn all \ into / and remove trailing /
|
---|
488 |
|
---|
489 | my ($realarchivedir, $realbuilddir);
|
---|
490 | # update the archive cache if needed
|
---|
491 | if ($cachedir)
|
---|
492 | {
|
---|
493 | if ($verbosity >= 1)
|
---|
494 | {
|
---|
495 | &gsprintf::gsprintf($out, "{buildcol.updating_archive_cache}\n")
|
---|
496 | }
|
---|
497 |
|
---|
498 | $cachedir =~ s/[\\\/]+$//;
|
---|
499 | if ($cachedir !~ /collect[\/\\]$collection/)
|
---|
500 | {
|
---|
501 | $cachedir = &FileUtils::filenameConcatenate($cachedir, 'collect', $collection);
|
---|
502 | }
|
---|
503 |
|
---|
504 | $realarchivedir = &FileUtils::filenameConcatenate($cachedir, 'archives');
|
---|
505 | $realbuilddir = &FileUtils::filenameConcatenate($cachedir, 'building');
|
---|
506 | &FileUtils::makeAllDirectories($realarchivedir);
|
---|
507 | &FileUtils::makeAllDirectories($realbuilddir);
|
---|
508 | &FileUtils::synchronizeDirectory($archivedir, $realarchivedir, $verbosity);
|
---|
509 | }
|
---|
510 | else
|
---|
511 | {
|
---|
512 | $realarchivedir = $archivedir;
|
---|
513 | $realbuilddir = $builddir;
|
---|
514 | }
|
---|
515 | $self->{'realarchivedir'} = $realarchivedir;
|
---|
516 | $self->{'realbuilddir'} = $realbuilddir;
|
---|
517 |
|
---|
518 | # build it in realbuilddir
|
---|
519 | &FileUtils::makeAllDirectories($realbuilddir);
|
---|
520 |
|
---|
521 | my ($buildertype, $builderdir, $builder);
|
---|
522 | # if a builder class has been created for this collection, use it
|
---|
523 | # otherwise, use the mg or mgpp builder
|
---|
524 | if (-e "$ENV{'GSDLCOLLECTDIR'}/custom/${collection}/perllib/custombuilder.pm")
|
---|
525 | {
|
---|
526 | $builderdir = "$ENV{'GSDLCOLLECTDIR'}/custom/${collection}/perllib";
|
---|
527 | $buildertype = "custombuilder";
|
---|
528 | }
|
---|
529 | elsif (-e "$ENV{'GSDLCOLLECTDIR'}/perllib/custombuilder.pm")
|
---|
530 | {
|
---|
531 | $builderdir = "$ENV{'GSDLCOLLECTDIR'}/perllib";
|
---|
532 | $buildertype = "custombuilder";
|
---|
533 | }
|
---|
534 | elsif (-e "$ENV{'GSDLCOLLECTDIR'}/perllib/${collection}builder.pm")
|
---|
535 | {
|
---|
536 | $builderdir = "$ENV{'GSDLCOLLECTDIR'}/perllib";
|
---|
537 | $buildertype = $collection . 'builder';
|
---|
538 | }
|
---|
539 | else
|
---|
540 | {
|
---|
541 | $builderdir = undef;
|
---|
542 | if ($buildtype ne '')
|
---|
543 | {
|
---|
544 | # caters for extension-based build types, such as 'solr'
|
---|
545 | $buildertype = $buildtype . 'builder';
|
---|
546 | }
|
---|
547 | else
|
---|
548 | {
|
---|
549 | # Default to mgpp
|
---|
550 | $buildertype = 'mgppbuilder';
|
---|
551 | }
|
---|
552 | }
|
---|
553 | # check for extension specific builders
|
---|
554 | # (that will then be run after main builder.pm
|
---|
555 | my @builderdir_list = ($builderdir);
|
---|
556 | my @buildertype_list = ($buildertype);
|
---|
557 |
|
---|
558 | if (defined $orthogonalbuildtypes)
|
---|
559 | {
|
---|
560 | foreach my $obt (@$orthogonalbuildtypes)
|
---|
561 | {
|
---|
562 | push(@builderdir_list,undef); # rely on @INC to find it
|
---|
563 | push(@buildertype_list,$obt."Builder");
|
---|
564 | }
|
---|
565 | }
|
---|
566 |
|
---|
567 | # Set up array of the main builder.pm, followed by any ones
|
---|
568 | # from the extension folders
|
---|
569 |
|
---|
570 | my $num_builders = scalar(@buildertype_list);
|
---|
571 | my @builders = ();
|
---|
572 |
|
---|
573 | for (my $i=0; $i<$num_builders; $i++)
|
---|
574 | {
|
---|
575 | my $this_builder;
|
---|
576 | my $this_buildertype = $buildertype_list[$i];
|
---|
577 | my $this_builderdir = $builderdir_list[$i];
|
---|
578 |
|
---|
579 | if ((defined $this_builderdir) && ($this_builderdir ne ""))
|
---|
580 | {
|
---|
581 | require "$this_builderdir/$this_buildertype.pm";
|
---|
582 | }
|
---|
583 | else
|
---|
584 | {
|
---|
585 | require "$this_buildertype.pm";
|
---|
586 | }
|
---|
587 |
|
---|
588 | eval("\$this_builder = new $this_buildertype(\$site, \$collection, " .
|
---|
589 | "\$realarchivedir, \$realbuilddir, \$verbosity, " .
|
---|
590 | "\$maxdocs, \$debug, \$keepold, \$incremental, \$incremental_mode, " .
|
---|
591 | "\$remove_empty_classifications, " .
|
---|
592 | "\$out, \$no_text, \$faillog, \$gli)");
|
---|
593 | die "$@" if $@;
|
---|
594 |
|
---|
595 | push(@builders,$this_builder);
|
---|
596 | }
|
---|
597 |
|
---|
598 | # Init phase for builders
|
---|
599 | for (my $i=0; $i<$num_builders; $i++)
|
---|
600 | {
|
---|
601 | my $this_buildertype = $buildertype_list[$i];
|
---|
602 | my $this_builderdir = $builderdir_list[$i];
|
---|
603 | my $this_builder = $builders[$i];
|
---|
604 |
|
---|
605 | $this_builder->init();
|
---|
606 | $this_builder->set_maxnumeric($maxnumeric);
|
---|
607 |
|
---|
608 | if (($this_buildertype eq "mgppbuilder") && $no_strip_html)
|
---|
609 | {
|
---|
610 | $this_builder->set_strip_html(0);
|
---|
611 | }
|
---|
612 |
|
---|
613 | if ($sections_index_document_metadata ne "never")
|
---|
614 | {
|
---|
615 | $this_builder->set_sections_index_document_metadata($sections_index_document_metadata);
|
---|
616 | }
|
---|
617 | if (($this_buildertype eq "lucenebuilder" || $this_buildertype eq "solrbuilder") && $sections_sort_on_document_metadata ne "never")
|
---|
618 | {
|
---|
619 | $this_builder->set_sections_sort_on_document_metadata($sections_sort_on_document_metadata);
|
---|
620 | }
|
---|
621 |
|
---|
622 | if ($store_metadata_coverage)
|
---|
623 | {
|
---|
624 | $this_builder->set_store_metadata_coverage(1);
|
---|
625 | }
|
---|
626 | }
|
---|
627 | return \@builders;
|
---|
628 | }
|
---|
629 |
|
---|
630 | sub build_collection
|
---|
631 | {
|
---|
632 | my $self = shift(@_);
|
---|
633 | my @builders = @{shift(@_)};
|
---|
634 |
|
---|
635 | my $indexlevel = $self->{'indexlevel'};
|
---|
636 | my $indexname = $self->{'indexname'};
|
---|
637 | my $mode = $self->{'mode'};
|
---|
638 | my $textindex = $self->{'textindex'};
|
---|
639 |
|
---|
640 | # Run the requested passes
|
---|
641 | if ($mode =~ /^all$/i)
|
---|
642 | {
|
---|
643 | # 'map' modifies the elements of the original array, so calling
|
---|
644 | # methods -- as done below -- will cause (by default) @builders
|
---|
645 | # to be changed to whatever these functions return (which is *not*
|
---|
646 | # what we want -- we want to leave the values unchanged)
|
---|
647 | # => Use 'local' (dynamic scoping) to give each 'map' call its
|
---|
648 | # own local copy This could also be done with:
|
---|
649 | # (my $new =$_)->method(); $new
|
---|
650 | # but is a bit more cumbersome to write
|
---|
651 | map { local $_=$_; $_->compress_text($textindex); } @builders;
|
---|
652 | # - we pass the required indexname and indexlevel (if specified) to the
|
---|
653 | # processor [jmt12]
|
---|
654 | map { local $_=$_; $_->build_indexes($indexname, $indexlevel); } @builders;
|
---|
655 | map { local $_=$_; $_->make_infodatabase(); } @builders;
|
---|
656 | map { local $_=$_; $_->collect_specific(); } @builders;
|
---|
657 | }
|
---|
658 | elsif ($mode =~ /^compress_text$/i)
|
---|
659 | {
|
---|
660 | map { local $_=$_; $_->compress_text($textindex); } @builders;
|
---|
661 | }
|
---|
662 | elsif ($mode =~ /^build_index$/i)
|
---|
663 | {
|
---|
664 | map { local $_=$_; $_->build_indexes($indexname, $indexlevel); } @builders;
|
---|
665 | }
|
---|
666 | elsif ($mode =~ /^infodb$/i)
|
---|
667 | {
|
---|
668 | map { local $_=$_; $_->make_infodatabase(); } @builders;
|
---|
669 | }
|
---|
670 | else
|
---|
671 | {
|
---|
672 | (&gsprintf::gsprintf(STDERR, "{buildcol.unknown_mode}\n", $mode) && die);
|
---|
673 | }
|
---|
674 | }
|
---|
675 | # build_collection()
|
---|
676 |
|
---|
677 | # @function build_auxiliary_files
|
---|
678 | #
|
---|
679 | sub build_auxiliary_files
|
---|
680 | {
|
---|
681 | my $self = shift(@_);
|
---|
682 | my @builders = @{shift(@_)};
|
---|
683 | if (!$self->{'debug'})
|
---|
684 | {
|
---|
685 | map {local $_=$_; $_->make_auxiliary_files(); } @builders;
|
---|
686 | }
|
---|
687 | }
|
---|
688 | # build_auxiliary_files()
|
---|
689 |
|
---|
690 | # @function complete_builders
|
---|
691 | #
|
---|
692 | sub complete_builders
|
---|
693 | {
|
---|
694 | my $self = shift(@_);
|
---|
695 | my @builders = @{shift(@_)};
|
---|
696 |
|
---|
697 | map {local $_=$_; $_->deinit(); } @builders;
|
---|
698 |
|
---|
699 | if (($self->{'realbuilddir'} ne $self->{'builddir'}) && !$self->{'debug'})
|
---|
700 | {
|
---|
701 | if ($self->{'verbosity'} >= 1)
|
---|
702 | {
|
---|
703 | &gsprintf::gsprintf($out, "{buildcol.copying_back_cached_build}\n");
|
---|
704 | }
|
---|
705 | &FileUtils::removeFilesRecursive($self->{'builddir'});
|
---|
706 | &FileUtils::copyFilesRecursive($self->{'realbuilddir'}, $self->{'builddir'});
|
---|
707 | }
|
---|
708 |
|
---|
709 | # for RSS support: Need rss-items.rdf file in index folder
|
---|
710 | # check if a file called rss-items.rdf exists in archives, then copy it into the building folder
|
---|
711 | # so that when building is moved to index, this file will then also be in index as desired
|
---|
712 | my $collection_dir = &util::resolve_collection_dir($self->{'collectdir'},
|
---|
713 | $self->{'collection'},
|
---|
714 | $self->{'site'});
|
---|
715 | my $rss_items_rdf_file = &FileUtils::filenameConcatenate($self->{'archivedir'}, 'rss-items.rdf');
|
---|
716 | # @todo FileUtils
|
---|
717 | if(defined $self->{'builddir'} && &FileUtils::directoryExists($self->{'builddir'}) && &FileUtils::fileExists($rss_items_rdf_file))
|
---|
718 | {
|
---|
719 | if ($self->{'verbosity'} >= 1)
|
---|
720 | {
|
---|
721 | my $archivedir_tail = "'".basename($self->{'archivedir'})."'";
|
---|
722 | my $builddir_tail = "'".basename($self->{'builddir'})."'";
|
---|
723 |
|
---|
724 | &gsprintf::gsprintf($self->{'out'}, "{buildcol.copying_rss_items_rdf}\n", $archivedir_tail, $builddir_tail);
|
---|
725 | }
|
---|
726 | &FileUtils::copyFiles($rss_items_rdf_file, $self->{'builddir'});
|
---|
727 | }
|
---|
728 |
|
---|
729 | if ($self->{'gli'})
|
---|
730 | {
|
---|
731 | print STDERR "</Build>\n";
|
---|
732 | }
|
---|
733 | }
|
---|
734 | # complete_builders()
|
---|
735 |
|
---|
736 | # @function activate_collection
|
---|
737 | #
|
---|
738 | sub activate_collection
|
---|
739 | {
|
---|
740 | my $self = shift(@_);
|
---|
741 | # if buildcol.pl was run with -activate, need to run activate.pl
|
---|
742 | # now that building's complete
|
---|
743 | if ($self->{'activate'})
|
---|
744 | {
|
---|
745 | #my $quoted_argv = join(" ", map { "\"$_\"" } @ARGV);
|
---|
746 | my @activate_argv = ();
|
---|
747 | push(@activate_argv, '-collectdir', $self->{'collectdir'}) if ($self->{'collectdir'});
|
---|
748 | push(@activate_argv, '-builddir', $self->{'builddir'}) if ($self->{'builddir'});
|
---|
749 | push(@activate_argv, '-site', $self->{'site'}) if ($self->{'site'});
|
---|
750 | push(@activate_argv, '-verbosity', $self->{'verbosity'}) if ($self->{'verbosity'});
|
---|
751 | push(@activate_argv, '-removeold') if ($self->{'removeold'});
|
---|
752 | push(@activate_argv, '-keepold') if ($self->{'keepold'});
|
---|
753 | push(@activate_argv, '-incremental') if ($self->{'incremental'});
|
---|
754 | my $quoted_argv = join(' ', map { "\"$_\"" } @activate_argv);
|
---|
755 | my $activatecol_cmd = '"' . &util::get_perl_exec(). '" -S activate.pl ' . $quoted_argv . ' "' . $self->get_collection() . '"';
|
---|
756 | my $activatecol_status = system($activatecol_cmd)/256;
|
---|
757 |
|
---|
758 | if ($activatecol_status != 0)
|
---|
759 | {
|
---|
760 | print STDERR "Error: Failed to run: $activatecol_cmd\n";
|
---|
761 | print STDERR " $!\n" if ($! ne '');
|
---|
762 | exit(-1);
|
---|
763 | }
|
---|
764 | }
|
---|
765 | }
|
---|
766 |
|
---|
767 | # @function deinit()
|
---|
768 | #
|
---|
769 | sub deinit
|
---|
770 | {
|
---|
771 | my $self = shift(@_);
|
---|
772 |
|
---|
773 | if ($self->{'close_out'})
|
---|
774 | {
|
---|
775 | close OUT;
|
---|
776 | }
|
---|
777 | if ($self->{'close_faillog'})
|
---|
778 | {
|
---|
779 | close FAILLOG;
|
---|
780 | }
|
---|
781 | }
|
---|
782 | # deinit()
|
---|
783 |
|
---|
784 | 1;
|
---|