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

Last change on this file since 14197 was 14197, checked in by xiao, 17 years ago

add an argument called disable_OAI (default is 0, i.e., enable the collection for oai metadata harvesting). Pass this argument to basebuilder.pm via the new sub.

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