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