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

Last change on this file since 16259 was 16259, checked in by mdewsnip, 16 years ago

Removed the "-incremental" option from buildcol.pl (because it didn't do anything different to "-keepold", and changed "-incremental_dlc" back to "-incremental". Lots more incremental improvements on the way.

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