[14028] | 1 | #!/usr/bin/perl -w
|
---|
| 2 |
|
---|
[22743] | 3 | ###########################################################################
|
---|
| 4 | #
|
---|
| 5 | # buildcol.pl --
|
---|
[14028] | 6 | # A component of the Greenstone digital library software
|
---|
| 7 | # from the New Zealand Digital Library Project at the
|
---|
| 8 | # University of Waikato, New Zealand.
|
---|
| 9 | #
|
---|
[22743] | 10 | # Copyright (C) 1999 New Zealand Digital Library Project
|
---|
| 11 | #
|
---|
[14028] | 12 | # This program is free software; you can redistribute it and/or modify
|
---|
| 13 | # it under the terms of the GNU General Public License as published by
|
---|
| 14 | # the Free Software Foundation; either version 2 of the License, or
|
---|
| 15 | # (at your option) any later version.
|
---|
| 16 | #
|
---|
| 17 | # This program is distributed in the hope that it will be useful,
|
---|
| 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 20 | # GNU General Public License for more details.
|
---|
| 21 | #
|
---|
| 22 | # You should have received a copy of the GNU General Public License
|
---|
| 23 | # along with this program; if not, write to the Free Software
|
---|
| 24 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 25 | #
|
---|
[22743] | 26 | ###########################################################################
|
---|
| 27 |
|
---|
| 28 |
|
---|
| 29 | # This program will build a particular collection.
|
---|
| 30 |
|
---|
[14028] | 31 | package buildcol;
|
---|
| 32 |
|
---|
| 33 | BEGIN {
|
---|
| 34 | die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
|
---|
| 35 | die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};
|
---|
| 36 | unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
|
---|
| 37 | unshift (@INC, "$ENV{'GSDLHOME'}/perllib/cpan");
|
---|
| 38 | unshift (@INC, "$ENV{'GSDLHOME'}/perllib/cpan/XML/XPath");
|
---|
| 39 | unshift (@INC, "$ENV{'GSDLHOME'}/perllib/plugins");
|
---|
| 40 | unshift (@INC, "$ENV{'GSDLHOME'}/perllib/classify");
|
---|
[14942] | 41 |
|
---|
[25553] | 42 | if (defined $ENV{'GSDL-RUN-SETUP'}) {
|
---|
| 43 | require util;
|
---|
| 44 | &util::setup_greenstone_env($ENV{'GSDLHOME'}, $ENV{'GSDLOS'});
|
---|
| 45 | }
|
---|
| 46 |
|
---|
[14942] | 47 | if (defined $ENV{'GSDLEXTS'}) {
|
---|
| 48 | my @extensions = split(/:/,$ENV{'GSDLEXTS'});
|
---|
| 49 | foreach my $e (@extensions) {
|
---|
| 50 | my $ext_prefix = "$ENV{'GSDLHOME'}/ext/$e";
|
---|
| 51 |
|
---|
| 52 | unshift (@INC, "$ext_prefix/perllib");
|
---|
| 53 | unshift (@INC, "$ext_prefix/perllib/cpan");
|
---|
[16788] | 54 | unshift (@INC, "$ext_prefix/perllib/plugins");
|
---|
| 55 | unshift (@INC, "$ext_prefix/perllib/classify");
|
---|
[14942] | 56 | }
|
---|
| 57 | }
|
---|
[21292] | 58 | if (defined $ENV{'GSDL3EXTS'}) {
|
---|
| 59 | my @extensions = split(/:/,$ENV{'GSDL3EXTS'});
|
---|
| 60 | foreach my $e (@extensions) {
|
---|
| 61 | my $ext_prefix = "$ENV{'GSDL3SRCHOME'}/ext/$e";
|
---|
| 62 |
|
---|
| 63 | unshift (@INC, "$ext_prefix/perllib");
|
---|
| 64 | unshift (@INC, "$ext_prefix/perllib/cpan");
|
---|
| 65 | unshift (@INC, "$ext_prefix/perllib/plugins");
|
---|
| 66 | unshift (@INC, "$ext_prefix/perllib/classify");
|
---|
| 67 | }
|
---|
| 68 | }
|
---|
| 69 |
|
---|
[14028] | 70 | }
|
---|
| 71 |
|
---|
| 72 | use colcfg;
|
---|
[21633] | 73 | use dbutil;
|
---|
[14028] | 74 | use util;
|
---|
| 75 | use scriptutil;
|
---|
| 76 | use FileHandle;
|
---|
| 77 | use gsprintf;
|
---|
| 78 | use printusage;
|
---|
| 79 | use parse2;
|
---|
| 80 |
|
---|
| 81 | use strict;
|
---|
| 82 | no strict 'refs'; # allow filehandles to be variables and vice versa
|
---|
| 83 | no strict 'subs'; # allow barewords (eg STDERR) as function arguments
|
---|
| 84 |
|
---|
| 85 |
|
---|
| 86 | my $mode_list =
|
---|
| 87 | [ { 'name' => "all",
|
---|
| 88 | 'desc' => "{buildcol.mode.all}" },
|
---|
| 89 | { 'name' => "compress_text",
|
---|
| 90 | 'desc' => "{buildcol.mode.compress_text}" },
|
---|
| 91 | { 'name' => "build_index",
|
---|
| 92 | 'desc' => "{buildcol.mode.build_index}" },
|
---|
| 93 | { 'name' => "infodb",
|
---|
| 94 | 'desc' => "{buildcol.mode.infodb}" } ];
|
---|
| 95 |
|
---|
| 96 | my $sec_index_list =
|
---|
| 97 | [ {'name' => "never",
|
---|
| 98 | 'desc' => "{buildcol.sections_index_document_metadata.never}" },
|
---|
| 99 | {'name' => "always",
|
---|
| 100 | 'desc' => "{buildcol.sections_index_document_metadata.always}" },
|
---|
| 101 | {'name' => "unless_section_metadata_exists",
|
---|
| 102 | 'desc' => "{buildcol.sections_index_document_metadata.unless_section_metadata_exists}" }
|
---|
| 103 | ];
|
---|
| 104 |
|
---|
| 105 | my $arguments =
|
---|
[14247] | 106 | [ { 'name' => "remove_empty_classifications",
|
---|
[14028] | 107 | 'desc' => "{buildcol.remove_empty_classifications}",
|
---|
| 108 | 'type' => "flag",
|
---|
| 109 | 'reqd' => "no",
|
---|
| 110 | 'modegli' => "2" },
|
---|
| 111 | { 'name' => "archivedir",
|
---|
| 112 | 'desc' => "{buildcol.archivedir}",
|
---|
| 113 | 'type' => "string",
|
---|
| 114 | 'reqd' => "no",
|
---|
| 115 | 'hiddengli' => "yes" },
|
---|
| 116 | { 'name' => "builddir",
|
---|
| 117 | 'desc' => "{buildcol.builddir}",
|
---|
| 118 | 'type' => "string",
|
---|
| 119 | 'reqd' => "no",
|
---|
| 120 | 'hiddengli' => "yes" },
|
---|
| 121 | # { 'name' => "cachedir",
|
---|
| 122 | # 'desc' => "{buildcol.cachedir}",
|
---|
| 123 | # 'type' => "string",
|
---|
| 124 | # 'reqd' => "no" },
|
---|
| 125 | { 'name' => "collectdir",
|
---|
| 126 | 'desc' => "{buildcol.collectdir}",
|
---|
| 127 | 'type' => "string",
|
---|
| 128 | # parsearg left "" as default
|
---|
| 129 | #'deft' => &util::filename_cat ($ENV{'GSDLHOME'}, "collect"),
|
---|
| 130 | 'reqd' => "no",
|
---|
| 131 | 'hiddengli' => "yes" },
|
---|
[14925] | 132 | { 'name' => "site",
|
---|
| 133 | 'desc' => "{buildcol.site}",
|
---|
| 134 | 'type' => "string",
|
---|
| 135 | 'deft' => "",
|
---|
| 136 | 'reqd' => "no",
|
---|
| 137 | 'hiddengli' => "yes" },
|
---|
[14028] | 138 | { 'name' => "debug",
|
---|
| 139 | 'desc' => "{buildcol.debug}",
|
---|
| 140 | 'type' => "flag",
|
---|
| 141 | 'reqd' => "no",
|
---|
| 142 | 'hiddengli' => "yes" },
|
---|
| 143 | { 'name' => "faillog",
|
---|
| 144 | 'desc' => "{buildcol.faillog}",
|
---|
| 145 | 'type' => "string",
|
---|
| 146 | # parsearg left "" as default
|
---|
| 147 | #'deft' => &util::filename_cat("<collectdir>", "colname", "etc", "fail.log"),
|
---|
| 148 | 'reqd' => "no",
|
---|
[18590] | 149 | 'modegli' => "3" },
|
---|
[14028] | 150 | { 'name' => "index",
|
---|
| 151 | 'desc' => "{buildcol.index}",
|
---|
| 152 | 'type' => "string",
|
---|
| 153 | 'reqd' => "no",
|
---|
[18590] | 154 | 'modegli' => "3" },
|
---|
[14028] | 155 | { 'name' => "incremental",
|
---|
| 156 | 'desc' => "{buildcol.incremental}",
|
---|
| 157 | 'type' => "flag",
|
---|
| 158 | 'hiddengli' => "yes" },
|
---|
| 159 | { 'name' => "keepold",
|
---|
| 160 | 'desc' => "{buildcol.keepold}",
|
---|
| 161 | 'type' => "flag",
|
---|
| 162 | 'reqd' => "no",
|
---|
| 163 | #'modegli' => "3",
|
---|
| 164 | 'hiddengli' => "yes" },
|
---|
| 165 | { 'name' => "removeold",
|
---|
| 166 | 'desc' => "{buildcol.removeold}",
|
---|
| 167 | 'type' => "flag",
|
---|
| 168 | 'reqd' => "no",
|
---|
| 169 | #'modegli' => "3",
|
---|
| 170 | 'hiddengli' => "yes" },
|
---|
| 171 | { 'name' => "language",
|
---|
| 172 | 'desc' => "{scripts.language}",
|
---|
| 173 | 'type' => "string",
|
---|
| 174 | 'reqd' => "no",
|
---|
[18590] | 175 | 'modegli' => "3" },
|
---|
[14028] | 176 | { 'name' => "maxdocs",
|
---|
| 177 | 'desc' => "{buildcol.maxdocs}",
|
---|
| 178 | 'type' => "int",
|
---|
| 179 | 'reqd' => "no",
|
---|
| 180 | 'hiddengli' => "yes" },
|
---|
| 181 | { 'name' => "maxnumeric",
|
---|
| 182 | 'desc' => "{buildcol.maxnumeric}",
|
---|
| 183 | 'type' => "int",
|
---|
| 184 | 'reqd' => "no",
|
---|
| 185 | 'deft' => "4",
|
---|
| 186 | 'range' => "4,512",
|
---|
| 187 | 'modegli' => "3" },
|
---|
| 188 | { 'name' => "mode",
|
---|
| 189 | 'desc' => "{buildcol.mode}",
|
---|
| 190 | 'type' => "enum",
|
---|
| 191 | 'list' => $mode_list,
|
---|
| 192 | # parsearg left "" as default
|
---|
| 193 | # 'deft' => "all",
|
---|
| 194 | 'reqd' => "no",
|
---|
[18590] | 195 | 'modegli' => "3" },
|
---|
[14028] | 196 | { 'name' => "no_strip_html",
|
---|
| 197 | 'desc' => "{buildcol.no_strip_html}",
|
---|
| 198 | 'type' => "flag",
|
---|
| 199 | 'reqd' => "no",
|
---|
[18590] | 200 | 'modegli' => "3" },
|
---|
[24755] | 201 | { 'name' => "store_metadata_coverage",
|
---|
| 202 | 'desc' => "{buildcol.store_metadata_coverage}",
|
---|
| 203 | 'type' => "flag",
|
---|
| 204 | 'reqd' => "no",
|
---|
| 205 | 'modegli' => "3" },
|
---|
[14028] | 206 | { 'name' => "no_text",
|
---|
| 207 | 'desc' => "{buildcol.no_text}",
|
---|
| 208 | 'type' => "flag",
|
---|
| 209 | 'reqd' => "no",
|
---|
[18590] | 210 | 'modegli' => "2" },
|
---|
[14028] | 211 | { 'name' => "sections_index_document_metadata",
|
---|
| 212 | 'desc' => "{buildcol.sections_index_document_metadata}",
|
---|
| 213 | 'type' => "enum",
|
---|
| 214 | 'list' => $sec_index_list,
|
---|
| 215 | 'reqd' => "no",
|
---|
[18590] | 216 | 'modegli' => "2" },
|
---|
[14028] | 217 | { 'name' => "out",
|
---|
| 218 | 'desc' => "{buildcol.out}",
|
---|
| 219 | 'type' => "string",
|
---|
| 220 | 'deft' => "STDERR",
|
---|
| 221 | 'reqd' => "no",
|
---|
| 222 | 'hiddengli' => "yes" },
|
---|
| 223 | { 'name' => "verbosity",
|
---|
| 224 | 'desc' => "{buildcol.verbosity}",
|
---|
| 225 | 'type' => "int",
|
---|
| 226 | # parsearg left "" as default
|
---|
| 227 | #'deft' => "2",
|
---|
| 228 | 'reqd' => "no",
|
---|
[18590] | 229 | 'modegli' => "3" },
|
---|
[14028] | 230 | { 'name' => "gli",
|
---|
| 231 | 'desc' => "",
|
---|
| 232 | 'type' => "flag",
|
---|
| 233 | 'reqd' => "no",
|
---|
| 234 | 'hiddengli' => "yes" },
|
---|
| 235 | { 'name' => "xml",
|
---|
| 236 | 'desc' => "{scripts.xml}",
|
---|
| 237 | 'type' => "flag",
|
---|
| 238 | 'reqd' => "no",
|
---|
[14247] | 239 | 'hiddengli' => "yes" },
|
---|
[25573] | 240 | { 'name' => "activate",
|
---|
| 241 | 'desc' => "{buildcol.activate}",
|
---|
| 242 | 'type' => "flag",
|
---|
| 243 | 'reqd' => "no",
|
---|
| 244 | 'hiddengli' => "yes" },
|
---|
[14028] | 245 | ];
|
---|
| 246 |
|
---|
| 247 | my $options = { 'name' => "buildcol.pl",
|
---|
| 248 | 'desc' => "{buildcol.desc}",
|
---|
| 249 | 'args' => $arguments };
|
---|
| 250 |
|
---|
| 251 |
|
---|
| 252 | # globals
|
---|
| 253 | my $collection;
|
---|
| 254 | my $configfilename;
|
---|
| 255 | my $out;
|
---|
| 256 |
|
---|
| 257 | # used to signify "gs2"(default) or "gs3"
|
---|
| 258 | my $gs_mode = "gs2";
|
---|
| 259 |
|
---|
| 260 | ## @method gsprintf()
|
---|
| 261 | # Print a string to the screen after looking it up from a locale dependant
|
---|
| 262 | # strings file. This function is losely based on the idea of resource
|
---|
| 263 | # bundles as used in Java.
|
---|
| 264 | #
|
---|
| 265 | # @param $error The STDERR stream.
|
---|
| 266 | # @param $text The string containing GS keys that should be replaced with
|
---|
| 267 | # their locale dependant equivilents.
|
---|
| 268 | # @param $out The output stream.
|
---|
| 269 | # @return The locale-based string to output.
|
---|
| 270 | #
|
---|
| 271 | sub gsprintf()
|
---|
| 272 | {
|
---|
| 273 | return &gsprintf::gsprintf(@_);
|
---|
| 274 | }
|
---|
| 275 | ## gsprintf() ##
|
---|
| 276 |
|
---|
| 277 | &main();
|
---|
| 278 |
|
---|
| 279 | ## @method main()
|
---|
| 280 | #
|
---|
| 281 | # [Parses up and validates the arguments to the build process before creating
|
---|
| 282 | # the appropriate build process to do the actual work - John]
|
---|
| 283 | #
|
---|
| 284 | # @note Added true incremental support - John Thompson, DL Consulting Ltd.
|
---|
| 285 | # @note There were several bugs regarding using directories other than
|
---|
| 286 | # "import" or "archives" during import and build quashed. - John
|
---|
| 287 | # Thompson, DL Consulting Ltd.
|
---|
| 288 | #
|
---|
[16259] | 289 | # @param $incremental If true indicates this build should not regenerate all
|
---|
[14028] | 290 | # the index and metadata files, and should instead just
|
---|
| 291 | # append the information found in the archives directory
|
---|
| 292 | # to the existing files. If this requires some complex
|
---|
| 293 | # work so as to correctly insert into a classifier so be
|
---|
| 294 | # it. Of course none of this is done here - instead the
|
---|
| 295 | # incremental argument is passed to the document
|
---|
| 296 | # processor.
|
---|
| 297 | #
|
---|
| 298 | sub main
|
---|
| 299 | {
|
---|
| 300 | # command line args
|
---|
[14925] | 301 | my ($verbosity, $archivedir, $cachedir, $builddir, $site, $maxdocs,
|
---|
[20571] | 302 | $debug, $mode, $indexname, $removeold, $keepold,
|
---|
| 303 | $incremental, $incremental_mode,
|
---|
[14028] | 304 | $remove_empty_classifications,
|
---|
[17570] | 305 | $collectdir, $build, $type, $textindex,
|
---|
[24755] | 306 | $no_strip_html, $store_metadata_coverage,
|
---|
| 307 | $no_text, $faillog, $gli, $index, $language,
|
---|
[25573] | 308 | $sections_index_document_metadata, $maxnumeric, $activate);
|
---|
| 309 |
|
---|
[14028] | 310 | my $xml = 0;
|
---|
| 311 | my $hashParsingResult = {};
|
---|
| 312 | # general options available to all plugins
|
---|
| 313 | my $intArgLeftinAfterParsing = parse2::parse(\@ARGV,$arguments,$hashParsingResult,"allow_extra_options");
|
---|
| 314 |
|
---|
| 315 | # If parse returns -1 then something has gone wrong
|
---|
| 316 | if ($intArgLeftinAfterParsing == -1)
|
---|
| 317 | {
|
---|
| 318 | &PrintUsage::print_txt_usage($options, "{buildcol.params}");
|
---|
| 319 | die "\n";
|
---|
| 320 | }
|
---|
| 321 |
|
---|
| 322 | foreach my $strVariable (keys %$hashParsingResult)
|
---|
| 323 | {
|
---|
| 324 | eval "\$$strVariable = \$hashParsingResult->{\"\$strVariable\"}";
|
---|
| 325 | }
|
---|
| 326 |
|
---|
| 327 | # If $language has been specified, load the appropriate resource bundle
|
---|
| 328 | # (Otherwise, the default resource bundle will be loaded automatically)
|
---|
| 329 | if ($language && $language =~ /\S/) {
|
---|
| 330 | &gsprintf::load_language_specific_resource_bundle($language);
|
---|
| 331 | }
|
---|
| 332 |
|
---|
| 333 | if ($xml) {
|
---|
| 334 | &PrintUsage::print_xml_usage($options);
|
---|
| 335 | print "\n";
|
---|
| 336 | return;
|
---|
| 337 | }
|
---|
| 338 |
|
---|
| 339 | if ($gli) { # the gli wants strings to be in UTF-8
|
---|
| 340 | &gsprintf::output_strings_in_UTF8;
|
---|
| 341 | }
|
---|
| 342 |
|
---|
| 343 | # now check that we had exactly one leftover arg, which should be
|
---|
| 344 | # the collection name. We don't want to do this earlier, cos
|
---|
| 345 | # -xml arg doesn't need a collection name
|
---|
| 346 | # Or if the user specified -h, then we output the usage also
|
---|
| 347 | if ($intArgLeftinAfterParsing != 1 || (@ARGV && $ARGV[0] =~ /^\-+h/))
|
---|
| 348 | {
|
---|
| 349 | &PrintUsage::print_txt_usage($options, "{buildcol.params}");
|
---|
| 350 | die "\n";
|
---|
| 351 | }
|
---|
| 352 |
|
---|
| 353 | $textindex = "";
|
---|
| 354 | my $close_out = 0;
|
---|
| 355 | if ($out !~ /^(STDERR|STDOUT)$/i) {
|
---|
| 356 | open (OUT, ">$out") ||
|
---|
| 357 | (&gsprintf(STDERR, "{common.cannot_open_output_file}\n", $out) && die);
|
---|
| 358 | $out = "buildcol::OUT";
|
---|
| 359 | $close_out = 1;
|
---|
| 360 | }
|
---|
| 361 | $out->autoflush(1);
|
---|
| 362 |
|
---|
| 363 | # get and check the collection
|
---|
[14925] | 364 | if (($collection = &colcfg::use_collection($site, @ARGV, $collectdir)) eq "") {
|
---|
[14028] | 365 | &PrintUsage::print_txt_usage($options, "{buildcol.params}");
|
---|
| 366 | die "\n";
|
---|
| 367 | }
|
---|
| 368 |
|
---|
| 369 | if ($faillog eq "") {
|
---|
| 370 | $faillog = &util::filename_cat($ENV{'GSDLCOLLECTDIR'}, "etc", "fail.log");
|
---|
| 371 | }
|
---|
| 372 | # note that we're appending to the faillog here (import.pl clears it each time)
|
---|
| 373 | # this could potentially create a situation where the faillog keeps being added
|
---|
| 374 | # to over multiple builds (if the import process is being skipped)
|
---|
| 375 | open (FAILLOG, ">>$faillog") ||
|
---|
| 376 | (&gsprintf(STDERR, "{common.cannot_open_fail_log}\n", $faillog) && die);
|
---|
| 377 | $faillog = 'buildcol::FAILLOG';
|
---|
| 378 | $faillog->autoflush(1);
|
---|
| 379 |
|
---|
| 380 | unshift (@INC, "$ENV{'GSDLCOLLECTDIR'}/perllib");
|
---|
| 381 | # Don't know why this didn't already happen, but now collection specific
|
---|
| 382 | # classify and plugins directory also added to include path
|
---|
| 383 | unshift (@INC, "$ENV{'GSDLCOLLECTDIR'}/perllib/classify");
|
---|
| 384 | unshift (@INC, "$ENV{'GSDLCOLLECTDIR'}/perllib/plugins");
|
---|
| 385 |
|
---|
[14247] | 386 | # Read in the collection configuration file.
|
---|
[24463] | 387 | my ($collectcfg, $buildtype, $orthogonalbuildtypes);
|
---|
[14247] | 388 | ($configfilename, $gs_mode) = &colcfg::get_collect_cfg_name($out);
|
---|
[20098] | 389 | $collectcfg = &colcfg::read_collection_cfg ($configfilename, $gs_mode);
|
---|
[21613] | 390 |
|
---|
| 391 | # If the infodbtype value wasn't defined in the collect.cfg file, use the default
|
---|
| 392 | if (!defined($collectcfg->{'infodbtype'}))
|
---|
| 393 | {
|
---|
| 394 | $collectcfg->{'infodbtype'} = &dbutil::get_default_infodb_type();
|
---|
| 395 | }
|
---|
[14247] | 396 |
|
---|
[14028] | 397 | if ($verbosity !~ /\d+/) {
|
---|
| 398 | if (defined $collectcfg->{'verbosity'} && $collectcfg->{'verbosity'} =~ /\d+/) {
|
---|
| 399 | $verbosity = $collectcfg->{'verbosity'};
|
---|
| 400 | } else {
|
---|
| 401 | $verbosity = 2; # the default
|
---|
| 402 | }
|
---|
| 403 | }
|
---|
| 404 | # we use searchtype for determining buildtype, but for old versions, use buildtype
|
---|
| 405 | if (defined $collectcfg->{'buildtype'}) {
|
---|
| 406 | $buildtype = $collectcfg->{'buildtype'};
|
---|
| 407 | } elsif (defined $collectcfg->{'searchtypes'} || defined $collectcfg->{'searchtype'}) {
|
---|
| 408 | $buildtype = "mgpp";
|
---|
| 409 | } else {
|
---|
| 410 | $buildtype = "mg"; #mg is the default
|
---|
| 411 | }
|
---|
[24463] | 412 |
|
---|
| 413 | if (defined $collectcfg->{'orthogonalbuildtypes'}) {
|
---|
| 414 | $orthogonalbuildtypes = $collectcfg->{'orthogonalbuildtypes'};
|
---|
| 415 | }
|
---|
| 416 |
|
---|
[14028] | 417 | if (defined $collectcfg->{'archivedir'} && $archivedir eq "") {
|
---|
| 418 | $archivedir = $collectcfg->{'archivedir'};
|
---|
| 419 | }
|
---|
| 420 | if (defined $collectcfg->{'cachedir'} && $cachedir eq "") {
|
---|
| 421 | $cachedir = $collectcfg->{'cachedir'};
|
---|
| 422 | }
|
---|
| 423 | if (defined $collectcfg->{'builddir'} && $builddir eq "") {
|
---|
| 424 | $builddir = $collectcfg->{'builddir'};
|
---|
| 425 | }
|
---|
| 426 | if ($maxdocs !~ /\-?\d+/) {
|
---|
| 427 | if (defined $collectcfg->{'maxdocs'} && $collectcfg->{'maxdocs'} =~ /\-?\d+/) {
|
---|
| 428 | $maxdocs = $collectcfg->{'maxdocs'};
|
---|
| 429 | } else {
|
---|
| 430 | $maxdocs = -1; # the default
|
---|
| 431 | }
|
---|
| 432 | }
|
---|
| 433 | if (defined $collectcfg->{'maxnumeric'} && $collectcfg->{'maxnumeric'} =~ /\d+/) {
|
---|
| 434 | $maxnumeric = $collectcfg->{'maxnumeric'};
|
---|
| 435 | }
|
---|
| 436 |
|
---|
| 437 | if ($maxnumeric < 4 || $maxnumeric > 512) {
|
---|
| 438 | $maxnumeric = 4;
|
---|
| 439 | }
|
---|
| 440 |
|
---|
| 441 | if (defined $collectcfg->{'debug'} && $collectcfg->{'debug'} =~ /^true$/i) {
|
---|
| 442 | $debug = 1;
|
---|
| 443 | }
|
---|
| 444 | if ($mode !~ /^(all|compress_text|build_index|infodb)$/) {
|
---|
| 445 | if (defined $collectcfg->{'mode'} && $collectcfg->{'mode'} =~ /^(all|compress_text|build_index|infodb)$/) {
|
---|
| 446 | $mode = $collectcfg->{'mode'};
|
---|
| 447 | } else {
|
---|
| 448 | $mode = "all"; # the default
|
---|
| 449 | }
|
---|
| 450 | }
|
---|
| 451 | if (defined $collectcfg->{'index'} && $indexname eq "") {
|
---|
| 452 | $indexname = $collectcfg->{'index'};
|
---|
| 453 | }
|
---|
| 454 | if (defined $collectcfg->{'no_text'} && $no_text == 0) {
|
---|
| 455 | if ($collectcfg->{'no_text'} =~ /^true$/i) {
|
---|
| 456 | $no_text = 1;
|
---|
| 457 | }
|
---|
| 458 | }
|
---|
| 459 | if (defined $collectcfg->{'no_strip_html'} && $no_strip_html == 0) {
|
---|
| 460 | if ($collectcfg->{'no_strip_html'} =~ /^true$/i) {
|
---|
| 461 | $no_strip_html = 1;
|
---|
| 462 | }
|
---|
| 463 | }
|
---|
[24755] | 464 | if (defined $collectcfg->{'store_metadata_coverage'} && $store_metadata_coverage == 0) {
|
---|
| 465 | if ($collectcfg->{'store_metadata_coverage'} =~ /^true$/i) {
|
---|
| 466 | $store_metadata_coverage = 1;
|
---|
| 467 | }
|
---|
| 468 | }
|
---|
[14028] | 469 | if (defined $collectcfg->{'remove_empty_classifications'} && $remove_empty_classifications == 0) {
|
---|
| 470 | if ($collectcfg->{'remove_empty_classifications'} =~ /^true$/i) {
|
---|
| 471 | $remove_empty_classifications = 1;
|
---|
| 472 | }
|
---|
[14247] | 473 | }
|
---|
[14028] | 474 |
|
---|
| 475 | if ($buildtype eq "mgpp" && defined $collectcfg->{'textcompress'}) {
|
---|
| 476 | $textindex = $collectcfg->{'textcompress'};
|
---|
| 477 | }
|
---|
| 478 | if (defined $collectcfg->{'gli'} && $collectcfg->{'gli'} =~ /^true$/i) {
|
---|
| 479 | $gli = 1;
|
---|
| 480 | }
|
---|
| 481 |
|
---|
| 482 | if ($sections_index_document_metadata !~ /\S/ && defined $collectcfg->{'sections_index_document_metadata'}) {
|
---|
| 483 | $sections_index_document_metadata = $collectcfg->{'sections_index_document_metadata'};
|
---|
| 484 | }
|
---|
| 485 |
|
---|
| 486 | if ($sections_index_document_metadata !~ /^(never|always|unless_section_metadata_exists)$/) {
|
---|
| 487 | $sections_index_document_metadata = "never";
|
---|
| 488 | }
|
---|
| 489 |
|
---|
[20571] | 490 | ($removeold, $keepold, $incremental, $incremental_mode)
|
---|
| 491 | = &scriptutil::check_removeold_and_keepold($removeold, $keepold,
|
---|
| 492 | $incremental, "building",
|
---|
| 493 | $collectcfg);
|
---|
[14028] | 494 |
|
---|
| 495 | $gli = 0 unless defined $gli;
|
---|
[14247] | 496 |
|
---|
[14028] | 497 | # New argument to track whether build is incremental
|
---|
| 498 | $incremental = 0 unless defined $incremental;
|
---|
| 499 |
|
---|
| 500 | print STDERR "<Build>\n" if $gli;
|
---|
| 501 |
|
---|
| 502 | #set the text index
|
---|
[25758] | 503 | if (($buildtype eq "mgpp") || ($buildtype eq "lucene") || ($buildtype eq "solr")) {
|
---|
[14028] | 504 | if ($textindex eq "") {
|
---|
| 505 | $textindex = "text";
|
---|
| 506 | }
|
---|
| 507 | }
|
---|
| 508 | else {
|
---|
| 509 | $textindex = "section:text";
|
---|
| 510 | }
|
---|
| 511 |
|
---|
| 512 | # fill in the default archives and building directories if none
|
---|
| 513 | # were supplied, turn all \ into / and remove trailing /
|
---|
| 514 |
|
---|
| 515 | my ($realarchivedir, $realbuilddir);
|
---|
| 516 | # Modified so that the archivedir, if provided as an argument, is made
|
---|
| 517 | # absolute if it isn't already
|
---|
| 518 | if ($archivedir eq "")
|
---|
| 519 | {
|
---|
| 520 | $archivedir = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "archives");
|
---|
| 521 | }
|
---|
| 522 | else
|
---|
| 523 | {
|
---|
[17571] | 524 | $archivedir = &util::make_absolute($ENV{'GSDLCOLLECTDIR'}, $archivedir);
|
---|
[14028] | 525 | }
|
---|
| 526 | # End Mod
|
---|
| 527 | $archivedir =~ s/[\\\/]+/\//g;
|
---|
| 528 | $archivedir =~ s/\/$//;
|
---|
[17585] | 529 |
|
---|
| 530 | if ($builddir eq "") {
|
---|
| 531 | $builddir = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "building");
|
---|
| 532 | if ($incremental) {
|
---|
| 533 | &gsprintf($out, "{buildcol.incremental_default_builddir}\n");
|
---|
| 534 | }
|
---|
| 535 | }
|
---|
[14028] | 536 | $builddir =~ s/[\\\/]+/\//g;
|
---|
| 537 | $builddir =~ s/\/$//;
|
---|
| 538 |
|
---|
| 539 | # update the archive cache if needed
|
---|
| 540 | if ($cachedir) {
|
---|
| 541 | &gsprintf($out, "{buildcol.updating_archive_cache}\n")
|
---|
| 542 | if ($verbosity >= 1);
|
---|
| 543 |
|
---|
| 544 | $cachedir =~ s/[\\\/]+$//;
|
---|
| 545 | $cachedir .= "/collect/$collection" unless
|
---|
| 546 | $cachedir =~ /collect\/$collection/;
|
---|
| 547 |
|
---|
| 548 | $realarchivedir = "$cachedir/archives";
|
---|
| 549 | $realbuilddir = "$cachedir/building";
|
---|
| 550 | &util::mk_all_dir ($realarchivedir);
|
---|
| 551 | &util::mk_all_dir ($realbuilddir);
|
---|
| 552 | &util::cachedir ($archivedir, $realarchivedir, $verbosity);
|
---|
| 553 |
|
---|
| 554 | } else {
|
---|
| 555 | $realarchivedir = $archivedir;
|
---|
| 556 | $realbuilddir = $builddir;
|
---|
| 557 | }
|
---|
| 558 |
|
---|
| 559 | # build it in realbuilddir
|
---|
| 560 | &util::mk_all_dir ($realbuilddir);
|
---|
| 561 |
|
---|
| 562 | my ($buildertype, $builderdir, $builder);
|
---|
| 563 | # if a builder class has been created for this collection, use it
|
---|
| 564 | # otherwise, use the mg or mgpp builder
|
---|
[14247] | 565 | if (-e "$ENV{'GSDLCOLLECTDIR'}/custom/${collection}/perllib/custombuilder.pm") {
|
---|
| 566 | $builderdir = "$ENV{'GSDLCOLLECTDIR'}/custom/${collection}/perllib";
|
---|
| 567 | $buildertype = "custombuilder";
|
---|
| 568 | } elsif (-e "$ENV{'GSDLCOLLECTDIR'}/perllib/custombuilder.pm") {
|
---|
[14028] | 569 | $builderdir = "$ENV{'GSDLCOLLECTDIR'}/perllib";
|
---|
[14247] | 570 | $buildertype = "custombuilder";
|
---|
| 571 | } elsif (-e "$ENV{'GSDLCOLLECTDIR'}/perllib/${collection}builder.pm") {
|
---|
| 572 | $builderdir = "$ENV{'GSDLCOLLECTDIR'}/perllib";
|
---|
[14028] | 573 | $buildertype = "${collection}builder";
|
---|
[24343] | 574 | } else {
|
---|
| 575 |
|
---|
[24459] | 576 | $builderdir = undef;
|
---|
| 577 | if ($buildtype ne "") {
|
---|
| 578 | # caters for extension-based build types, such as 'solr'
|
---|
| 579 | $buildertype = $buildtype."builder";
|
---|
[14028] | 580 | }
|
---|
[24459] | 581 | else {
|
---|
| 582 | # Default to mgpp
|
---|
[14028] | 583 | $buildertype = "mgppbuilder";
|
---|
| 584 | }
|
---|
| 585 | }
|
---|
[24343] | 586 | # check for extension specific builders
|
---|
| 587 | # (that will then be run after main builder.pm
|
---|
| 588 |
|
---|
| 589 | my @builderdir_list = ($builderdir);
|
---|
| 590 | my @buildertype_list = ($buildertype);
|
---|
| 591 |
|
---|
[24463] | 592 | if (defined $orthogonalbuildtypes) {
|
---|
| 593 | foreach my $obt (@$orthogonalbuildtypes) {
|
---|
[14028] | 594 |
|
---|
[24463] | 595 | push(@builderdir_list,undef); # rely on @INC to find it
|
---|
| 596 | push(@buildertype_list,$obt."Builder");
|
---|
[24343] | 597 | }
|
---|
| 598 | }
|
---|
[14028] | 599 |
|
---|
[24343] | 600 | # Set up array of the main builder.pm, followed by any ones
|
---|
| 601 | # from the extension folders
|
---|
[14028] | 602 |
|
---|
[24343] | 603 | my $num_builders = scalar(@buildertype_list);
|
---|
| 604 | my @builders = ();
|
---|
| 605 |
|
---|
| 606 | for (my $i=0; $i<$num_builders; $i++) {
|
---|
| 607 | my $this_builder;
|
---|
| 608 | my $this_buildertype = $buildertype_list[$i];
|
---|
| 609 | my $this_builderdir = $builderdir_list[$i];
|
---|
| 610 |
|
---|
[24459] | 611 | if ((defined $this_builderdir) && ($this_builderdir ne "")) {
|
---|
| 612 | require "$this_builderdir/$this_buildertype.pm";
|
---|
| 613 | }
|
---|
| 614 | else {
|
---|
| 615 | require "$this_buildertype.pm";
|
---|
| 616 | }
|
---|
[24343] | 617 |
|
---|
[24495] | 618 | eval("\$this_builder = new $this_buildertype(\$site, \$collection, " .
|
---|
[24343] | 619 | "\$realarchivedir, \$realbuilddir, \$verbosity, " .
|
---|
| 620 | "\$maxdocs, \$debug, \$keepold, \$incremental, \$incremental_mode, " .
|
---|
| 621 | "\$remove_empty_classifications, " .
|
---|
| 622 | "\$out, \$no_text, \$faillog, \$gli)");
|
---|
| 623 | die "$@" if $@;
|
---|
| 624 |
|
---|
| 625 | push(@builders,$this_builder);
|
---|
[14028] | 626 | }
|
---|
[24343] | 627 |
|
---|
| 628 | # Init phase for builders
|
---|
| 629 | for (my $i=0; $i<$num_builders; $i++) {
|
---|
| 630 | my $this_buildertype = $buildertype_list[$i];
|
---|
| 631 | my $this_builderdir = $builderdir_list[$i];
|
---|
| 632 | my $this_builder = $builders[$i];
|
---|
| 633 |
|
---|
| 634 | $this_builder->init();
|
---|
| 635 | $this_builder->set_maxnumeric($maxnumeric);
|
---|
| 636 |
|
---|
| 637 | if (($this_buildertype eq "mgppbuilder") && $no_strip_html) {
|
---|
| 638 | $this_builder->set_strip_html(0);
|
---|
| 639 | }
|
---|
[24755] | 640 |
|
---|
[24343] | 641 | if ($sections_index_document_metadata ne "never") {
|
---|
| 642 | $this_builder->set_sections_index_document_metadata($sections_index_document_metadata);
|
---|
| 643 | }
|
---|
[24755] | 644 |
|
---|
| 645 | if ($store_metadata_coverage) {
|
---|
| 646 | $this_builder->set_store_metadata_coverage(1);
|
---|
| 647 | }
|
---|
[14028] | 648 | }
|
---|
| 649 |
|
---|
[24343] | 650 | # Run the requested passes
|
---|
| 651 |
|
---|
[14028] | 652 | if ($mode =~ /^all$/i) {
|
---|
[24343] | 653 |
|
---|
| 654 | # 'map' modifies the elements of the original array, so calling
|
---|
| 655 | # methods -- as done below -- will cause (by default) @builders
|
---|
| 656 | # to be changed to whatever these functions return (which is *not*
|
---|
| 657 | # what we want -- we want to leave the values unchanged)
|
---|
| 658 | # => Use 'local' (dynamic scoping) to give each 'map' call its
|
---|
| 659 | # own local copy This could also be done with:
|
---|
| 660 | # (my $new =$_)->method(); $new
|
---|
| 661 | # but is a bit more cumbersome to write
|
---|
[24459] | 662 |
|
---|
[24343] | 663 | map { local $_=$_; $_->compress_text($textindex); } @builders;
|
---|
| 664 | map { local $_=$_; $_->build_indexes($indexname); } @builders;
|
---|
| 665 | map { local $_=$_; $_->make_infodatabase(); } @builders;
|
---|
| 666 | map { local $_=$_; $_->collect_specific(); } @builders;
|
---|
[14028] | 667 | } elsif ($mode =~ /^compress_text$/i) {
|
---|
[24343] | 668 | map { local $_=$_; $_->compress_text($textindex); } @builders;
|
---|
[14028] | 669 | } elsif ($mode =~ /^build_index$/i) {
|
---|
[24343] | 670 | map { local $_=$_; $_->build_indexes($indexname); } @builders;
|
---|
[14028] | 671 | } elsif ($mode =~ /^infodb$/i) {
|
---|
[24343] | 672 | map { local $_=$_; $_->make_infodatabase(); } @builders;
|
---|
[14028] | 673 | } else {
|
---|
| 674 | (&gsprintf(STDERR, "{buildcol.unknown_mode}\n", $mode) && die);
|
---|
| 675 | }
|
---|
| 676 |
|
---|
[24343] | 677 | if (!$debug) {
|
---|
| 678 | map {local $_=$_; $_->make_auxiliary_files(); } @builders;
|
---|
| 679 | }
|
---|
| 680 | map {local $_=$_; $_->deinit(); } @builders;
|
---|
[14028] | 681 |
|
---|
| 682 | if (($realbuilddir ne $builddir) && !$debug) {
|
---|
| 683 | &gsprintf($out, "{buildcol.copying_back_cached_build}\n")
|
---|
| 684 | if ($verbosity >= 1);
|
---|
| 685 | &util::rm_r ($builddir);
|
---|
| 686 | &util::cp_r ($realbuilddir, $builddir);
|
---|
| 687 | }
|
---|
| 688 |
|
---|
[25573] | 689 | # if buildcol.pl was run with -activate, need to run activate.pl
|
---|
| 690 | # now that building's complete
|
---|
| 691 | if($activate) {
|
---|
| 692 |
|
---|
| 693 | #my $quoted_argv = join(" ", map { "\"$_\"" } @ARGV);
|
---|
| 694 |
|
---|
| 695 | my @activate_argv = ();
|
---|
[25579] | 696 | push(@activate_argv,"-collectdir",$collectdir) if($collectdir);
|
---|
| 697 | push(@activate_argv,"-builddir",$builddir) if($builddir);
|
---|
| 698 | push(@activate_argv,"-site",$site) if($site);
|
---|
| 699 | push(@activate_argv,"-verbosity",$verbosity) if($verbosity);
|
---|
[25573] | 700 | push(@activate_argv,"-removeold") if($removeold);
|
---|
| 701 | push(@activate_argv,"-keepold") if($keepold);
|
---|
| 702 | my $quoted_argv = join(" ", map { "\"$_\"" } @activate_argv);
|
---|
| 703 |
|
---|
| 704 | my $activatecol_cmd = "\"".&util::get_perl_exec()."\" -S activate.pl $quoted_argv \"$collection\"";
|
---|
| 705 |
|
---|
| 706 | my $activatecol_status = system($activatecol_cmd)/256;
|
---|
| 707 |
|
---|
| 708 | if ($activatecol_status != 0) {
|
---|
| 709 | print STDERR "Error: Failed to run: $activatecol_cmd\n";
|
---|
| 710 | print STDERR " $!\n" if ($! ne "");
|
---|
| 711 | exit(-1);
|
---|
| 712 | }
|
---|
| 713 | }
|
---|
| 714 |
|
---|
[14028] | 715 | close OUT if $close_out;
|
---|
| 716 | close FAILLOG;
|
---|
| 717 |
|
---|
| 718 | print STDERR "</Build>\n" if $gli;
|
---|
| 719 | }
|
---|
| 720 |
|
---|
| 721 |
|
---|
[24343] | 722 |
|
---|