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

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

Moved the heavy lifting from the buildcol.pl script into a proper perl class, buildcolutils.pm, thus allowing parts of the build process to be overridden by versions loaded by extensions. Replace deprecated util.pm calls with FileUtils.pm ones

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