[1031] | 1 | #!/usr/bin/perl -w
|
---|
[4] | 2 |
|
---|
[538] | 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 |
|
---|
[4] | 29 | # This program will import a number of files into a particular collection
|
---|
| 30 |
|
---|
[1424] | 31 | package import;
|
---|
| 32 |
|
---|
[4] | 33 | BEGIN {
|
---|
| 34 | die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
|
---|
| 35 | die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};
|
---|
[9] | 36 | unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
|
---|
[5882] | 37 | unshift (@INC, "$ENV{'GSDLHOME'}/perllib/cpan");
|
---|
[9] | 38 | unshift (@INC, "$ENV{'GSDLHOME'}/perllib/plugins");
|
---|
[946] | 39 | unshift (@INC, "$ENV{'GSDLHOME'}/perllib/classify");
|
---|
[4] | 40 | }
|
---|
| 41 |
|
---|
| 42 | use arcinfo;
|
---|
| 43 | use colcfg;
|
---|
| 44 | use plugin;
|
---|
[783] | 45 | use docprint;
|
---|
[130] | 46 | use util;
|
---|
[10417] | 47 | use scriptutil;
|
---|
[1424] | 48 | use FileHandle;
|
---|
[9970] | 49 | use gsprintf 'gsprintf';
|
---|
[4776] | 50 | use printusage;
|
---|
[10215] | 51 | use parse2;
|
---|
[4] | 52 |
|
---|
[10255] | 53 | use strict;
|
---|
| 54 | no strict 'refs'; # allow filehandles to be variables and vice versa
|
---|
| 55 | no strict 'subs'; # allow barewords (eg STDERR) as function arguments
|
---|
| 56 |
|
---|
[4776] | 57 | my $oidtype_list =
|
---|
| 58 | [ { 'name' => "hash",
|
---|
[4873] | 59 | 'desc' => "{import.OIDtype.hash}" },
|
---|
[4776] | 60 | { 'name' => "incremental",
|
---|
[8796] | 61 | 'desc' => "{import.OIDtype.incremental}" },
|
---|
| 62 | { 'name' => "assigned",
|
---|
| 63 | 'desc' => "{import.OIDtype.assigned}" },
|
---|
| 64 | { 'name' => "dirname",
|
---|
| 65 | 'desc' => "{import.OIDtype.dirname}" } ];
|
---|
[4776] | 66 |
|
---|
[7906] | 67 | #** define to use the original GA format or METS format
|
---|
| 68 | my $saveas_list =
|
---|
| 69 | [ { 'name' => "GA",
|
---|
| 70 | 'desc' => "{import.saveas.GA}" },
|
---|
| 71 | { 'name' => "METS",
|
---|
| 72 | 'desc' => "{import.saveas.METS}" } ];
|
---|
| 73 |
|
---|
| 74 |
|
---|
[6407] | 75 | # Possible attributes for each argument
|
---|
| 76 | # name: The name of the argument
|
---|
| 77 | # desc: A description (or more likely a reference to a description) for this argument
|
---|
| 78 | # type: The type of control used to represent the argument. Options include: string, int, flag, regexp, metadata, metadatum, language, enum etc
|
---|
| 79 | # reqd: Is this argument required?
|
---|
| 80 | # hiddengli: Is this argument hidden in GLI?
|
---|
| 81 | # modegli: The lowest detail mode this argument is visible at in GLI
|
---|
| 82 |
|
---|
[4776] | 83 | my $arguments =
|
---|
| 84 | [ { 'name' => "archivedir",
|
---|
[6921] | 85 | 'desc' => "{import.archivedir}",
|
---|
[4776] | 86 | 'type' => "string",
|
---|
[6407] | 87 | 'reqd' => "no",
|
---|
| 88 | 'hiddengli' => "yes" },
|
---|
[4776] | 89 | { 'name' => "collectdir",
|
---|
[4873] | 90 | 'desc' => "{import.collectdir}",
|
---|
[4776] | 91 | 'type' => "string",
|
---|
[10215] | 92 | # parsearg left "" as default
|
---|
| 93 | #'deft' => &util::filename_cat ($ENV{'GSDLHOME'}, "collect"),
|
---|
| 94 | 'deft' => "",
|
---|
[6407] | 95 | 'reqd' => "no",
|
---|
| 96 | 'hiddengli' => "yes" },
|
---|
[4776] | 97 | { 'name' => "debug",
|
---|
[4873] | 98 | 'desc' => "{import.debug}",
|
---|
[4776] | 99 | 'type' => "flag",
|
---|
[6407] | 100 | 'reqd' => "no",
|
---|
| 101 | 'hiddengli' => "yes" },
|
---|
[4776] | 102 | { 'name' => "faillog",
|
---|
[4873] | 103 | 'desc' => "{import.faillog}",
|
---|
[4776] | 104 | 'type' => "string",
|
---|
[10215] | 105 | # parsearg left "" as default
|
---|
| 106 | #'deft' => &util::filename_cat("<collectdir>", "colname", "etc", "fail.log"),
|
---|
| 107 | 'deft' => "",
|
---|
[6407] | 108 | 'reqd' => "no",
|
---|
| 109 | 'modegli' => "4" },
|
---|
[4776] | 110 | { 'name' => "groupsize",
|
---|
[4873] | 111 | 'desc' => "{import.groupsize}",
|
---|
[4776] | 112 | 'type' => "int",
|
---|
| 113 | 'deft' => "1",
|
---|
[6407] | 114 | 'reqd' => "no",
|
---|
| 115 | 'modegli' => "3" },
|
---|
[4776] | 116 | { 'name' => "gzip",
|
---|
[4873] | 117 | 'desc' => "{import.gzip}",
|
---|
[4776] | 118 | 'type' => "flag",
|
---|
[6407] | 119 | 'reqd' => "no",
|
---|
| 120 | 'modegli' => "4" },
|
---|
[4776] | 121 | { 'name' => "importdir",
|
---|
[4873] | 122 | 'desc' => "{import.importdir}",
|
---|
[4776] | 123 | 'type' => "string",
|
---|
[6407] | 124 | 'reqd' => "no",
|
---|
| 125 | 'hiddengli' => "yes" },
|
---|
[4776] | 126 | { 'name' => "keepold",
|
---|
[4873] | 127 | 'desc' => "{import.keepold}",
|
---|
[4776] | 128 | 'type' => "flag",
|
---|
[6407] | 129 | 'reqd' => "no",
|
---|
[10459] | 130 | 'modegli' => "3" },
|
---|
[10417] | 131 | { 'name' => "removeold",
|
---|
| 132 | 'desc' => "{import.removeold}",
|
---|
| 133 | 'type' => "flag",
|
---|
| 134 | 'reqd' => "no",
|
---|
| 135 | 'modegli' => "3" },
|
---|
[6407] | 136 | { 'name' => "language",
|
---|
| 137 | 'desc' => "{scripts.language}",
|
---|
| 138 | 'type' => "string",
|
---|
| 139 | 'reqd' => "no",
|
---|
| 140 | 'modegli' => "4" },
|
---|
[4776] | 141 | { 'name' => "maxdocs",
|
---|
[4873] | 142 | 'desc' => "{import.maxdocs}",
|
---|
[4776] | 143 | 'type' => "int",
|
---|
[6407] | 144 | 'reqd' => "no",
|
---|
[10215] | 145 | # parsearg left "" as default
|
---|
| 146 | #'deft' => "-1",
|
---|
[7063] | 147 | 'range' => "1,",
|
---|
[6407] | 148 | 'modegli' => "1" },
|
---|
[4776] | 149 | { 'name' => "OIDtype",
|
---|
[4873] | 150 | 'desc' => "{import.OIDtype}",
|
---|
[4776] | 151 | 'type' => "enum",
|
---|
| 152 | 'list' => $oidtype_list,
|
---|
[10215] | 153 | # parsearg left "" as default
|
---|
| 154 | #'deft' => "hash",
|
---|
[6407] | 155 | 'reqd' => "no",
|
---|
| 156 | 'modegli' => "3" },
|
---|
[4776] | 157 | { 'name' => "out",
|
---|
[4873] | 158 | 'desc' => "{import.out}",
|
---|
[4776] | 159 | 'type' => "string",
|
---|
| 160 | 'deft' => "STDERR",
|
---|
[6407] | 161 | 'reqd' => "no",
|
---|
| 162 | 'hiddengli' => "yes" },
|
---|
[7906] | 163 | { 'name' => "saveas",
|
---|
| 164 | 'desc' => "{import.saveas}",
|
---|
| 165 | 'type' => "enum",
|
---|
| 166 | 'list' => $saveas_list,
|
---|
| 167 | 'deft' => "GA",
|
---|
| 168 | 'reqd' => "no",
|
---|
| 169 | 'modegli' => "3" },
|
---|
[4776] | 170 | { 'name' => "sortmeta",
|
---|
[4873] | 171 | 'desc' => "{import.sortmeta}",
|
---|
[10215] | 172 | # 'type' => "metadatum",
|
---|
| 173 | 'type' => "string",
|
---|
[6407] | 174 | 'reqd' => "no",
|
---|
[8153] | 175 | 'modegli' => "3" },
|
---|
[8855] | 176 | { 'name' => "removeprefix",
|
---|
| 177 | 'desc' => "{BasClas.removeprefix}",
|
---|
[9066] | 178 | 'type' => "regexp",
|
---|
[8855] | 179 | 'deft' => "",
|
---|
[9066] | 180 | 'reqd' => "no",
|
---|
| 181 | 'modegli' => "3" },
|
---|
[8855] | 182 | { 'name' => "removesuffix",
|
---|
| 183 | 'desc' => "{BasClas.removesuffix}",
|
---|
[9066] | 184 | 'type' => "regexp",
|
---|
[8855] | 185 | 'deft' => "",
|
---|
[9066] | 186 | 'reqd' => "no",
|
---|
| 187 | 'modegli' => "3" },
|
---|
[4776] | 188 | { 'name' => "statsfile",
|
---|
[4873] | 189 | 'desc' => "{import.statsfile}",
|
---|
[4776] | 190 | 'type' => "string",
|
---|
| 191 | 'deft' => "STDERR",
|
---|
[6407] | 192 | 'reqd' => "no",
|
---|
| 193 | 'hiddengli' => "yes" },
|
---|
[4776] | 194 | { 'name' => "verbosity",
|
---|
[4873] | 195 | 'desc' => "{import.verbosity}",
|
---|
[4776] | 196 | 'type' => "int",
|
---|
[10215] | 197 | 'range' => "0,",
|
---|
| 198 | # parsearg left "" as default
|
---|
| 199 | #'deft' => "2",
|
---|
[6407] | 200 | 'reqd' => "no",
|
---|
[10215] | 201 | 'modegli' => "4" },
|
---|
| 202 | { 'name' => "gli",
|
---|
| 203 | 'desc' => "",
|
---|
| 204 | 'type' => "flag",
|
---|
| 205 | 'reqd' => "no",
|
---|
| 206 | 'hiddengli' => "yes" },
|
---|
| 207 | { 'name' => "xml",
|
---|
[10349] | 208 | 'desc' => "{scripts.xml}",
|
---|
[10215] | 209 | 'type' => "flag",
|
---|
| 210 | 'reqd' => "no",
|
---|
| 211 | 'hiddengli' => "yes" }];
|
---|
[4776] | 212 |
|
---|
| 213 | my $options = { 'name' => "import.pl",
|
---|
[5093] | 214 | 'desc' => "{import.desc}",
|
---|
[4776] | 215 | 'args' => $arguments };
|
---|
| 216 |
|
---|
[4] | 217 |
|
---|
[1424] | 218 | &main();
|
---|
[4] | 219 |
|
---|
| 220 | sub main {
|
---|
[783] | 221 | my ($verbosity, $importdir, $archivedir, $keepold,
|
---|
[9951] | 222 | $removeold, $saveas, $version,
|
---|
| 223 | $gzip, $groupsize, $OIDtype, $debug,
|
---|
[2328] | 224 | $maxdocs, $collection, $configfilename, $collectcfg,
|
---|
[8855] | 225 | $pluginfo, $sortmeta, $removeprefix, $removesuffix,
|
---|
| 226 | $archive_info_filename, $statsfile,
|
---|
[10255] | 227 | $archive_info, $processor, $out, $faillog, $collectdir, $gli, $language);
|
---|
[2355] | 228 |
|
---|
[4776] | 229 | my $xml = 0;
|
---|
[10215] | 230 |
|
---|
[8603] | 231 | my $service = "import";
|
---|
[4776] | 232 |
|
---|
[10215] | 233 | my $hashParsingResult = {};
|
---|
| 234 | my $blnParseFailed = "false";
|
---|
| 235 | # general options available to all plugins
|
---|
[10255] | 236 | my $intArgLeftinAfterParsing = parse2::parse(\@ARGV,$arguments,$hashParsingResult,"allow_extra_options");
|
---|
[10337] | 237 | # If there is more than one argument left after parsing, it mean user input too many arguments.
|
---|
| 238 | if($intArgLeftinAfterParsing > 1)
|
---|
[10215] | 239 | {
|
---|
[6926] | 240 | &PrintUsage::print_txt_usage($options, "{import.params}");
|
---|
[4] | 241 | die "\n";
|
---|
| 242 | }
|
---|
[10255] | 243 |
|
---|
[10215] | 244 | foreach my $strVariable (keys %$hashParsingResult)
|
---|
| 245 | {
|
---|
| 246 | eval "\$$strVariable = \$hashParsingResult->{\"\$strVariable\"}";
|
---|
| 247 | }
|
---|
[8855] | 248 |
|
---|
[6945] | 249 | # If $language has been specified, load the appropriate resource bundle
|
---|
| 250 | # (Otherwise, the default resource bundle will be loaded automatically)
|
---|
[10255] | 251 | if ($language && $language =~ /\S/) {
|
---|
[6945] | 252 | &gsprintf::load_language_specific_resource_bundle($language);
|
---|
| 253 | }
|
---|
[6926] | 254 |
|
---|
[4776] | 255 | if ($xml) {
|
---|
[6926] | 256 | &PrintUsage::print_xml_usage($options);
|
---|
[7950] | 257 | print "\n";
|
---|
| 258 | return;
|
---|
[4776] | 259 | }
|
---|
| 260 |
|
---|
[7101] | 261 | if ($gli) { # the gli wants strings to be in UTF-8
|
---|
| 262 | &gsprintf::output_strings_in_UTF8;
|
---|
| 263 | }
|
---|
[8603] | 264 |
|
---|
[1424] | 265 | my $close_out = 0;
|
---|
| 266 | if ($out !~ /^(STDERR|STDOUT)$/i) {
|
---|
[5093] | 267 | open (OUT, ">$out") ||
|
---|
[6921] | 268 | (&gsprintf(STDERR, "{common.cannot_open_output_file}\n", $out) && die);
|
---|
[1424] | 269 | $out = 'import::OUT';
|
---|
| 270 | $close_out = 1;
|
---|
| 271 | }
|
---|
| 272 | $out->autoflush(1);
|
---|
| 273 |
|
---|
[130] | 274 | # get and check the collection name
|
---|
[2287] | 275 | if (($collection = &util::use_collection(@ARGV, $collectdir)) eq "") {
|
---|
[6926] | 276 | &PrintUsage::print_txt_usage($options, "{import.params}");
|
---|
[4] | 277 | die "\n";
|
---|
| 278 | }
|
---|
[2785] | 279 |
|
---|
| 280 | if ($faillog eq "") {
|
---|
| 281 | $faillog = &util::filename_cat($ENV{'GSDLCOLLECTDIR'}, "etc", "fail.log");
|
---|
[2755] | 282 | }
|
---|
[5093] | 283 | open (FAILLOG, ">$faillog") ||
|
---|
[6921] | 284 | (&gsprintf(STDERR, "{import.cannot_open_fail_log}\n", $faillog) && die);
|
---|
[8603] | 285 |
|
---|
[10215] | 286 |
|
---|
[3402] | 287 | my $faillogname = $faillog;
|
---|
[2785] | 288 | $faillog = 'import::FAILLOG';
|
---|
| 289 | $faillog->autoflush(1);
|
---|
[130] | 290 |
|
---|
[1287] | 291 | # check sortmeta
|
---|
| 292 | $sortmeta = undef unless defined $sortmeta && $sortmeta =~ /\S/;
|
---|
| 293 | if (defined $sortmeta && $groupsize > 1) {
|
---|
[6921] | 294 | &gsprintf($out, "{import.cannot_sort}\n\n");
|
---|
[1287] | 295 | $sortmeta = undef;
|
---|
| 296 | }
|
---|
[843] | 297 | # dynamically load 'docsave' module so it can pick up on a collection
|
---|
| 298 | # specific docsave.pm is specified.
|
---|
| 299 |
|
---|
| 300 | unshift (@INC, "$ENV{'GSDLCOLLECTDIR'}/perllib");
|
---|
| 301 | require docsave;
|
---|
| 302 |
|
---|
[2355] | 303 | # get the list of plugins for this collection and set any options that
|
---|
| 304 | # were specified in the collect.cfg (all import.pl options except
|
---|
[2755] | 305 | # -collectdir, -out and -faillog may be specified in the collect.cfg (these
|
---|
[2355] | 306 | # options must be known before we read the collect.cfg))
|
---|
[814] | 307 | my $plugins = [];
|
---|
[6584] | 308 | my @global_opts = ();
|
---|
| 309 |
|
---|
[2287] | 310 | $configfilename = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "etc", "collect.cfg");
|
---|
[10417] | 311 | if (!-e $configfilename) {
|
---|
| 312 | (&gsprintf($out, "{common.cannot_find_cfg_file}\n", $configfilename) && die);
|
---|
| 313 | }
|
---|
| 314 |
|
---|
| 315 | $collectcfg = &colcfg::read_collect_cfg ($configfilename);
|
---|
| 316 | if (defined $collectcfg->{'plugin'}) {
|
---|
| 317 | $plugins = $collectcfg->{'plugin'};
|
---|
| 318 | }
|
---|
[2355] | 319 |
|
---|
[10417] | 320 | if ($verbosity !~ /\d+/) {
|
---|
| 321 | if (defined $collectcfg->{'verbosity'} && $collectcfg->{'verbosity'} =~ /\d+/) {
|
---|
| 322 | $verbosity = $collectcfg->{'verbosity'};
|
---|
| 323 | } else {
|
---|
| 324 | $verbosity = 2; # the default
|
---|
[2355] | 325 | }
|
---|
[10417] | 326 | }
|
---|
| 327 | if (defined $collectcfg->{'importdir'} && $importdir eq "") {
|
---|
| 328 | $importdir = $collectcfg->{'importdir'};
|
---|
| 329 | }
|
---|
| 330 | if (defined $collectcfg->{'archivedir'} && $archivedir eq "") {
|
---|
| 331 | $archivedir = $collectcfg->{'archivedir'};
|
---|
| 332 | }
|
---|
[8603] | 333 |
|
---|
[10417] | 334 | if (defined $collectcfg->{'gzip'} && !$gzip) {
|
---|
| 335 | if ($collectcfg->{'gzip'} =~ /^true$/i) {
|
---|
| 336 | $gzip = 1;
|
---|
[9546] | 337 | }
|
---|
[10417] | 338 | }
|
---|
| 339 | if ($maxdocs !~ /\-?\d+/) {
|
---|
| 340 | if (defined $collectcfg->{'maxdocs'} && $collectcfg->{'maxdocs'} =~ /\-?\d+/) {
|
---|
| 341 | $maxdocs = $collectcfg->{'maxdocs'};
|
---|
| 342 | } else {
|
---|
| 343 | $maxdocs = -1; # the default
|
---|
[9546] | 344 | }
|
---|
[10417] | 345 | }
|
---|
| 346 | if ($groupsize == 1) {
|
---|
| 347 | if (defined $collectcfg->{'groupsize'} && $collectcfg->{'groupsize'} =~ /\d+/) {
|
---|
| 348 | $groupsize = $collectcfg->{'groupsize'};
|
---|
[2355] | 349 | }
|
---|
[10417] | 350 | }
|
---|
| 351 | if ($OIDtype !~ /^(hash|incremental|assigned|dirname)$/) {
|
---|
| 352 | if (defined $collectcfg->{'OIDtype'} && $collectcfg->{'OIDtype'} =~ /^(hash|incremental|assigned|dirname)$/) {
|
---|
| 353 | $OIDtype = $collectcfg->{'OIDtype'};
|
---|
| 354 | } else {
|
---|
| 355 | $OIDtype = "hash"; # the default
|
---|
[6330] | 356 | }
|
---|
[10417] | 357 | }
|
---|
| 358 | if ($saveas !~ /^(GA|METS)$/) {
|
---|
| 359 | if (defined $collectcfg->{'saveas'} && $collectcfg->{'saveas'} =~ /^(GA|METS)$/) {
|
---|
| 360 | $saveas = $collectcfg->{'saveas'};
|
---|
| 361 | } else {
|
---|
| 362 | $saveas ="GA";
|
---|
[6584] | 363 | }
|
---|
[4] | 364 | }
|
---|
[10417] | 365 | if (defined $collectcfg->{'sortmeta'} && (!defined $sortmeta || $sortmeta eq "")) {
|
---|
| 366 | $sortmeta = $collectcfg->{'sortmeta'};
|
---|
| 367 | }
|
---|
| 368 |
|
---|
| 369 | if (defined $collectcfg->{'removeprefix'} && $removeprefix eq "") {
|
---|
| 370 | $removeprefix = $collectcfg->{'removeprefix'};
|
---|
| 371 | }
|
---|
| 372 |
|
---|
| 373 | if (defined $collectcfg->{'removesuffix'} && $removesuffix eq "") {
|
---|
| 374 | $removesuffix = $collectcfg->{'removesuffix'};
|
---|
| 375 | }
|
---|
| 376 | if (defined $collectcfg->{'debug'} && $collectcfg->{'debug'} =~ /^true$/i) {
|
---|
| 377 | $debug = 1;
|
---|
| 378 | }
|
---|
| 379 | if (defined $collectcfg->{'gli'} && $collectcfg->{'gli'} =~ /^true$/i) {
|
---|
| 380 | $gli = 1;
|
---|
| 381 | }
|
---|
| 382 |
|
---|
| 383 |
|
---|
| 384 | # global plugin stuff
|
---|
| 385 | if (defined $collectcfg->{'separate_cjk'} && $collectcfg->{'separate_cjk'} =~ /^true$/i) {
|
---|
| 386 | push @global_opts, "-separate_cjk";
|
---|
| 387 | }
|
---|
| 388 |
|
---|
| 389 | # check keepold and removeold
|
---|
| 390 | ($removeold, $keepold) = &scriptutil::check_removeold_and_keepold($removeold, $keepold, "archives", $collectcfg);
|
---|
| 391 |
|
---|
[6330] | 392 | $gli = 0 unless defined $gli;
|
---|
| 393 |
|
---|
| 394 | print STDERR "<Import>\n" if $gli;
|
---|
[4] | 395 |
|
---|
[130] | 396 | # fill in the default import and archives directories if none
|
---|
| 397 | # were supplied, turn all \ into / and remove trailing /
|
---|
[2287] | 398 | $importdir = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "import") if $importdir eq "";
|
---|
[130] | 399 | $importdir =~ s/[\\\/]+/\//g;
|
---|
| 400 | $importdir =~ s/\/$//;
|
---|
[2287] | 401 | $archivedir = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "archives") if $archivedir eq "";
|
---|
[130] | 402 | $archivedir =~ s/[\\\/]+/\//g;
|
---|
| 403 | $archivedir =~ s/\/$//;
|
---|
[4] | 404 |
|
---|
| 405 | # load all the plugins
|
---|
[6584] | 406 | $pluginfo = &plugin::load_plugins ($plugins, $verbosity, $out, $faillog, \@global_opts);
|
---|
[4] | 407 | if (scalar(@$pluginfo) == 0) {
|
---|
[6921] | 408 | &gsprintf($out, "{import.no_plugins_loaded}\n");
|
---|
[4] | 409 | die "\n";
|
---|
| 410 | }
|
---|
[5093] | 411 |
|
---|
[10463] | 412 | # remove the old contents of the archives directory (and tmp directory) if needed
|
---|
| 413 | if ($removeold) {
|
---|
| 414 | if (-e $archivedir) {
|
---|
| 415 | &gsprintf($out, "{import.removing_archives}\n");
|
---|
| 416 | &util::rm_r ($archivedir);
|
---|
| 417 | }
|
---|
[10481] | 418 | my $tmpdir = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "tmp");
|
---|
[10463] | 419 | $tmpdir =~ s/[\\\/]+/\//g;
|
---|
| 420 | $tmpdir =~ s/\/$//;
|
---|
| 421 | if (-e $tmpdir) {
|
---|
| 422 | &gsprintf($out, "{import.removing_tmpdir}\n");
|
---|
| 423 | &util::rm_r ($tmpdir);
|
---|
| 424 | }
|
---|
[130] | 425 | }
|
---|
[6921] | 426 |
|
---|
[4] | 427 | # read the archive information file
|
---|
[783] | 428 | if (!$debug) {
|
---|
| 429 | $archive_info_filename = &util::filename_cat ($archivedir, "archives.inf");
|
---|
| 430 | $archive_info = new arcinfo ();
|
---|
| 431 | $archive_info->load_info ($archive_info_filename);
|
---|
[4] | 432 |
|
---|
[783] | 433 | # create a docsave object to process the documents
|
---|
[8603] | 434 | $processor = new docsave ($collection, $archive_info, $verbosity, $gzip, $groupsize, $out, $service, $saveas);
|
---|
[10162] | 435 | $processor->setoutputdir ($archivedir);
|
---|
[8855] | 436 | $processor->set_sortmeta ($sortmeta, $removeprefix, $removesuffix) if defined $sortmeta;
|
---|
[2328] | 437 | $processor->set_OIDtype ($OIDtype);
|
---|
[7906] | 438 | $processor->set_saveas ($saveas);
|
---|
[11735] | 439 | $processor->set_saveas_version ("greenstone");
|
---|
[9951] | 440 |
|
---|
[783] | 441 | } else {
|
---|
| 442 | $processor = new docprint ();
|
---|
| 443 | }
|
---|
[4] | 444 |
|
---|
[11333] | 445 | &plugin::begin($pluginfo, $importdir, $processor, $maxdocs, $gli);
|
---|
[843] | 446 |
|
---|
[4] | 447 | # process the import directory
|
---|
[9854] | 448 | &plugin::read ($pluginfo, $importdir, "", {}, $processor, $maxdocs, 0, $gli);
|
---|
[4] | 449 |
|
---|
[2287] | 450 | &plugin::end($pluginfo, $processor);
|
---|
[2785] | 451 |
|
---|
[10162] | 452 | &plugin::deinit($pluginfo, $processor);
|
---|
| 453 |
|
---|
[4] | 454 | # write out the archive information file
|
---|
[783] | 455 | if (!$debug) {
|
---|
[1287] | 456 | $processor->close_file_output() if $groupsize > 1;
|
---|
[783] | 457 | $archive_info->save_info($archive_info_filename);
|
---|
| 458 | }
|
---|
[2785] | 459 |
|
---|
| 460 | # write out import stats
|
---|
| 461 | my $close_stats = 0;
|
---|
| 462 | if ($statsfile !~ /^(STDERR|STDOUT)$/i) {
|
---|
| 463 | if (open (STATS, ">$statsfile")) {
|
---|
| 464 | $statsfile = 'import::STATS';
|
---|
| 465 | $close_stats = 1;
|
---|
| 466 | } else {
|
---|
[6921] | 467 | &gsprintf($out, "{import.cannot_open_stats_file}", $statsfile);
|
---|
| 468 | &gsprintf($out, "{import.stats_backup}\n");
|
---|
[2785] | 469 | $statsfile = 'STDERR';
|
---|
| 470 | }
|
---|
| 471 | }
|
---|
| 472 |
|
---|
[6921] | 473 | &gsprintf($out, "\n");
|
---|
| 474 | &gsprintf($out, "*********************************************\n");
|
---|
| 475 | &gsprintf($out, "{import.complete}\n");
|
---|
| 476 | &gsprintf($out, "*********************************************\n");
|
---|
[2785] | 477 |
|
---|
[6330] | 478 | &plugin::write_stats($pluginfo, $statsfile, $faillogname, $gli);
|
---|
[2785] | 479 | if ($close_stats) {
|
---|
| 480 | close STATS;
|
---|
| 481 | }
|
---|
| 482 |
|
---|
[1424] | 483 | close OUT if $close_out;
|
---|
[2785] | 484 | close FAILLOG;
|
---|
[4] | 485 | }
|
---|