[14031] | 1 | #!/usr/bin/perl -w
|
---|
| 2 |
|
---|
| 3 | ###########################################################################
|
---|
| 4 | #
|
---|
| 5 | # import.pl --
|
---|
| 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 | #
|
---|
| 10 | # Copyright (C) 1999 New Zealand Digital Library Project
|
---|
| 11 | #
|
---|
| 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 | #
|
---|
| 26 | ###########################################################################
|
---|
| 27 |
|
---|
| 28 |
|
---|
| 29 | # This program will import a number of files into a particular collection
|
---|
| 30 |
|
---|
| 31 | package import;
|
---|
| 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");
|
---|
[20571] | 38 | unshift (@INC, "$ENV{'GSDLHOME'}/perllib/cpan/perl-5.8");
|
---|
[14031] | 39 | unshift (@INC, "$ENV{'GSDLHOME'}/perllib/plugins");
|
---|
| 40 | unshift (@INC, "$ENV{'GSDLHOME'}/perllib/plugouts");
|
---|
[14957] | 41 |
|
---|
| 42 | if (defined $ENV{'GSDLEXTS'}) {
|
---|
| 43 | my @extensions = split(/:/,$ENV{'GSDLEXTS'});
|
---|
| 44 | foreach my $e (@extensions) {
|
---|
| 45 | my $ext_prefix = "$ENV{'GSDLHOME'}/ext/$e";
|
---|
| 46 |
|
---|
| 47 | unshift (@INC, "$ext_prefix/perllib");
|
---|
| 48 | unshift (@INC, "$ext_prefix/perllib/cpan");
|
---|
[16788] | 49 | unshift (@INC, "$ext_prefix/perllib/plugins");
|
---|
| 50 | unshift (@INC, "$ext_prefix/perllib/plugouts");
|
---|
[14957] | 51 | }
|
---|
| 52 | }
|
---|
[21291] | 53 | if (defined $ENV{'GSDL3EXTS'}) {
|
---|
| 54 | my @extensions = split(/:/,$ENV{'GSDL3EXTS'});
|
---|
| 55 | foreach my $e (@extensions) {
|
---|
| 56 | my $ext_prefix = "$ENV{'GSDL3SRCHOME'}/ext/$e";
|
---|
| 57 |
|
---|
| 58 | unshift (@INC, "$ext_prefix/perllib");
|
---|
| 59 | unshift (@INC, "$ext_prefix/perllib/cpan");
|
---|
| 60 | unshift (@INC, "$ext_prefix/perllib/plugins");
|
---|
| 61 | unshift (@INC, "$ext_prefix/perllib/plugouts");
|
---|
| 62 | }
|
---|
| 63 | }
|
---|
[14031] | 64 | }
|
---|
| 65 |
|
---|
[14957] | 66 | use strict;
|
---|
| 67 | no strict 'refs'; # allow filehandles to be variables and vice versa
|
---|
| 68 | no strict 'subs'; # allow barewords (eg STDERR) as function arguments
|
---|
| 69 |
|
---|
[14031] | 70 | use arcinfo;
|
---|
| 71 | use colcfg;
|
---|
[21633] | 72 | use dbutil;
|
---|
[14031] | 73 | use plugin;
|
---|
| 74 | use plugout;
|
---|
| 75 | use manifest;
|
---|
[18456] | 76 | use inexport;
|
---|
[14031] | 77 | use util;
|
---|
| 78 | use scriptutil;
|
---|
| 79 | use FileHandle;
|
---|
| 80 | use gsprintf 'gsprintf';
|
---|
| 81 | use printusage;
|
---|
| 82 | use parse2;
|
---|
| 83 |
|
---|
| 84 |
|
---|
| 85 |
|
---|
| 86 | my $oidtype_list =
|
---|
| 87 | [ { 'name' => "hash",
|
---|
| 88 | 'desc' => "{import.OIDtype.hash}" },
|
---|
| 89 | { 'name' => "assigned",
|
---|
| 90 | 'desc' => "{import.OIDtype.assigned}" },
|
---|
| 91 | { 'name' => "incremental",
|
---|
| 92 | 'desc' => "{import.OIDtype.incremental}" },
|
---|
| 93 | { 'name' => "dirname",
|
---|
| 94 | 'desc' => "{import.OIDtype.dirname}" } ];
|
---|
| 95 |
|
---|
[14957] | 96 |
|
---|
| 97 | # used to control output file format
|
---|
[14031] | 98 | my $saveas_list =
|
---|
[17751] | 99 | [ { 'name' => "GreenstoneXML",
|
---|
| 100 | 'desc' => "{export.saveas.GreenstoneXML}"},
|
---|
[14957] | 101 | { 'name' => "GreenstoneMETS",
|
---|
| 102 | 'desc' => "{export.saveas.GreenstoneMETS}"},
|
---|
[17038] | 103 | ];
|
---|
[14031] | 104 |
|
---|
| 105 |
|
---|
| 106 | # Possible attributes for each argument
|
---|
| 107 | # name: The name of the argument
|
---|
| 108 | # desc: A description (or more likely a reference to a description) for this argument
|
---|
| 109 | # type: The type of control used to represent the argument. Options include: string, int, flag, regexp, metadata, language, enum etc
|
---|
| 110 | # reqd: Is this argument required?
|
---|
| 111 | # hiddengli: Is this argument hidden in GLI?
|
---|
| 112 | # modegli: The lowest detail mode this argument is visible at in GLI
|
---|
| 113 |
|
---|
[14957] | 114 | my $saveas_argument
|
---|
| 115 | = { 'name' => "saveas",
|
---|
| 116 | 'desc' => "{import.saveas}",
|
---|
| 117 | 'type' => "enum",
|
---|
| 118 | 'list' => $saveas_list,
|
---|
[17751] | 119 | 'deft' => "GreenstoneXML",
|
---|
[14957] | 120 | 'reqd' => "no",
|
---|
| 121 | 'modegli' => "3" };
|
---|
| 122 |
|
---|
| 123 |
|
---|
[14031] | 124 | my $arguments =
|
---|
[14957] | 125 | [
|
---|
| 126 | $saveas_argument,
|
---|
| 127 | { 'name' => "archivedir",
|
---|
[14031] | 128 | 'desc' => "{import.archivedir}",
|
---|
| 129 | 'type' => "string",
|
---|
| 130 | 'reqd' => "no",
|
---|
| 131 | 'hiddengli' => "yes" },
|
---|
[14957] | 132 | { 'name' => "importdir",
|
---|
| 133 | 'desc' => "{import.importdir}",
|
---|
| 134 | 'type' => "string",
|
---|
| 135 | 'reqd' => "no",
|
---|
| 136 | 'hiddengli' => "yes" },
|
---|
[14031] | 137 | { 'name' => "collectdir",
|
---|
| 138 | 'desc' => "{import.collectdir}",
|
---|
| 139 | 'type' => "string",
|
---|
| 140 | # parsearg left "" as default
|
---|
| 141 | #'deft' => &util::filename_cat ($ENV{'GSDLHOME'}, "collect"),
|
---|
| 142 | 'deft' => "",
|
---|
| 143 | 'reqd' => "no",
|
---|
| 144 | 'hiddengli' => "yes" },
|
---|
[14925] | 145 | { 'name' => "site",
|
---|
| 146 | 'desc' => "{import.site}",
|
---|
| 147 | 'type' => "string",
|
---|
| 148 | 'deft' => "",
|
---|
| 149 | 'reqd' => "no",
|
---|
| 150 | 'hiddengli' => "yes" },
|
---|
[14031] | 151 | { 'name' => "manifest",
|
---|
| 152 | 'desc' => "{import.manifest}",
|
---|
| 153 | 'type' => "string",
|
---|
| 154 | 'deft' => "",
|
---|
| 155 | 'reqd' => "no",
|
---|
| 156 | 'hiddengli' => "yes" },
|
---|
| 157 | { 'name' => "debug",
|
---|
| 158 | 'desc' => "{import.debug}",
|
---|
| 159 | 'type' => "flag",
|
---|
| 160 | 'reqd' => "no",
|
---|
| 161 | 'hiddengli' => "yes" },
|
---|
| 162 | { 'name' => "faillog",
|
---|
| 163 | 'desc' => "{import.faillog}",
|
---|
| 164 | 'type' => "string",
|
---|
| 165 | # parsearg left "" as default
|
---|
| 166 | #'deft' => &util::filename_cat("<collectdir>", "colname", "etc", "fail.log"),
|
---|
| 167 | 'deft' => "",
|
---|
| 168 | 'reqd' => "no",
|
---|
[18590] | 169 | 'modegli' => "3" },
|
---|
[14031] | 170 | { 'name' => "incremental",
|
---|
| 171 | 'desc' => "{import.incremental}",
|
---|
| 172 | 'type' => "flag",
|
---|
| 173 | 'hiddengli' => "yes" },
|
---|
| 174 | { 'name' => "keepold",
|
---|
| 175 | 'desc' => "{import.keepold}",
|
---|
| 176 | 'type' => "flag",
|
---|
| 177 | 'reqd' => "no",
|
---|
| 178 | 'hiddengli' => "yes" },
|
---|
| 179 | { 'name' => "removeold",
|
---|
| 180 | 'desc' => "{import.removeold}",
|
---|
| 181 | 'type' => "flag",
|
---|
| 182 | 'reqd' => "no",
|
---|
| 183 | 'hiddengli' => "yes" },
|
---|
| 184 | { 'name' => "language",
|
---|
| 185 | 'desc' => "{scripts.language}",
|
---|
| 186 | 'type' => "string",
|
---|
| 187 | 'reqd' => "no",
|
---|
| 188 | 'hiddengli' => "yes" },
|
---|
| 189 | { 'name' => "maxdocs",
|
---|
| 190 | 'desc' => "{import.maxdocs}",
|
---|
| 191 | 'type' => "int",
|
---|
| 192 | 'reqd' => "no",
|
---|
| 193 | # parsearg left "" as default
|
---|
| 194 | #'deft' => "-1",
|
---|
| 195 | 'range' => "1,",
|
---|
| 196 | 'modegli' => "1" },
|
---|
[17038] | 197 | # don't set the default to hash - want to allow this to come from
|
---|
| 198 | # entry in collect.cfg but want to override it here
|
---|
[14031] | 199 | { 'name' => "OIDtype",
|
---|
| 200 | 'desc' => "{import.OIDtype}",
|
---|
| 201 | 'type' => "enum",
|
---|
| 202 | 'list' => $oidtype_list,
|
---|
| 203 | # parsearg left "" as default
|
---|
| 204 | #'deft' => "hash",
|
---|
| 205 | 'reqd' => "no",
|
---|
| 206 | 'modegli' => "2" },
|
---|
| 207 | { 'name' => "OIDmetadata",
|
---|
| 208 | 'desc' => "{import.OIDmetadata}",
|
---|
[19625] | 209 | 'type' => "string",
|
---|
[20685] | 210 | #'type' => "metadata", #doesn't work properly in GLI
|
---|
[18528] | 211 | # parsearg left "" as default
|
---|
| 212 | #'deft' => "dc.Identifier",
|
---|
[14031] | 213 | 'reqd' => "no",
|
---|
| 214 | 'modegli' => "2" },
|
---|
| 215 | { 'name' => "out",
|
---|
| 216 | 'desc' => "{import.out}",
|
---|
| 217 | 'type' => "string",
|
---|
| 218 | 'deft' => "STDERR",
|
---|
| 219 | 'reqd' => "no",
|
---|
| 220 | 'hiddengli' => "yes" },
|
---|
| 221 | { 'name' => "sortmeta",
|
---|
| 222 | 'desc' => "{import.sortmeta}",
|
---|
[19625] | 223 | 'type' => "string",
|
---|
| 224 | #'type' => "metadata", #doesn't work properly in GLI
|
---|
[14031] | 225 | 'reqd' => "no",
|
---|
[18590] | 226 | 'modegli' => "2" },
|
---|
[14031] | 227 | { 'name' => "removeprefix",
|
---|
| 228 | 'desc' => "{BasClas.removeprefix}",
|
---|
| 229 | 'type' => "regexp",
|
---|
| 230 | 'deft' => "",
|
---|
| 231 | 'reqd' => "no",
|
---|
| 232 | 'modegli' => "3" },
|
---|
| 233 | { 'name' => "removesuffix",
|
---|
| 234 | 'desc' => "{BasClas.removesuffix}",
|
---|
| 235 | 'type' => "regexp",
|
---|
| 236 | 'deft' => "",
|
---|
| 237 | 'reqd' => "no",
|
---|
| 238 | 'modegli' => "3" },
|
---|
| 239 | { 'name' => "groupsize",
|
---|
| 240 | 'desc' => "{import.groupsize}",
|
---|
| 241 | 'type' => "int",
|
---|
| 242 | 'deft' => "1",
|
---|
| 243 | 'reqd' => "no",
|
---|
[18590] | 244 | 'modegli' => "2" },
|
---|
[14031] | 245 | { 'name' => "gzip",
|
---|
| 246 | 'desc' => "{import.gzip}",
|
---|
| 247 | 'type' => "flag",
|
---|
| 248 | 'reqd' => "no",
|
---|
[18590] | 249 | 'modegli' => "3" },
|
---|
[14031] | 250 | { 'name' => "statsfile",
|
---|
| 251 | 'desc' => "{import.statsfile}",
|
---|
| 252 | 'type' => "string",
|
---|
| 253 | 'deft' => "STDERR",
|
---|
| 254 | 'reqd' => "no",
|
---|
| 255 | 'hiddengli' => "yes" },
|
---|
| 256 | { 'name' => "verbosity",
|
---|
| 257 | 'desc' => "{import.verbosity}",
|
---|
| 258 | 'type' => "int",
|
---|
| 259 | 'range' => "0,",
|
---|
| 260 | # parsearg left "" as default
|
---|
| 261 | #'deft' => "2",
|
---|
| 262 | 'reqd' => "no",
|
---|
[18590] | 263 | 'modegli' => "3" },
|
---|
[14031] | 264 | { 'name' => "gli",
|
---|
[17142] | 265 | 'desc' => "{scripts.gli}",
|
---|
[14031] | 266 | 'type' => "flag",
|
---|
| 267 | 'reqd' => "no",
|
---|
| 268 | 'hiddengli' => "yes" },
|
---|
| 269 | { 'name' => "xml",
|
---|
| 270 | 'desc' => "{scripts.xml}",
|
---|
| 271 | 'type' => "flag",
|
---|
| 272 | 'reqd' => "no",
|
---|
| 273 | 'hiddengli' => "yes" }];
|
---|
| 274 |
|
---|
| 275 | my $options = { 'name' => "import.pl",
|
---|
| 276 | 'desc' => "{import.desc}",
|
---|
| 277 | 'args' => $arguments };
|
---|
| 278 |
|
---|
| 279 |
|
---|
| 280 | &main();
|
---|
| 281 |
|
---|
| 282 | sub main {
|
---|
[14957] | 283 | # params
|
---|
| 284 | my ($language, $verbosity, $debug,
|
---|
[17142] | 285 | $collectdir, $importdir, $archivedir, $site, $manifest,
|
---|
[20571] | 286 | $incremental, $incremental_mode, $keepold, $removeold,
|
---|
[17142] | 287 | $saveas,
|
---|
[14957] | 288 | $OIDtype, $OIDmetadata,
|
---|
| 289 | $maxdocs, $statsfile,
|
---|
[17142] | 290 | $out, $faillog, $gli,
|
---|
[14957] | 291 | $gzip, $groupsize,
|
---|
[20757] | 292 | $sortmeta, $removeprefix, $removesuffix
|
---|
[14957] | 293 | );
|
---|
| 294 |
|
---|
[14031] | 295 | my $xml = 0;
|
---|
| 296 |
|
---|
[14957] | 297 | # other vars
|
---|
[17142] | 298 | my ($configfilename, $collection, $collectcfg,
|
---|
[18440] | 299 | $arcinfo_doc_filename, $arcinfo_src_filename, $archive_info,
|
---|
[14957] | 300 | $gs_mode,
|
---|
| 301 | $processor, $pluginfo);
|
---|
| 302 |
|
---|
[14031] | 303 | my $service = "import";
|
---|
| 304 |
|
---|
| 305 | my $hashParsingResult = {};
|
---|
| 306 | # general options available to all plugins
|
---|
| 307 | my $intArgLeftinAfterParsing = parse2::parse(\@ARGV,$arguments,$hashParsingResult,"allow_extra_options");
|
---|
| 308 | # Parse returns -1 if something has gone wrong
|
---|
[14957] | 309 | if ($intArgLeftinAfterParsing == -1)
|
---|
[14031] | 310 | {
|
---|
| 311 | &PrintUsage::print_txt_usage($options, "{import.params}");
|
---|
| 312 | die "\n";
|
---|
| 313 | }
|
---|
| 314 |
|
---|
| 315 | foreach my $strVariable (keys %$hashParsingResult)
|
---|
| 316 | {
|
---|
| 317 | eval "\$$strVariable = \$hashParsingResult->{\"\$strVariable\"}";
|
---|
| 318 | }
|
---|
| 319 |
|
---|
| 320 | # If $language has been specified, load the appropriate resource bundle
|
---|
| 321 | # (Otherwise, the default resource bundle will be loaded automatically)
|
---|
| 322 | if ($language && $language =~ /\S/) {
|
---|
| 323 | &gsprintf::load_language_specific_resource_bundle($language);
|
---|
| 324 | }
|
---|
| 325 |
|
---|
| 326 | if ($xml) {
|
---|
| 327 | &PrintUsage::print_xml_usage($options);
|
---|
| 328 | print "\n";
|
---|
| 329 | return;
|
---|
| 330 | }
|
---|
| 331 |
|
---|
| 332 | if ($gli) { # the gli wants strings to be in UTF-8
|
---|
| 333 | &gsprintf::output_strings_in_UTF8;
|
---|
| 334 | }
|
---|
| 335 |
|
---|
| 336 | # now check that we had exactly one leftover arg, which should be
|
---|
| 337 | # the collection name. We don't want to do this earlier, cos
|
---|
| 338 | # -xml arg doesn't need a collection name
|
---|
| 339 | # Or if the user specified -h, then we output the usage also
|
---|
| 340 | if ($intArgLeftinAfterParsing != 1 || (@ARGV && $ARGV[0] =~ /^\-+h/))
|
---|
| 341 | {
|
---|
[17142] | 342 | &PrintUsage::print_txt_usage($options, "{import.params}");
|
---|
[14031] | 343 | die "\n";
|
---|
| 344 | }
|
---|
| 345 |
|
---|
| 346 | my $close_out = 0;
|
---|
| 347 | if ($out !~ /^(STDERR|STDOUT)$/i) {
|
---|
| 348 | open (OUT, ">$out") ||
|
---|
| 349 | (&gsprintf(STDERR, "{common.cannot_open_output_file}: $!\n", $out) && die);
|
---|
| 350 | $out = 'import::OUT';
|
---|
| 351 | $close_out = 1;
|
---|
| 352 | }
|
---|
| 353 | $out->autoflush(1);
|
---|
| 354 |
|
---|
| 355 | # get and check the collection name
|
---|
[14925] | 356 | if (($collection = &colcfg::use_collection($site, @ARGV, $collectdir)) eq "") {
|
---|
[14031] | 357 | &PrintUsage::print_txt_usage($options, "{import.params}");
|
---|
| 358 | die "\n";
|
---|
| 359 | }
|
---|
| 360 |
|
---|
| 361 | # add collection's perllib dir into include path in
|
---|
| 362 | # case we have collection specific modules
|
---|
| 363 | unshift (@INC, "$ENV{'GSDLCOLLECTDIR'}/perllib");
|
---|
| 364 |
|
---|
| 365 | # check that we can open the faillog
|
---|
| 366 | if ($faillog eq "") {
|
---|
| 367 | $faillog = &util::filename_cat($ENV{'GSDLCOLLECTDIR'}, "etc", "fail.log");
|
---|
| 368 | }
|
---|
| 369 | open (FAILLOG, ">$faillog") ||
|
---|
| 370 | (&gsprintf(STDERR, "{import.cannot_open_fail_log}\n", $faillog) && die);
|
---|
| 371 |
|
---|
| 372 |
|
---|
| 373 | my $faillogname = $faillog;
|
---|
| 374 | $faillog = 'import::FAILLOG';
|
---|
| 375 | $faillog->autoflush(1);
|
---|
| 376 |
|
---|
[14111] | 377 | # Read in the collection configuration file.
|
---|
| 378 | ($configfilename, $gs_mode) = &colcfg::get_collect_cfg_name($out);
|
---|
[20098] | 379 | $collectcfg = &colcfg::read_collection_cfg ($configfilename, $gs_mode);
|
---|
[21613] | 380 |
|
---|
| 381 | # If the infodbtype value wasn't defined in the collect.cfg file, use the default
|
---|
| 382 | if (!defined($collectcfg->{'infodbtype'}))
|
---|
| 383 | {
|
---|
| 384 | $collectcfg->{'infodbtype'} = &dbutil::get_default_infodb_type();
|
---|
| 385 | }
|
---|
[14925] | 386 |
|
---|
[14031] | 387 | if (defined $collectcfg->{'importdir'} && $importdir eq "") {
|
---|
| 388 | $importdir = $collectcfg->{'importdir'};
|
---|
| 389 | }
|
---|
| 390 | if (defined $collectcfg->{'archivedir'} && $archivedir eq "") {
|
---|
| 391 | $archivedir = $collectcfg->{'archivedir'};
|
---|
| 392 | }
|
---|
| 393 | # fill in the default import and archives directories if none
|
---|
| 394 | # were supplied, turn all \ into / and remove trailing /
|
---|
| 395 | $importdir = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "import") if $importdir eq "";
|
---|
| 396 | $importdir =~ s/[\\\/]+/\//g;
|
---|
| 397 | $importdir =~ s/\/$//;
|
---|
| 398 | if (!-e $importdir) {
|
---|
| 399 | &gsprintf($out, "{import.no_import_dir}\n\n", $importdir);
|
---|
| 400 | die "\n";
|
---|
| 401 | }
|
---|
| 402 |
|
---|
| 403 | $archivedir = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "archives") if $archivedir eq "";
|
---|
| 404 | $archivedir =~ s/[\\\/]+/\//g;
|
---|
| 405 | $archivedir =~ s/\/$//;
|
---|
| 406 |
|
---|
| 407 | my $plugins = [];
|
---|
| 408 | if (defined $collectcfg->{'plugin'}) {
|
---|
| 409 | $plugins = $collectcfg->{'plugin'};
|
---|
| 410 | }
|
---|
| 411 | #some global options for the plugins
|
---|
| 412 | my @global_opts = ();
|
---|
| 413 |
|
---|
| 414 | if ($verbosity !~ /\d+/) {
|
---|
| 415 | if (defined $collectcfg->{'verbosity'} && $collectcfg->{'verbosity'} =~ /\d+/) {
|
---|
| 416 | $verbosity = $collectcfg->{'verbosity'};
|
---|
| 417 | } else {
|
---|
| 418 | $verbosity = 2; # the default
|
---|
| 419 | }
|
---|
| 420 | }
|
---|
| 421 | if (defined $collectcfg->{'manifest'} && $manifest eq "") {
|
---|
| 422 | $manifest = $collectcfg->{'manifest'};
|
---|
| 423 | }
|
---|
| 424 |
|
---|
| 425 | if (defined $collectcfg->{'gzip'} && !$gzip) {
|
---|
| 426 | if ($collectcfg->{'gzip'} =~ /^true$/i) {
|
---|
| 427 | $gzip = 1;
|
---|
| 428 | }
|
---|
| 429 | }
|
---|
| 430 |
|
---|
| 431 | if ($maxdocs !~ /\-?\d+/) {
|
---|
| 432 | if (defined $collectcfg->{'maxdocs'} && $collectcfg->{'maxdocs'} =~ /\-?\d+/) {
|
---|
| 433 | $maxdocs = $collectcfg->{'maxdocs'};
|
---|
| 434 | } else {
|
---|
| 435 | $maxdocs = -1; # the default
|
---|
| 436 | }
|
---|
| 437 | }
|
---|
| 438 | if ($groupsize == 1) {
|
---|
| 439 | if (defined $collectcfg->{'groupsize'} && $collectcfg->{'groupsize'} =~ /\d+/) {
|
---|
| 440 | $groupsize = $collectcfg->{'groupsize'};
|
---|
| 441 | }
|
---|
| 442 | }
|
---|
| 443 |
|
---|
[17142] | 444 | if (!defined $OIDtype || ($OIDtype !~ /^(hash|incremental|assigned|dirname)$/ )) {
|
---|
[14031] | 445 | if (defined $collectcfg->{'OIDtype'} && $collectcfg->{'OIDtype'} =~ /^(hash|incremental|assigned|dirname)$/) {
|
---|
| 446 | $OIDtype = $collectcfg->{'OIDtype'};
|
---|
| 447 | } else {
|
---|
| 448 | $OIDtype = "hash"; # the default
|
---|
| 449 | }
|
---|
| 450 | }
|
---|
[14556] | 451 |
|
---|
[18528] | 452 | if ((!defined $OIDmetadata) || ($OIDmetadata eq "")) {
|
---|
| 453 | if (defined $collectcfg->{'OIDmetadata'}) {
|
---|
| 454 | $OIDmetadata = $collectcfg->{'OIDmetadata'};
|
---|
| 455 | } else {
|
---|
| 456 | $OIDmetadata = "dc.Identifier"; # the default
|
---|
| 457 | }
|
---|
| 458 | }
|
---|
| 459 |
|
---|
[14031] | 460 | if (defined $collectcfg->{'sortmeta'} && (!defined $sortmeta || $sortmeta eq "")) {
|
---|
| 461 | $sortmeta = $collectcfg->{'sortmeta'};
|
---|
| 462 | }
|
---|
| 463 | # sortmeta cannot be used with group size
|
---|
| 464 | $sortmeta = undef unless defined $sortmeta && $sortmeta =~ /\S/;
|
---|
| 465 | if (defined $sortmeta && $groupsize > 1) {
|
---|
| 466 | &gsprintf($out, "{import.cannot_sort}\n\n");
|
---|
| 467 | $sortmeta = undef;
|
---|
| 468 | }
|
---|
[15072] | 469 |
|
---|
[14031] | 470 | if (defined $collectcfg->{'removeprefix'} && $removeprefix eq "") {
|
---|
| 471 | $removeprefix = $collectcfg->{'removeprefix'};
|
---|
| 472 | }
|
---|
| 473 |
|
---|
| 474 | if (defined $collectcfg->{'removesuffix'} && $removesuffix eq "") {
|
---|
| 475 | $removesuffix = $collectcfg->{'removesuffix'};
|
---|
| 476 | }
|
---|
| 477 | if (defined $collectcfg->{'debug'} && $collectcfg->{'debug'} =~ /^true$/i) {
|
---|
| 478 | $debug = 1;
|
---|
| 479 | }
|
---|
| 480 | if (defined $collectcfg->{'gli'} && $collectcfg->{'gli'} =~ /^true$/i) {
|
---|
| 481 | $gli = 1;
|
---|
| 482 | }
|
---|
[17142] | 483 | $gli = 0 unless defined $gli;
|
---|
| 484 |
|
---|
[14031] | 485 | # check keepold and removeold
|
---|
[20571] | 486 | ($removeold, $keepold, $incremental, $incremental_mode)
|
---|
| 487 | = &scriptutil::check_removeold_and_keepold($removeold, $keepold,
|
---|
| 488 | $incremental, "archives",
|
---|
| 489 | $collectcfg);
|
---|
[14031] | 490 |
|
---|
| 491 |
|
---|
| 492 | print STDERR "<Import>\n" if $gli;
|
---|
| 493 |
|
---|
| 494 | my $manifest_lookup = new manifest();
|
---|
| 495 | if ($manifest ne "") {
|
---|
| 496 | my $manifest_filename = $manifest;
|
---|
| 497 |
|
---|
| 498 | if ($manifest_filename !~ m/^[\\\/]/) {
|
---|
| 499 | $manifest_filename = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, $manifest_filename);
|
---|
| 500 | }
|
---|
| 501 |
|
---|
| 502 | $manifest =~ s/[\\\/]+/\//g;
|
---|
| 503 | $manifest =~ s/\/$//;
|
---|
| 504 |
|
---|
| 505 | $manifest_lookup->parse($manifest_filename);
|
---|
| 506 | }
|
---|
| 507 |
|
---|
| 508 |
|
---|
| 509 | # load all the plugins
|
---|
[20571] | 510 | $pluginfo = &plugin::load_plugins ($plugins, $verbosity, $out, $faillog, \@global_opts, $incremental_mode);
|
---|
[14031] | 511 | if (scalar(@$pluginfo) == 0) {
|
---|
| 512 | &gsprintf($out, "{import.no_plugins_loaded}\n");
|
---|
| 513 | die "\n";
|
---|
| 514 | }
|
---|
| 515 |
|
---|
| 516 | # remove the old contents of the archives directory (and tmp directory) if needed
|
---|
| 517 | if ($removeold) {
|
---|
| 518 | if (-e $archivedir) {
|
---|
| 519 | &gsprintf($out, "{import.removing_archives}\n");
|
---|
| 520 | &util::rm_r ($archivedir);
|
---|
| 521 | }
|
---|
| 522 | my $tmpdir = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "tmp");
|
---|
| 523 | $tmpdir =~ s/[\\\/]+/\//g;
|
---|
| 524 | $tmpdir =~ s/\/$//;
|
---|
| 525 | if (-e $tmpdir) {
|
---|
| 526 | &gsprintf($out, "{import.removing_tmpdir}\n");
|
---|
| 527 | &util::rm_r ($tmpdir);
|
---|
| 528 | }
|
---|
| 529 | }
|
---|
[21291] | 530 |
|
---|
[14031] | 531 | # create the archives dir if needed
|
---|
| 532 | &util::mk_all_dir($archivedir);
|
---|
| 533 |
|
---|
| 534 | # read the archive information file
|
---|
[18440] | 535 | ## $arcinfo_doc_filename = &util::filename_cat ($archivedir, "archives.inf");
|
---|
| 536 |
|
---|
[21581] | 537 | # BACKWARDS COMPATIBILITY: Just in case there are old .ldb/.bdb files (won't do anything for other infodbtypes)
|
---|
[21664] | 538 | &util::rename_ldb_or_bdb_file(&util::filename_cat($archivedir, "archiveinf-doc"));
|
---|
| 539 | &util::rename_ldb_or_bdb_file(&util::filename_cat($archivedir, "archiveinf-src"));
|
---|
[21581] | 540 |
|
---|
| 541 | $arcinfo_doc_filename = &dbutil::get_infodb_file_path($collectcfg->{'infodbtype'}, "archiveinf-doc", $archivedir);
|
---|
| 542 | $arcinfo_src_filename = &dbutil::get_infodb_file_path($collectcfg->{'infodbtype'}, "archiveinf-src", $archivedir);
|
---|
[18660] | 543 |
|
---|
[21580] | 544 | $archive_info = new arcinfo ($collectcfg->{'infodbtype'});
|
---|
[18440] | 545 | $archive_info->load_info ($arcinfo_doc_filename);
|
---|
[14031] | 546 |
|
---|
[18440] | 547 | if ($manifest eq "") {
|
---|
| 548 | # Load in list of files in import folder from last import (if present)
|
---|
[18456] | 549 | $archive_info->load_prev_import_filelist ($arcinfo_src_filename);
|
---|
[18440] | 550 | }
|
---|
| 551 |
|
---|
[14031] | 552 | ####Use Plugout####
|
---|
[17142] | 553 | my ($plugout);
|
---|
[19657] | 554 | if (defined $collectcfg->{'plugout'}) {
|
---|
| 555 | # If a plugout was specified in the collect.cfg file, assume it is sensible
|
---|
| 556 | # We can't check the name because it could be anything, if it is a custom plugout
|
---|
[17142] | 557 | $plugout = $collectcfg->{'plugout'};
|
---|
| 558 | }
|
---|
| 559 | else{
|
---|
[17751] | 560 | if ($saveas !~ /^(GreenstoneXML|GreenstoneMETS)$/) {
|
---|
| 561 | push @$plugout,"GreenstoneXMLPlugout";
|
---|
[17142] | 562 | }
|
---|
| 563 | else{
|
---|
| 564 | push @$plugout,$saveas."Plugout";
|
---|
| 565 | }
|
---|
| 566 | }
|
---|
| 567 |
|
---|
[14556] | 568 | push @$plugout,("-output_info",$archive_info) if (defined $archive_info);
|
---|
| 569 | push @$plugout,("-verbosity",$verbosity) if (defined $verbosity);
|
---|
| 570 | push @$plugout,("-gzip_output") if ($gzip);
|
---|
| 571 | push @$plugout,("-group_size",$groupsize) if (defined $groupsize);
|
---|
| 572 | push @$plugout,("-output_handle",$out) if (defined $out);
|
---|
| 573 | push @$plugout,("-debug") if ($debug);
|
---|
[14031] | 574 |
|
---|
[14556] | 575 | $processor = &plugout::load_plugout($plugout);
|
---|
[14031] | 576 | $processor->setoutputdir ($archivedir);
|
---|
| 577 | $processor->set_sortmeta ($sortmeta, $removeprefix, $removesuffix) if defined $sortmeta;
|
---|
| 578 | $processor->set_OIDtype ($OIDtype, $OIDmetadata);
|
---|
| 579 |
|
---|
| 580 | &plugin::begin($pluginfo, $importdir, $processor, $maxdocs, $gli);
|
---|
[21291] | 581 |
|
---|
| 582 | if ($removeold) {
|
---|
| 583 | # occasionally, plugins may want to do something on remove old, eg pharos image indexing
|
---|
[21309] | 584 | &plugin::remove_all($pluginfo, $importdir, $processor, $maxdocs, $gli);
|
---|
[21291] | 585 | }
|
---|
[14031] | 586 | if ($manifest eq "") {
|
---|
| 587 | # process the import directory
|
---|
[16377] | 588 | my $block_hash = {};
|
---|
| 589 | my $metadata = {};
|
---|
| 590 | # gobal blocking pass may set up some metadata
|
---|
| 591 | &plugin::file_block_read($pluginfo, $importdir, "", $block_hash, $metadata, $gli);
|
---|
[18440] | 592 |
|
---|
| 593 |
|
---|
[20685] | 594 | if ($incremental || $incremental_mode eq "onlyadd") {
|
---|
[18528] | 595 |
|
---|
| 596 | &inexport::prime_doc_oid_count($archivedir);
|
---|
| 597 |
|
---|
| 598 |
|
---|
[18469] | 599 | # Can now work out which files were new, already existed, and have
|
---|
| 600 | # been deleted
|
---|
| 601 |
|
---|
[20571] | 602 | &inexport::new_vs_old_import_diff($archive_info,$block_hash,$importdir,
|
---|
| 603 | $archivedir,$verbosity,$incremental_mode);
|
---|
[18469] | 604 |
|
---|
| 605 | my @new_files = sort keys %{$block_hash->{'new_files'}};
|
---|
| 606 | if (scalar(@new_files>0)) {
|
---|
[20807] | 607 | print STDERR "New files and modified metadata files since last import:\n ";
|
---|
[18469] | 608 | print STDERR join("\n ",@new_files), "\n";
|
---|
| 609 | }
|
---|
| 610 |
|
---|
[20685] | 611 | if ($incremental) {
|
---|
| 612 | # only look for deletions if we are truely incremental
|
---|
| 613 | my @deleted_files = sort keys %{$block_hash->{'deleted_files'}};
|
---|
| 614 | # Filter out any in gsdl/tmp area
|
---|
| 615 | my @filtered_deleted_files = ();
|
---|
| 616 | my $gsdl_tmp_area = &util::filename_cat($ENV{'GSDLHOME'}, "tmp");
|
---|
| 617 | my $collect_tmp_area = &util::filename_cat($ENV{'GSDLCOLLECTDIR'}, "tmp");
|
---|
| 618 | $gsdl_tmp_area = &util::filename_to_regex($gsdl_tmp_area);
|
---|
| 619 | $collect_tmp_area = &util::filename_to_regex($collect_tmp_area);
|
---|
| 620 |
|
---|
| 621 |
|
---|
| 622 | foreach my $df (@deleted_files) {
|
---|
| 623 | next if ($df =~ m/^$gsdl_tmp_area/);
|
---|
| 624 | next if ($df =~ m/^$collect_tmp_area/);
|
---|
| 625 |
|
---|
| 626 | push(@filtered_deleted_files,$df);
|
---|
| 627 | }
|
---|
| 628 |
|
---|
| 629 |
|
---|
| 630 | @deleted_files = @filtered_deleted_files;
|
---|
| 631 |
|
---|
[21309] | 632 | if (scalar(@deleted_files)>0) {
|
---|
[20685] | 633 | print STDERR "Files deleted since last import:\n ";
|
---|
| 634 | print STDERR join("\n ",@deleted_files), "\n";
|
---|
| 635 |
|
---|
| 636 |
|
---|
[21618] | 637 | &plugin::remove_some($pluginfo, $collectcfg->{'infodbtype'}, $archivedir, \@deleted_files);
|
---|
[21309] | 638 |
|
---|
| 639 | &inexport::mark_docs_for_deletion($archive_info,$block_hash,\@deleted_files, $archivedir,$verbosity, "delete");
|
---|
| 640 | }
|
---|
[20685] | 641 |
|
---|
| 642 | my @reindex_files = sort keys %{$block_hash->{'reindex_files'}};
|
---|
| 643 |
|
---|
[21309] | 644 | if (scalar(@reindex_files)>0) {
|
---|
[20685] | 645 | print STDERR "Files to reindex since last import:\n ";
|
---|
| 646 | print STDERR join("\n ",@reindex_files), "\n";
|
---|
[21618] | 647 | &plugin::remove_some($pluginfo, $collectcfg->{'infodbtype'}, $archivedir, \@reindex_files);
|
---|
[21309] | 648 | &inexport::mark_docs_for_deletion($archive_info,$block_hash,\@reindex_files, $archivedir,$verbosity, "reindex");
|
---|
[20685] | 649 | }
|
---|
[21309] | 650 |
|
---|
[20685] | 651 | }
|
---|
| 652 |
|
---|
[19500] | 653 | # Play it safe, and run through the entire folder, only processing new or edited files
|
---|
| 654 | &plugin::read ($pluginfo, $importdir, "", $block_hash, $metadata, $processor, $maxdocs, 0, $gli);
|
---|
| 655 |
|
---|
[18440] | 656 | }
|
---|
[19500] | 657 | else {
|
---|
| 658 | &plugin::read ($pluginfo, $importdir, "", $block_hash, $metadata, $processor, $maxdocs, 0, $gli);
|
---|
| 659 | }
|
---|
[18440] | 660 |
|
---|
[14031] | 661 | }
|
---|
[18507] | 662 | else
|
---|
[16255] | 663 | {
|
---|
| 664 | # process any files marked for importing
|
---|
[19303] | 665 | foreach my $file (keys %{$manifest_lookup->{'import'}}) {
|
---|
[16377] | 666 | &plugin::read ($pluginfo, $importdir, $file, {}, {}, $processor, $maxdocs, 0, $gli);
|
---|
[14031] | 667 | }
|
---|
| 668 |
|
---|
[18456] | 669 | my @deleted_files = keys %{$manifest_lookup->{'delete'}};
|
---|
[18440] | 670 |
|
---|
[19500] | 671 | &inexport::mark_docs_for_deletion($archive_info,{},\@deleted_files,$archivedir);
|
---|
[14031] | 672 | }
|
---|
| 673 |
|
---|
| 674 | &plugin::end($pluginfo, $processor);
|
---|
| 675 |
|
---|
| 676 | &plugin::deinit($pluginfo, $processor);
|
---|
| 677 |
|
---|
[18528] | 678 | # Store the value of OIDCount (used in doc.pm) so it can be
|
---|
| 679 | # restored correctly to this value on an incremental build
|
---|
| 680 | &inexport::store_doc_oid_count($archivedir);
|
---|
| 681 |
|
---|
[14031] | 682 | # write out the archive information file
|
---|
| 683 | $processor->close_file_output() if $groupsize > 1;
|
---|
| 684 | $processor->close_group_output() if $processor->is_group();
|
---|
[14957] | 685 |
|
---|
| 686 | # The following 'if' statement is in the export.pl version of the script,
|
---|
[18440] | 687 | # The reason for the 'if' statement is now given in export.pl
|
---|
| 688 | # Unclear at this point if the same should be done here
|
---|
| 689 | ## if (($saveas =~ m/^.*METS$/) || ($saveas eq "MARC")) {
|
---|
| 690 | # Not all export types need this (e.g. DSpace)
|
---|
| 691 |
|
---|
[14957] | 692 | # should we still do this in debug mode??
|
---|
| 693 |
|
---|
[18440] | 694 | # for backwards compatability with archvies.inf file
|
---|
[20571] | 695 | if ($arcinfo_doc_filename =~ m/(contents)|(\.inf)$/) {
|
---|
[18440] | 696 | $archive_info->save_info($arcinfo_doc_filename);
|
---|
| 697 | }
|
---|
[19775] | 698 | else {
|
---|
[21564] | 699 | $archive_info->save_revinfo_db($arcinfo_src_filename);
|
---|
[19775] | 700 | }
|
---|
[18440] | 701 |
|
---|
[19775] | 702 |
|
---|
[14957] | 703 | ## }
|
---|
[14031] | 704 |
|
---|
| 705 | # write out import stats
|
---|
| 706 | my $close_stats = 0;
|
---|
| 707 | if ($statsfile !~ /^(STDERR|STDOUT)$/i) {
|
---|
| 708 | if (open (STATS, ">$statsfile")) {
|
---|
| 709 | $statsfile = 'import::STATS';
|
---|
| 710 | $close_stats = 1;
|
---|
| 711 | } else {
|
---|
| 712 | &gsprintf($out, "{import.cannot_open_stats_file}", $statsfile);
|
---|
| 713 | &gsprintf($out, "{import.stats_backup}\n");
|
---|
| 714 | $statsfile = 'STDERR';
|
---|
| 715 | }
|
---|
| 716 | }
|
---|
| 717 |
|
---|
| 718 | &gsprintf($out, "\n");
|
---|
| 719 | &gsprintf($out, "*********************************************\n");
|
---|
| 720 | &gsprintf($out, "{import.complete}\n");
|
---|
| 721 | &gsprintf($out, "*********************************************\n");
|
---|
| 722 |
|
---|
| 723 | &plugin::write_stats($pluginfo, $statsfile, $faillogname, $gli);
|
---|
| 724 | if ($close_stats) {
|
---|
| 725 | close STATS;
|
---|
| 726 | }
|
---|
| 727 |
|
---|
| 728 | close OUT if $close_out;
|
---|
| 729 | close FAILLOG;
|
---|
| 730 | }
|
---|