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

Last change on this file since 27482 was 27482, checked in by jmt12, 11 years ago

Replace slash replacement regexs with a call the FileUtils::sanitizePath() which does a much better job of preserving file protocols

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