source: main/trunk/greenstone2/perllib/buildcolutils.pm@ 29079

Last change on this file since 29079 was 29079, checked in by kjdon, 10 years ago

removed a comment no longer needed

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