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

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

Correcting bug that left archivedir undefined in some circumstances - code to do this was lurking down in the part that handled building files from cache, so I've moved this into the part that sets up the arguments/options instead. RSS feed files should now be copied correctly. Sorry Anu.

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