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

Last change on this file since 14925 was 14925, checked in by dmn, 16 years ago

davidbs changes to update for gs3 building

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