source: gsdl/trunk/bin/script/buildcol.pl@ 16788

Last change on this file since 16788 was 16788, checked in by davidb, 16 years ago

Now checks for extended plugins and classifiers as well as in standard place

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 24.6 KB
Line 
1#!/usr/bin/perl -w
2
3## @file buildcol.pl
4# This program will build a particular collection.
5# A component of the Greenstone digital library software
6# from the New Zealand Digital Library Project at the
7# University of Waikato, New Zealand.
8#
9# This program is free software; you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation; either version 2 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program; if not, write to the Free Software
21# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22#
23# @note 11/04/03 Added usage datastructure - John Thompson
24#
25# @author New Zealand Digital Library Project unless otherwise stated
26# @copy 1999 New Zealand Digital Library Project
27#
28package buildcol;
29
30BEGIN {
31 die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
32 die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};
33 unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
34 unshift (@INC, "$ENV{'GSDLHOME'}/perllib/cpan");
35 unshift (@INC, "$ENV{'GSDLHOME'}/perllib/cpan/XML/XPath");
36 unshift (@INC, "$ENV{'GSDLHOME'}/perllib/plugins");
37 unshift (@INC, "$ENV{'GSDLHOME'}/perllib/classify");
38
39 if (defined $ENV{'GSDLEXTS'}) {
40 my @extensions = split(/:/,$ENV{'GSDLEXTS'});
41 foreach my $e (@extensions) {
42 my $ext_prefix = "$ENV{'GSDLHOME'}/ext/$e";
43
44 unshift (@INC, "$ext_prefix/perllib");
45 unshift (@INC, "$ext_prefix/perllib/cpan");
46 unshift (@INC, "$ext_prefix/perllib/plugins");
47 unshift (@INC, "$ext_prefix/perllib/plugouts");
48 unshift (@INC, "$ext_prefix/perllib/classify");
49 }
50 }
51}
52
53use colcfg;
54use util;
55use scriptutil;
56use FileHandle;
57use gsprintf;
58use printusage;
59use parse2;
60
61use strict;
62no strict 'refs'; # allow filehandles to be variables and vice versa
63no strict 'subs'; # allow barewords (eg STDERR) as function arguments
64
65# used in updating Collectionconfig.xml in create_images()
66use Twig;
67
68my $mode_list =
69 [ { 'name' => "all",
70 'desc' => "{buildcol.mode.all}" },
71 { 'name' => "compress_text",
72 'desc' => "{buildcol.mode.compress_text}" },
73 { 'name' => "build_index",
74 'desc' => "{buildcol.mode.build_index}" },
75 { 'name' => "infodb",
76 'desc' => "{buildcol.mode.infodb}" } ];
77
78my $sec_index_list =
79 [ {'name' => "never",
80 'desc' => "{buildcol.sections_index_document_metadata.never}" },
81 {'name' => "always",
82 'desc' => "{buildcol.sections_index_document_metadata.always}" },
83 {'name' => "unless_section_metadata_exists",
84 'desc' => "{buildcol.sections_index_document_metadata.unless_section_metadata_exists}" }
85 ];
86
87my $arguments =
88 [ { 'name' => "remove_empty_classifications",
89 'desc' => "{buildcol.remove_empty_classifications}",
90 'type' => "flag",
91 'reqd' => "no",
92 'modegli' => "2" },
93 { 'name' => "archivedir",
94 'desc' => "{buildcol.archivedir}",
95 'type' => "string",
96 'reqd' => "no",
97 'hiddengli' => "yes" },
98 { 'name' => "builddir",
99 'desc' => "{buildcol.builddir}",
100 'type' => "string",
101 'reqd' => "no",
102 'hiddengli' => "yes" },
103# { 'name' => "cachedir",
104# 'desc' => "{buildcol.cachedir}",
105# 'type' => "string",
106# 'reqd' => "no" },
107 { 'name' => "collectdir",
108 'desc' => "{buildcol.collectdir}",
109 'type' => "string",
110 # parsearg left "" as default
111 #'deft' => &util::filename_cat ($ENV{'GSDLHOME'}, "collect"),
112 'reqd' => "no",
113 'hiddengli' => "yes" },
114 { 'name' => "site",
115 'desc' => "{buildcol.site}",
116 'type' => "string",
117 'deft' => "",
118 'reqd' => "no",
119 'hiddengli' => "yes" },
120 { 'name' => "create_images",
121 'desc' => "{buildcol.create_images}",
122 'type' => "flag",
123 'reqd' => "no",
124 'modegli' => "4" },
125 { 'name' => "debug",
126 'desc' => "{buildcol.debug}",
127 'type' => "flag",
128 'reqd' => "no",
129 'hiddengli' => "yes" },
130 { 'name' => "faillog",
131 'desc' => "{buildcol.faillog}",
132 'type' => "string",
133 # parsearg left "" as default
134 #'deft' => &util::filename_cat("<collectdir>", "colname", "etc", "fail.log"),
135 'reqd' => "no",
136 'modegli' => "4" },
137 { 'name' => "index",
138 'desc' => "{buildcol.index}",
139 'type' => "string",
140 'reqd' => "no",
141 'modegli' => "4" },
142 { 'name' => "incremental",
143 'desc' => "{buildcol.incremental}",
144 'type' => "flag",
145 'hiddengli' => "yes" },
146 { 'name' => "keepold",
147 'desc' => "{buildcol.keepold}",
148 'type' => "flag",
149 'reqd' => "no",
150 #'modegli' => "3",
151 'hiddengli' => "yes" },
152 { 'name' => "removeold",
153 'desc' => "{buildcol.removeold}",
154 'type' => "flag",
155 'reqd' => "no",
156 #'modegli' => "3",
157 'hiddengli' => "yes" },
158 { 'name' => "language",
159 'desc' => "{scripts.language}",
160 'type' => "string",
161 'reqd' => "no",
162 'modegli' => "4" },
163 { 'name' => "maxdocs",
164 'desc' => "{buildcol.maxdocs}",
165 'type' => "int",
166 'reqd' => "no",
167 'hiddengli' => "yes" },
168 { 'name' => "maxnumeric",
169 'desc' => "{buildcol.maxnumeric}",
170 'type' => "int",
171 'reqd' => "no",
172 'deft' => "4",
173 'range' => "4,512",
174 'modegli' => "3" },
175 { 'name' => "mode",
176 'desc' => "{buildcol.mode}",
177 'type' => "enum",
178 'list' => $mode_list,
179 # parsearg left "" as default
180# 'deft' => "all",
181 'reqd' => "no",
182 'modegli' => "4" },
183 { 'name' => "no_strip_html",
184 'desc' => "{buildcol.no_strip_html}",
185 'type' => "flag",
186 'reqd' => "no",
187 'modegli' => "4" },
188 { 'name' => "no_text",
189 'desc' => "{buildcol.no_text}",
190 'type' => "flag",
191 'reqd' => "no",
192 'modegli' => "3" },
193 { 'name' => "sections_index_document_metadata",
194 'desc' => "{buildcol.sections_index_document_metadata}",
195 'type' => "enum",
196 'list' => $sec_index_list,
197 'reqd' => "no",
198 'modegli' => "3" },
199 { 'name' => "out",
200 'desc' => "{buildcol.out}",
201 'type' => "string",
202 'deft' => "STDERR",
203 'reqd' => "no",
204 'hiddengli' => "yes" },
205 { 'name' => "verbosity",
206 'desc' => "{buildcol.verbosity}",
207 'type' => "int",
208 # parsearg left "" as default
209 #'deft' => "2",
210 'reqd' => "no",
211 'modegli' => "4" },
212 { 'name' => "gli",
213 'desc' => "",
214 'type' => "flag",
215 'reqd' => "no",
216 'hiddengli' => "yes" },
217 { 'name' => "xml",
218 'desc' => "{scripts.xml}",
219 'type' => "flag",
220 'reqd' => "no",
221 'hiddengli' => "yes" },
222 { 'name' => "disable_OAI",
223 'desc' => "{buildcol.disable_OAI}",
224 'type' => "flag",
225 'reqd' => "no",
226 'modegli' => "2",
227 'hiddengli' => "yes" },
228 ];
229
230my $options = { 'name' => "buildcol.pl",
231 'desc' => "{buildcol.desc}",
232 'args' => $arguments };
233
234
235# globals
236my $collection;
237my $configfilename;
238my $out;
239
240# used to signify "gs2"(default) or "gs3"
241my $gs_mode = "gs2";
242
243## @method gsprintf()
244# Print a string to the screen after looking it up from a locale dependant
245# strings file. This function is losely based on the idea of resource
246# bundles as used in Java.
247#
248# @param $error The STDERR stream.
249# @param $text The string containing GS keys that should be replaced with
250# their locale dependant equivilents.
251# @param $out The output stream.
252# @return The locale-based string to output.
253#
254sub gsprintf()
255{
256 return &gsprintf::gsprintf(@_);
257}
258## gsprintf() ##
259
260&main();
261
262## @method main()
263#
264# [Parses up and validates the arguments to the build process before creating
265# the appropriate build process to do the actual work - John]
266#
267# @note Added true incremental support - John Thompson, DL Consulting Ltd.
268# @note There were several bugs regarding using directories other than
269# "import" or "archives" during import and build quashed. - John
270# Thompson, DL Consulting Ltd.
271#
272# @param $incremental If true indicates this build should not regenerate all
273# the index and metadata files, and should instead just
274# append the information found in the archives directory
275# to the existing files. If this requires some complex
276# work so as to correctly insert into a classifier so be
277# it. Of course none of this is done here - instead the
278# incremental argument is passed to the document
279# processor.
280#
281sub main
282{
283 # command line args
284 my ($verbosity, $archivedir, $cachedir, $builddir, $site, $maxdocs,
285 $debug, $mode, $indexname, $removeold, $keepold, $incremental,
286 $remove_empty_classifications,
287 $create_images, $collectdir, $build, $type, $textindex,
288 $no_strip_html, $no_text, $faillog, $gli, $index, $language,
289 $sections_index_document_metadata, $maxnumeric,
290 $disable_OAI);
291
292 my $xml = 0;
293 my $hashParsingResult = {};
294 # general options available to all plugins
295 my $intArgLeftinAfterParsing = parse2::parse(\@ARGV,$arguments,$hashParsingResult,"allow_extra_options");
296
297 # If parse returns -1 then something has gone wrong
298 if ($intArgLeftinAfterParsing == -1)
299 {
300 &PrintUsage::print_txt_usage($options, "{buildcol.params}");
301 die "\n";
302 }
303
304 foreach my $strVariable (keys %$hashParsingResult)
305 {
306 eval "\$$strVariable = \$hashParsingResult->{\"\$strVariable\"}";
307 }
308
309 # If $language has been specified, load the appropriate resource bundle
310 # (Otherwise, the default resource bundle will be loaded automatically)
311 if ($language && $language =~ /\S/) {
312 &gsprintf::load_language_specific_resource_bundle($language);
313 }
314
315 if ($xml) {
316 &PrintUsage::print_xml_usage($options);
317 print "\n";
318 return;
319 }
320
321 if ($gli) { # the gli wants strings to be in UTF-8
322 &gsprintf::output_strings_in_UTF8;
323 }
324
325 # now check that we had exactly one leftover arg, which should be
326 # the collection name. We don't want to do this earlier, cos
327 # -xml arg doesn't need a collection name
328 # Or if the user specified -h, then we output the usage also
329 if ($intArgLeftinAfterParsing != 1 || (@ARGV && $ARGV[0] =~ /^\-+h/))
330 {
331 &PrintUsage::print_txt_usage($options, "{buildcol.params}");
332 die "\n";
333 }
334
335 $textindex = "";
336 my $close_out = 0;
337 if ($out !~ /^(STDERR|STDOUT)$/i) {
338 open (OUT, ">$out") ||
339 (&gsprintf(STDERR, "{common.cannot_open_output_file}\n", $out) && die);
340 $out = "buildcol::OUT";
341 $close_out = 1;
342 }
343 $out->autoflush(1);
344
345 # get and check the collection
346 if (($collection = &colcfg::use_collection($site, @ARGV, $collectdir)) eq "") {
347 &PrintUsage::print_txt_usage($options, "{buildcol.params}");
348 die "\n";
349 }
350
351 if ($faillog eq "") {
352 $faillog = &util::filename_cat($ENV{'GSDLCOLLECTDIR'}, "etc", "fail.log");
353 }
354 # note that we're appending to the faillog here (import.pl clears it each time)
355 # this could potentially create a situation where the faillog keeps being added
356 # to over multiple builds (if the import process is being skipped)
357 open (FAILLOG, ">>$faillog") ||
358 (&gsprintf(STDERR, "{common.cannot_open_fail_log}\n", $faillog) && die);
359 $faillog = 'buildcol::FAILLOG';
360 $faillog->autoflush(1);
361
362 unshift (@INC, "$ENV{'GSDLCOLLECTDIR'}/perllib");
363 # Don't know why this didn't already happen, but now collection specific
364 # classify and plugins directory also added to include path
365 unshift (@INC, "$ENV{'GSDLCOLLECTDIR'}/perllib/classify");
366 unshift (@INC, "$ENV{'GSDLCOLLECTDIR'}/perllib/plugins");
367
368 # Read in the collection configuration file.
369 my ($collectcfg, $buildtype);
370 ($configfilename, $gs_mode) = &colcfg::get_collect_cfg_name($out);
371 if ($gs_mode eq "gs2") {
372 $collectcfg = &colcfg::read_collect_cfg ($configfilename);
373 } elsif ($gs_mode eq "gs3") {
374 $collectcfg = &colcfg::read_collection_cfg_xml ($configfilename);
375 }
376
377 if ($verbosity !~ /\d+/) {
378 if (defined $collectcfg->{'verbosity'} && $collectcfg->{'verbosity'} =~ /\d+/) {
379 $verbosity = $collectcfg->{'verbosity'};
380 } else {
381 $verbosity = 2; # the default
382 }
383 }
384 # we use searchtype for determining buildtype, but for old versions, use buildtype
385 if (defined $collectcfg->{'buildtype'}) {
386 $buildtype = $collectcfg->{'buildtype'};
387 } elsif (defined $collectcfg->{'searchtypes'} || defined $collectcfg->{'searchtype'}) {
388 $buildtype = "mgpp";
389 } else {
390 $buildtype = "mg"; #mg is the default
391 }
392 if (defined $collectcfg->{'archivedir'} && $archivedir eq "") {
393 $archivedir = $collectcfg->{'archivedir'};
394 }
395 if (defined $collectcfg->{'cachedir'} && $cachedir eq "") {
396 $cachedir = $collectcfg->{'cachedir'};
397 }
398 if (defined $collectcfg->{'builddir'} && $builddir eq "") {
399 $builddir = $collectcfg->{'builddir'};
400 }
401 if ($maxdocs !~ /\-?\d+/) {
402 if (defined $collectcfg->{'maxdocs'} && $collectcfg->{'maxdocs'} =~ /\-?\d+/) {
403 $maxdocs = $collectcfg->{'maxdocs'};
404 } else {
405 $maxdocs = -1; # the default
406 }
407 }
408 if (defined $collectcfg->{'maxnumeric'} && $collectcfg->{'maxnumeric'} =~ /\d+/) {
409 $maxnumeric = $collectcfg->{'maxnumeric'};
410 }
411
412 if ($maxnumeric < 4 || $maxnumeric > 512) {
413 $maxnumeric = 4;
414 }
415
416 if (defined $collectcfg->{'debug'} && $collectcfg->{'debug'} =~ /^true$/i) {
417 $debug = 1;
418 }
419 if ($mode !~ /^(all|compress_text|build_index|infodb)$/) {
420 if (defined $collectcfg->{'mode'} && $collectcfg->{'mode'} =~ /^(all|compress_text|build_index|infodb)$/) {
421 $mode = $collectcfg->{'mode'};
422 } else {
423 $mode = "all"; # the default
424 }
425 }
426 if (defined $collectcfg->{'index'} && $indexname eq "") {
427 $indexname = $collectcfg->{'index'};
428 }
429 if (defined $collectcfg->{'no_text'} && $no_text == 0) {
430 if ($collectcfg->{'no_text'} =~ /^true$/i) {
431 $no_text = 1;
432 }
433 }
434 if (defined $collectcfg->{'no_strip_html'} && $no_strip_html == 0) {
435 if ($collectcfg->{'no_strip_html'} =~ /^true$/i) {
436 $no_strip_html = 1;
437 }
438 }
439 if (defined $collectcfg->{'remove_empty_classifications'} && $remove_empty_classifications == 0) {
440 if ($collectcfg->{'remove_empty_classifications'} =~ /^true$/i) {
441 $remove_empty_classifications = 1;
442 }
443 }
444
445
446 if (defined $collectcfg->{'create_images'} && $collectcfg->{'create_images'} =~ /^true$/i) {
447 $create_images = 1;
448 }
449 if ($buildtype eq "mgpp" && defined $collectcfg->{'textcompress'}) {
450 $textindex = $collectcfg->{'textcompress'};
451 }
452 if (defined $collectcfg->{'gli'} && $collectcfg->{'gli'} =~ /^true$/i) {
453 $gli = 1;
454 }
455
456 if ($sections_index_document_metadata !~ /\S/ && defined $collectcfg->{'sections_index_document_metadata'}) {
457 $sections_index_document_metadata = $collectcfg->{'sections_index_document_metadata'};
458 }
459
460 if ($sections_index_document_metadata !~ /^(never|always|unless_section_metadata_exists)$/) {
461 $sections_index_document_metadata = "never";
462 }
463
464 ($removeold, $keepold, $incremental) = &scriptutil::check_removeold_and_keepold($removeold, $keepold, $incremental, "building", $collectcfg);
465
466 $gli = 0 unless defined $gli;
467
468 # If the disable_OAI flag is not present, the option $disable_OAI with the value of 0 will be passed to basebuilder.pm
469 $disable_OAI = 0 unless defined $disable_OAI;
470
471 # New argument to track whether build is incremental
472 $incremental = 0 unless defined $incremental;
473
474 print STDERR "<Build>\n" if $gli;
475
476 #set the text index
477 if (($buildtype eq "mgpp") || ($buildtype eq "lucene")) {
478 if ($textindex eq "") {
479 $textindex = "text";
480 }
481 }
482 else {
483 $textindex = "section:text";
484 }
485
486 # create default images if required
487 if ($create_images) {
488 my $collection_name = $collection;
489 $collection_name = $collectcfg->{'collectionmeta'}->{'collectionname'}->{'default'}
490 if defined $collectcfg->{'collectionmeta'}->{'collectionname'}->{'default'};
491 &create_images ($collection_name);
492 }
493
494 # fill in the default archives and building directories if none
495 # were supplied, turn all \ into / and remove trailing /
496
497 my ($realarchivedir, $realbuilddir);
498 # Modified so that the archivedir, if provided as an argument, is made
499 # absolute if it isn't already
500 if ($archivedir eq "")
501 {
502 $archivedir = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "archives");
503 }
504 else
505 {
506 $archivedir = &make_absolute($ENV{'GSDLCOLLECTDIR'}, $archivedir);
507 }
508 # End Mod
509 $archivedir =~ s/[\\\/]+/\//g;
510 $archivedir =~ s/\/$//;
511 $builddir = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "building") if $builddir eq "";
512 $builddir =~ s/[\\\/]+/\//g;
513 $builddir =~ s/\/$//;
514
515 # update the archive cache if needed
516 if ($cachedir) {
517 &gsprintf($out, "{buildcol.updating_archive_cache}\n")
518 if ($verbosity >= 1);
519
520 $cachedir =~ s/[\\\/]+$//;
521 $cachedir .= "/collect/$collection" unless
522 $cachedir =~ /collect\/$collection/;
523
524 $realarchivedir = "$cachedir/archives";
525 $realbuilddir = "$cachedir/building";
526 &util::mk_all_dir ($realarchivedir);
527 &util::mk_all_dir ($realbuilddir);
528 &util::cachedir ($archivedir, $realarchivedir, $verbosity);
529
530 } else {
531 $realarchivedir = $archivedir;
532 $realbuilddir = $builddir;
533 }
534
535 # build it in realbuilddir
536 &util::mk_all_dir ($realbuilddir);
537
538 my ($buildertype, $builderdir, $builder);
539 # if a builder class has been created for this collection, use it
540 # otherwise, use the mg or mgpp builder
541 if (-e "$ENV{'GSDLCOLLECTDIR'}/custom/${collection}/perllib/custombuilder.pm") {
542 $builderdir = "$ENV{'GSDLCOLLECTDIR'}/custom/${collection}/perllib";
543 $buildertype = "custombuilder";
544 } elsif (-e "$ENV{'GSDLCOLLECTDIR'}/perllib/custombuilder.pm") {
545 $builderdir = "$ENV{'GSDLCOLLECTDIR'}/perllib";
546 $buildertype = "custombuilder";
547 } elsif (-e "$ENV{'GSDLCOLLECTDIR'}/perllib/${collection}builder.pm") {
548 $builderdir = "$ENV{'GSDLCOLLECTDIR'}/perllib";
549 $buildertype = "${collection}builder";
550 } else {
551 $builderdir = "$ENV{'GSDLHOME'}/perllib";
552 if ($buildtype eq "lucene") {
553 $buildertype = "lucenebuilder";
554 }
555 elsif ($buildtype eq "mgpp") {
556 $buildertype = "mgppbuilder";
557 }
558 else {
559 $buildertype = "mgbuilder";
560 }
561 }
562
563 require "$builderdir/$buildertype.pm";
564
565 eval("\$builder = new $buildertype(\$collection, " .
566 "\$realarchivedir, \$realbuilddir, \$verbosity, " .
567 "\$maxdocs, \$debug, \$keepold, \$incremental, " .
568 "\$remove_empty_classifications, " .
569 "\$out, \$no_text, \$faillog, \$gli, \$disable_OAI)");
570 die "$@" if $@;
571
572 $builder->init();
573 $builder->set_maxnumeric($maxnumeric);
574
575 if (($buildertype eq "mgppbuilder") && $no_strip_html) {
576 $builder->set_strip_html(0);
577 }
578 if ($sections_index_document_metadata ne "never") {
579 $builder->set_sections_index_document_metadata($sections_index_document_metadata);
580 }
581
582 if ($mode =~ /^all$/i) {
583 $builder->compress_text($textindex);
584 $builder->build_indexes($indexname);
585 $builder->make_infodatabase();
586 $builder->collect_specific();
587 } elsif ($mode =~ /^compress_text$/i) {
588 $builder->compress_text($textindex);
589 } elsif ($mode =~ /^build_index$/i) {
590 $builder->build_indexes($indexname);
591 } elsif ($mode =~ /^infodb$/i) {
592 $builder->make_infodatabase();
593 } else {
594 (&gsprintf(STDERR, "{buildcol.unknown_mode}\n", $mode) && die);
595 }
596
597 $builder->make_auxiliary_files() if !$debug;
598 $builder->deinit();
599
600 if (($realbuilddir ne $builddir) && !$debug) {
601 &gsprintf($out, "{buildcol.copying_back_cached_build}\n")
602 if ($verbosity >= 1);
603 &util::rm_r ($builddir);
604 &util::cp_r ($realbuilddir, $builddir);
605 }
606
607 close OUT if $close_out;
608 close FAILLOG;
609
610 print STDERR "</Build>\n" if $gli;
611}
612## main() ##
613
614## @method create_images()
615#
616# [Used to create default cover images... from what I'm not quite sure - John]
617#
618sub create_images {
619 my ($collection_name) = @_;
620
621 my $image_script = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "script", "gimp", "title_icon-1.2.pl");
622 if (!-e $image_script) {
623 &gsprintf($out, "{buildcol.no_image_script}", $image_script);
624 &gsprintf($out, "{buildcol.no_default_images}\n\n");
625 return;
626 }
627
628 my $imagedir = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "images");
629
630 &util::mk_all_dir ($imagedir);
631
632 # create the images
633 system ("$image_script -size 1.5 -image_dir \"$imagedir\" -filename $collection.gif -text \"$collection_name\"");
634 system ("$image_script -image_dir \"$imagedir\" -filename ${collection}sm.gif -text \"$collection_name\"");
635
636 if ($gs_mode eq "gs3") {
637 # update the CollectionConfig.xml file
638 # what we need to do is find in CollectionConfig.xml the two elements with attributes 'icon' and 'smallicon'
639 # and replace the node text with $collection.gif and ${collection}sm.gif respectively. If they don't exist,
640 # create new ones by using the image names.
641
642
643 my $found = 0; my $foundsm = 0;
644
645 my $twig = XML::Twig->new();
646 $twig->parsefile($configfilename);
647 my $root = $twig->root;
648 my $displayItemList = $root->first_child('displayItemList');
649 my @displayItem = $displayItemList->children('displayItem');
650 foreach my $displayItem (@displayItem) {
651 my $att_value = $displayItem->{'att'}->{'name'};
652
653 if($att_value eq 'icon') {
654 $found = 1;
655 }
656 elsif ( $att_value eq 'smallicon') {
657 $foundsm = 1;
658 }
659 }
660
661 if ($found eq 0) { print "write icon";
662 my $icon_displayItem_element = XML::Twig::Elt->new('displayItem');
663 $icon_displayItem_element->set_att('name', '$collection.gif');
664 $icon_displayItem_element->set_att('lang', 'en');
665 $icon_displayItem_element->set_text("$collection.gif");
666 $icon_displayItem_element->paste('last_child', $displayItemList);
667 }
668 if ($foundsm eq 0) {
669 my $smallicon_displayItem_element = XML::Twig::Elt->new('displayItem');
670 $smallicon_displayItem_element->set_att('name', 'smallicon');
671 $smallicon_displayItem_element->set_att('lang', 'en');
672 $smallicon_displayItem_element->set_text("${collection}sm.gif");
673 $smallicon_displayItem_element->paste('last_child', $displayItemList);
674
675
676 }
677 open (OUT, ">$configfilename") or die "cannot open file $configfilename for output: $!";
678 #select OUT;
679 $twig->print( \*OUT );
680 close OUT;
681 return;
682 }
683
684 # update the collect.cfg configuration file (this will need
685 # to be changed when the config file format changes)
686 if (!open (CFGFILE, $configfilename)) {
687 &gsprintf($out, "{buildcol.cannot_open_cfg_file}\n", $configfilename);
688 &gsprintf($out, "{buildcol.unlinked_col_images}\n");
689 return;
690 }
691
692 my $line = ""; my $file = "";
693 my $found = 0; my $foundsm = 0;
694 while (defined ($line = <CFGFILE>)) {
695 if ($line =~ /collectionmeta\s+iconcollection\s+/) {
696 $line = "collectionmeta iconcollection _httpprefix_/collect/$collection/images/$collection.gif\n";
697 $found = 1;
698 } elsif ($line =~ /collectionmeta\s+iconcollectionsmall\s+/) {
699 $line = "collectionmeta iconcollectionsmall _httpprefix_/collect/$collection/images/${collection}sm.gif\n";
700 $foundsm = 1;
701 }
702 $file .= $line;
703 }
704 close CFGFILE;
705
706 $file .= "collectionmeta iconcollection _httpprefix_/collect/$collection/images/$collection.gif\n" if !$found;
707 $file .= "collectionmeta iconcollectionsmall _httpprefix_/collect/$collection/images/${collection}sm.gif\n" if !$foundsm;
708
709 if (!open (CFGFILE, ">$configfilename")) {
710 &gsprintf($out, "{buildcol.cannot_open_cfg_file}\n", $configfilename);
711 &gsprintf($out, "{buildcol.unlinked_col_images}\n");
712 return;
713 }
714 print CFGFILE $file;
715 close CFGFILE;
716}
717## create_images() ##
718
719## @method make_absolute()
720#
721# Ensure the given file path is absolute in respect to the given base path.
722#
723# @param $base_dir A string denoting the base path the given dir must be
724# absolute to.
725# @param $dir The directory to be made absolute as a string. Note that the
726# dir may already be absolute, in which case it will remain
727# unchanged.
728# @return The now absolute form of the directory as a string.
729#
730# @author John Thompson, DL Consulting Ltd.
731# @copy 2006 DL Consulting Ltd.
732#
733sub make_absolute()
734 {
735 my ($base_dir, $dir) = @_;
736 $dir = $base_dir . "/$dir" if ($dir =~ m#^[^/]#);
737 $dir =~ s|^/tmp_mnt||;
738 1 while($dir =~ s|/[^/]*/\.\./|/|g);
739 $dir =~ s|/[.][.]?/|/|g;
740 $dir =~ tr|/|/|s;
741 return $dir;
742 }
743## make_absolute() ##
Note: See TracBrowser for help on using the repository browser.