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