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

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

make builddir absolute if it isn't already (so you can say -builddir building1 for example). Needed to use self->builddir not $builddir as the latter was empty, so I have changed the make absolute for archivesdir in the same way

  • Property svn:executable set to *
File size: 25.5 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 # - why don't we make builddir absolute similar to archivedir?
302 $self->{'builddir'} = &FileUtils::sanitizePath($self->{'builddir'});
303 #$self->{'builddir'} =~ s/[\\\/]+/\//g;
304 #$self->{'builddir'} =~ s/\/$//;
305
306 if (defined $collectcfg->{'cachedir'} && $self->{'cachedir'} eq "")
307 {
308 $self->{'cachedir'} = $collectcfg->{'cachedir'};
309 }
310
311 if ($self->{'maxdocs'} !~ /\-?\d+/)
312 {
313 if (defined $collectcfg->{'maxdocs'} && $collectcfg->{'maxdocs'} =~ /\-?\d+/)
314 {
315 $self->{'maxdocs'} = $collectcfg->{'maxdocs'};
316 }
317 else
318 {
319 $self->{'maxdocs'} = -1; # the default
320 }
321 }
322
323 # always clobbers? [jmt12]
324 if (defined $collectcfg->{'maxnumeric'} && $collectcfg->{'maxnumeric'} =~ /\d+/)
325 {
326 $self->{'maxnumeric'} = $collectcfg->{'maxnumeric'};
327 }
328 if ($self->{'maxnumeric'} < 4 || $self->{'maxnumeric'} > 512)
329 {
330 $self->{'maxnumeric'} = 4;
331 }
332
333 if (defined $collectcfg->{'debug'} && $collectcfg->{'debug'} =~ /^true$/i)
334 {
335 $self->{'debug'} = 1;
336 }
337
338 if ($self->{'mode'} !~ /^(all|compress_text|build_index|infodb|extra)$/)
339 {
340 if (defined $collectcfg->{'mode'} && $collectcfg->{'mode'} =~ /^(all|compress_text|build_index|infodb|extra)$/)
341 {
342 $self->{'mode'} = $collectcfg->{'mode'};
343 }
344 else
345 {
346 $self->{'mode'} = "all"; # the default
347 }
348 }
349
350 # Presumably 'index' from the collect.cfg still works [jmt12]
351 if (defined $collectcfg->{'index'} && $self->{'indexname'} eq "")
352 {
353 $self->{'indexname'} = $collectcfg->{'index'};
354 }
355 # - 'index' from the command line doesn't make it through parsing so I
356 # renamed this option 'indexname' [jmt12]
357 if (defined $collectcfg->{'indexname'} && $self->{'indexname'} eq "")
358 {
359 $self->{'indexname'} = $collectcfg->{'indexname'};
360 }
361 # - we may also define the index level to build now [jmt12]
362 if (defined $collectcfg->{'indexlevel'} && $self->{'indexlevel'} eq "")
363 {
364 $self->{'indexlevel'} = $collectcfg->{'indexlevel'};
365 }
366
367 if (defined $collectcfg->{'no_text'} && $self->{'no_text'} == 0)
368 {
369 if ($collectcfg->{'no_text'} =~ /^true$/i)
370 {
371 $self->{'no_text'} = 1;
372 }
373 }
374
375 if (defined $collectcfg->{'no_strip_html'} && $self->{'no_strip_html'} == 0)
376 {
377 if ($collectcfg->{'no_strip_html'} =~ /^true$/i)
378 {
379 $self->{'no_strip_html'} = 1;
380 }
381 }
382
383 if (defined $collectcfg->{'store_metadata_coverage'} && $self->{'store_metadata_coverage'} == 0)
384 {
385 if ($collectcfg->{'store_metadata_coverage'} =~ /^true$/i)
386 {
387 $self->{'store_metadata_coverage'} = 1;
388 }
389 }
390
391 if (defined $collectcfg->{'remove_empty_classifications'} && $self->{'remove_empty_classifications'} == 0)
392 {
393 if ($collectcfg->{'remove_empty_classifications'} =~ /^true$/i)
394 {
395 $self->{'remove_empty_classifications'} = 1;
396 }
397 }
398
399 if (defined $collectcfg->{'gli'} && $collectcfg->{'gli'} =~ /^true$/i)
400 {
401 $self->{'gli'} = 1;
402 }
403 if (!defined $self->{'gli'})
404 {
405 $self->{'gli'} = 0;
406 }
407
408 if ($self->{'sections_index_document_metadata'} !~ /\S/ && defined $collectcfg->{'sections_index_document_metadata'})
409 {
410 $self->{'sections_index_document_metadata'} = $collectcfg->{'sections_index_document_metadata'};
411 }
412
413 if ($self->{'sections_index_document_metadata'} !~ /^(never|always|unless_section_metadata_exists)$/) {
414 $self->{'sections_index_document_metadata'} = 'never';
415 }
416
417 if ($self->{'sections_sort_on_document_metadata'} !~ /\S/ && defined $collectcfg->{'sections_sort_on_document_metadata'})
418 {
419 $self->{'sections_sort_on_document_metadata'} = $collectcfg->{'sections_sort_on_document_metadata'};
420 }
421
422 if ($self->{'sections_sort_on_document_metadata'} !~ /^(never|always|unless_section_metadata_exists)$/) {
423 $self->{'sections_sort_on_document_metadata'} = 'never';
424 }
425
426 my ($removeold, $keepold, $incremental, $incremental_mode)
427 = &scriptutil::check_removeold_and_keepold($self->{'removeold'}, $self->{'keepold'},
428 $self->{'incremental'}, 'building',
429 $collectcfg);
430 $self->{'removeold'} = $removeold;
431 $self->{'keepold'} = $keepold;
432 $self->{'incremental'} = $incremental;
433 $self->{'incremental_mode'} = $incremental_mode;
434
435 # New argument to track whether build is incremental
436 if (!defined $self->{'incremental'})
437 {
438 $self->{'incremental'} = 0;
439 }
440
441 #set the text index
442 if (($self->{'buildtype'} eq 'mgpp') || ($self->{'buildtype'} eq 'lucene') || ($self->{'buildtype'} eq 'solr'))
443 {
444 if ($self->{'textindex'} eq '')
445 {
446 $self->{'textindex'} = 'text';
447 }
448 }
449 else
450 {
451 $self->{'textindex'} = 'section:text';
452 }
453}
454# set_collection_options()
455
456# @function prepare_builders
457#
458sub prepare_builders
459{
460 my $self = shift @_;
461 my ($config_filename,$collectcfg) = @_;
462
463 my $archivedir = $self->{'archivedir'};
464 my $builddir = $self->{'builddir'};
465 my $buildtype = $self->{'buildtype'};
466 my $cachedir = $self->{'cachedir'};
467 my $collectdir = $self->{'collectdir'};
468 my $collection = $self->{'collection'};
469 my $debug = $self->{'debug'};
470 my $faillog = $self->{'faillog'};
471 my $gli = $self->{'gli'};
472 my $incremental = $self->{'incremental'};
473 my $incremental_mode = $self->{'incremental_mode'};
474 my $keepold = $self->{'keepold'};
475 my $maxdocs = $self->{'maxdocs'};
476 my $maxnumeric = $self->{'maxnumeric'};
477 my $no_strip_html = $self->{'no_strip_html'};
478 my $no_text = $self->{'no_text'};
479 my $orthogonalbuildtypes = $self->{'orthogonalbuildtypes'};
480 my $out = $self->{'out'};
481 my $remove_empty_classifications = $self->{'remove_empty_classifications'};
482 my $sections_index_document_metadata = $self->{'sections_index_document_metadata'};
483 my $sections_sort_on_document_metadata = $self->{'sections_sort_on_document_metadata'};
484 my $site = $self->{'site'};
485 my $store_metadata_coverage = $self->{'store_metadata_coverage'};
486 my $verbosity = $self->{'verbosity'};
487
488 if ($gli)
489 {
490 print STDERR "<Build>\n";
491 }
492
493 # fill in the default archives and building directories if none
494 # were supplied, turn all \ into / and remove trailing /
495
496 my ($realarchivedir, $realbuilddir);
497 # update the archive cache if needed
498 if ($cachedir)
499 {
500 if ($verbosity >= 1)
501 {
502 &gsprintf::gsprintf($out, "{buildcol.updating_archive_cache}\n")
503 }
504
505 $cachedir =~ s/[\\\/]+$//;
506 if ($cachedir !~ /collect[\/\\]$collection/)
507 {
508 $cachedir = &FileUtils::filenameConcatenate($cachedir, 'collect', $collection);
509 }
510
511 $realarchivedir = &FileUtils::filenameConcatenate($cachedir, 'archives');
512 $realbuilddir = &FileUtils::filenameConcatenate($cachedir, 'building');
513 &FileUtils::makeAllDirectories($realarchivedir);
514 &FileUtils::makeAllDirectories($realbuilddir);
515 &FileUtils::synchronizeDirectory($archivedir, $realarchivedir, $verbosity);
516 }
517 else
518 {
519 $realarchivedir = $archivedir;
520 $realbuilddir = $builddir;
521 }
522 $self->{'realarchivedir'} = $realarchivedir;
523 $self->{'realbuilddir'} = $realbuilddir;
524
525 # build it in realbuilddir
526 &FileUtils::makeAllDirectories($realbuilddir);
527
528 my ($buildertype, $builderdir, $builder);
529 # if a builder class has been created for this collection, use it
530 # otherwise, use the mg or mgpp builder
531 if (-e "$ENV{'GSDLCOLLECTDIR'}/custom/${collection}/perllib/custombuilder.pm")
532 {
533 $builderdir = "$ENV{'GSDLCOLLECTDIR'}/custom/${collection}/perllib";
534 $buildertype = "custombuilder";
535 }
536 elsif (-e "$ENV{'GSDLCOLLECTDIR'}/perllib/custombuilder.pm")
537 {
538 $builderdir = "$ENV{'GSDLCOLLECTDIR'}/perllib";
539 $buildertype = "custombuilder";
540 }
541 elsif (-e "$ENV{'GSDLCOLLECTDIR'}/perllib/${collection}builder.pm")
542 {
543 $builderdir = "$ENV{'GSDLCOLLECTDIR'}/perllib";
544 $buildertype = $collection . 'builder';
545 }
546 else
547 {
548 $builderdir = undef;
549 if ($buildtype ne '')
550 {
551 # caters for extension-based build types, such as 'solr'
552 $buildertype = $buildtype . 'builder';
553 }
554 else
555 {
556 # Default to mgpp
557 $buildertype = 'mgppbuilder';
558 }
559 }
560 # check for extension specific builders
561 # (that will then be run after main builder.pm
562 my @builderdir_list = ($builderdir);
563 my @buildertype_list = ($buildertype);
564
565 my $mode = $self->{'mode'};
566
567 if ($mode eq "extra") {
568 # knock out the main builder type, by reseting the lists to be empty
569 @builderdir_list = ();
570 @buildertype_list = ();
571 }
572
573 if (defined $orthogonalbuildtypes)
574 {
575 foreach my $obt (@$orthogonalbuildtypes)
576 {
577 push(@builderdir_list,undef); # rely on @INC to find it
578 push(@buildertype_list,$obt."Builder");
579 }
580 }
581
582 # Set up array of the main builder.pm, followed by any ones
583 # from the extension folders
584
585 my $num_builders = scalar(@buildertype_list);
586 my @builders = ();
587
588 for (my $i=0; $i<$num_builders; $i++)
589 {
590 my $this_builder;
591 my $this_buildertype = $buildertype_list[$i];
592 my $this_builderdir = $builderdir_list[$i];
593
594 if ((defined $this_builderdir) && ($this_builderdir ne ""))
595 {
596 require "$this_builderdir/$this_buildertype.pm";
597 }
598 else
599 {
600 require "$this_buildertype.pm";
601 }
602
603 eval("\$this_builder = new $this_buildertype(\$site, \$collection, " .
604 "\$realarchivedir, \$realbuilddir, \$verbosity, " .
605 "\$maxdocs, \$debug, \$keepold, \$incremental, \$incremental_mode, " .
606 "\$remove_empty_classifications, " .
607 "\$out, \$no_text, \$faillog, \$gli)");
608 die "$@" if $@;
609
610 push(@builders,$this_builder);
611 }
612
613 # Init phase for builders
614 for (my $i=0; $i<$num_builders; $i++)
615 {
616 my $this_buildertype = $buildertype_list[$i];
617 my $this_builderdir = $builderdir_list[$i];
618 my $this_builder = $builders[$i];
619
620 $this_builder->init();
621 $this_builder->set_maxnumeric($maxnumeric);
622
623 if (($this_buildertype eq "mgppbuilder") && $no_strip_html)
624 {
625 $this_builder->set_strip_html(0);
626 }
627
628 if ($sections_index_document_metadata ne "never")
629 {
630 $this_builder->set_sections_index_document_metadata($sections_index_document_metadata);
631 }
632 if (($this_buildertype eq "lucenebuilder" || $this_buildertype eq "solrbuilder") && $sections_sort_on_document_metadata ne "never")
633 {
634 $this_builder->set_sections_sort_on_document_metadata($sections_sort_on_document_metadata);
635 }
636
637 if ($store_metadata_coverage)
638 {
639 $this_builder->set_store_metadata_coverage(1);
640 }
641 }
642 return \@builders;
643}
644
645sub build_collection
646{
647 my $self = shift(@_);
648 my @builders = @{shift(@_)};
649
650 my $indexlevel = $self->{'indexlevel'};
651 my $indexname = $self->{'indexname'};
652 my $mode = $self->{'mode'};
653 my $textindex = $self->{'textindex'};
654
655 # Run the requested passes
656 if ($mode =~ /^(all|extra)$/i)
657 {
658 # 'map' modifies the elements of the original array, so calling
659 # methods -- as done below -- will cause (by default) @builders
660 # to be changed to whatever these functions return (which is *not*
661 # what we want -- we want to leave the values unchanged)
662 # => Use 'local' (dynamic scoping) to give each 'map' call its
663 # own local copy This could also be done with:
664 # (my $new =$_)->method(); $new
665 # but is a bit more cumbersome to write
666 map { local $_=$_; $_->compress_text($textindex); } @builders;
667 # - we pass the required indexname and indexlevel (if specified) to the
668 # processor [jmt12]
669 map { local $_=$_; $_->build_indexes($indexname, $indexlevel); } @builders;
670 map { local $_=$_; $_->make_infodatabase(); } @builders;
671 map { local $_=$_; $_->collect_specific(); } @builders;
672 }
673 elsif ($mode =~ /^compress_text$/i)
674 {
675 map { local $_=$_; $_->compress_text($textindex); } @builders;
676 }
677 elsif ($mode =~ /^build_index$/i)
678 {
679 map { local $_=$_; $_->build_indexes($indexname, $indexlevel); } @builders;
680 }
681 elsif ($mode =~ /^infodb$/i)
682 {
683 map { local $_=$_; $_->make_infodatabase(); } @builders;
684 }
685 else
686 {
687 (&gsprintf::gsprintf(STDERR, "{buildcol.unknown_mode}\n", $mode) && die);
688 }
689}
690# build_collection()
691
692# @function build_auxiliary_files
693#
694sub build_auxiliary_files
695{
696 my $self = shift(@_);
697 my @builders = @{shift(@_)};
698 if (!$self->{'debug'})
699 {
700 map {local $_=$_; $_->make_auxiliary_files(); } @builders;
701 }
702}
703# build_auxiliary_files()
704
705# @function complete_builders
706#
707sub complete_builders
708{
709 my $self = shift(@_);
710 my @builders = @{shift(@_)};
711
712 map {local $_=$_; $_->deinit(); } @builders;
713
714 if (($self->{'realbuilddir'} ne $self->{'builddir'}) && !$self->{'debug'})
715 {
716 if ($self->{'verbosity'} >= 1)
717 {
718 &gsprintf::gsprintf($out, "{buildcol.copying_back_cached_build}\n");
719 }
720 &FileUtils::removeFilesRecursive($self->{'builddir'});
721 &FileUtils::copyFilesRecursive($self->{'realbuilddir'}, $self->{'builddir'});
722 }
723
724 # for RSS support: Need rss-items.rdf file in index folder
725 # check if a file called rss-items.rdf exists in archives, then copy it into the building folder
726 # so that when building is moved to index, this file will then also be in index as desired
727 my $collection_dir = &util::resolve_collection_dir($self->{'collectdir'},
728 $self->{'collection'},
729 $self->{'site'});
730 my $rss_items_rdf_file = &FileUtils::filenameConcatenate($self->{'archivedir'}, 'rss-items.rdf');
731 # @todo FileUtils
732 if(defined $self->{'builddir'} && &FileUtils::directoryExists($self->{'builddir'}) && &FileUtils::fileExists($rss_items_rdf_file))
733 {
734 if ($self->{'verbosity'} >= 1)
735 {
736 my $archivedir_tail = "'".basename($self->{'archivedir'})."'";
737 my $builddir_tail = "'".basename($self->{'builddir'})."'";
738
739 &gsprintf::gsprintf($self->{'out'}, "{buildcol.copying_rss_items_rdf}\n", $archivedir_tail, $builddir_tail);
740 }
741 &FileUtils::copyFiles($rss_items_rdf_file, $self->{'builddir'});
742 }
743
744 if ($self->{'gli'})
745 {
746 print STDERR "</Build>\n";
747 }
748}
749# complete_builders()
750
751# @function activate_collection
752#
753sub activate_collection
754{
755 my $self = shift(@_);
756 # if buildcol.pl was run with -activate, need to run activate.pl
757 # now that building's complete
758 if ($self->{'activate'})
759 {
760 #my $quoted_argv = join(" ", map { "\"$_\"" } @ARGV);
761 my @activate_argv = ();
762 push(@activate_argv, '-collectdir', $self->{'collectdir'}) if ($self->{'collectdir'});
763 push(@activate_argv, '-builddir', $self->{'builddir'}) if ($self->{'builddir'});
764 push(@activate_argv, '-site', $self->{'site'}) if ($self->{'site'});
765 push(@activate_argv, '-verbosity', $self->{'verbosity'}) if ($self->{'verbosity'});
766 push(@activate_argv, '-removeold') if ($self->{'removeold'});
767 push(@activate_argv, '-keepold') if ($self->{'keepold'});
768 push(@activate_argv, '-incremental') if ($self->{'incremental'});
769 my $quoted_argv = join(' ', map { "\"$_\"" } @activate_argv);
770 my $activatecol_cmd = '"' . &util::get_perl_exec(). '" -S activate.pl ' . $quoted_argv . ' "' . $self->get_collection() . '"';
771 my $activatecol_status = system($activatecol_cmd)/256;
772
773 if ($activatecol_status != 0)
774 {
775 print STDERR "Error: Failed to run: $activatecol_cmd\n";
776 print STDERR " $!\n" if ($! ne '');
777 exit(-1);
778 }
779 }
780}
781
782# @function deinit()
783#
784sub deinit
785{
786 my $self = shift(@_);
787
788 if ($self->{'close_out'})
789 {
790 close OUT;
791 }
792 if ($self->{'close_faillog'})
793 {
794 close FAILLOG;
795 }
796}
797# deinit()
798
7991;
Note: See TracBrowser for help on using the repository browser.