[8879] | 1 | #!/usr/bin/perl -w
|
---|
| 2 |
|
---|
| 3 | ###########################################################################
|
---|
| 4 | #
|
---|
| 5 | # export.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 export a particular collection into a specific Format (e.g. METS or DSpace)
|
---|
| 30 | # Author: Chi-Yu Huang Date: 08-10-2004
|
---|
| 31 |
|
---|
| 32 | package export;
|
---|
| 33 |
|
---|
| 34 | BEGIN {
|
---|
| 35 | die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
|
---|
| 36 | die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};
|
---|
| 37 | unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
|
---|
| 38 | unshift (@INC, "$ENV{'GSDLHOME'}/perllib/cpan");
|
---|
| 39 | unshift (@INC, "$ENV{'GSDLHOME'}/perllib/plugins");
|
---|
[12333] | 40 | unshift (@INC, "$ENV{'GSDLHOME'}/perllib/plugouts");
|
---|
[8879] | 41 | unshift (@INC, "$ENV{'GSDLHOME'}/perllib/classify");
|
---|
| 42 | }
|
---|
| 43 |
|
---|
[10340] | 44 | use strict;
|
---|
| 45 | no strict 'refs'; # allow filehandles to be variables and vice versa
|
---|
| 46 | no strict 'subs'; # allow barewords (eg STDERR) as function arguments
|
---|
| 47 |
|
---|
[10162] | 48 | use arcinfo;
|
---|
[8879] | 49 | use colcfg;
|
---|
| 50 | use plugin;
|
---|
[12333] | 51 | use plugout;
|
---|
[8879] | 52 | use util;
|
---|
[10417] | 53 | use scriptutil;
|
---|
[8879] | 54 | use FileHandle;
|
---|
| 55 | use gsprintf;
|
---|
| 56 | use printusage;
|
---|
[10340] | 57 | use parse2;
|
---|
[8879] | 58 |
|
---|
[10340] | 59 |
|
---|
[8879] | 60 | my $oidtype_list =
|
---|
| 61 | [ { 'name' => "hash",
|
---|
[12691] | 62 | 'desc' => "{import.OIDtype.hash}" },
|
---|
[8879] | 63 | { 'name' => "incremental",
|
---|
[12691] | 64 | 'desc' => "{import.OIDtype.incremental}" },
|
---|
| 65 | { 'name' => "assigned",
|
---|
| 66 | 'desc' => "{import.OIDtype.assigned}" },
|
---|
| 67 | { 'name' => "dirname",
|
---|
| 68 | 'desc' => "{import.OIDtype.dirname}" } ];
|
---|
[8879] | 69 |
|
---|
| 70 | #** define to use the METS format or DSpace format
|
---|
| 71 | my $saveas_list =
|
---|
| 72 | [ { 'name' => "DSpace",
|
---|
| 73 | 'desc' => "{export.saveas.DSpace}" },
|
---|
| 74 | { 'name' => "METS",
|
---|
[12333] | 75 | 'desc' => "{export.saveas.METS}"},
|
---|
| 76 | { 'name' => "GA",
|
---|
| 77 | 'desc' => "{export.saveas.GA}"},
|
---|
| 78 | { 'name' => "MARCXML",
|
---|
| 79 | 'desc' => "{export.saveas.MARCXML}"}
|
---|
| 80 | ];
|
---|
[8879] | 81 |
|
---|
| 82 |
|
---|
| 83 | # Possible attributes for each argument
|
---|
| 84 | # name: The name of the argument
|
---|
| 85 | # desc: A description (or more likely a reference to a description) for this argument
|
---|
[12361] | 86 | # type: The type of control used to represent the argument. Options include: string, int, flag, regexp, metadata, language, enum etc
|
---|
[8879] | 87 | # reqd: Is this argument required?
|
---|
| 88 | # hiddengli: Is this argument hidden in GLI?
|
---|
| 89 | # modegli: The lowest detail mode this argument is visible at in GLI
|
---|
| 90 |
|
---|
[9233] | 91 | my $saveas_argument =
|
---|
| 92 | { 'name' => "saveas",
|
---|
| 93 | 'desc' => "{export.saveas}",
|
---|
| 94 | 'type' => "enum",
|
---|
| 95 | 'list' => $saveas_list,
|
---|
| 96 | 'deft' => "METS",
|
---|
| 97 | 'reqd' => "no",
|
---|
| 98 | 'modegli' => "3" };
|
---|
| 99 |
|
---|
| 100 |
|
---|
[8879] | 101 | my $arguments =
|
---|
[10340] | 102 | [
|
---|
| 103 | $saveas_argument,
|
---|
| 104 | { 'name' => "saveas_version",
|
---|
| 105 | 'desc' => "{export.saveas_version}",
|
---|
| 106 | 'type' => "string",
|
---|
[11746] | 107 | 'reqd' => "no",
|
---|
[12333] | 108 | 'deft' => "greenstone" },
|
---|
[10340] | 109 | { 'name' => "exportdir",
|
---|
[8879] | 110 | 'desc' => "{export.exportdir}",
|
---|
| 111 | 'type' => "string",
|
---|
| 112 | 'reqd' => "no",
|
---|
| 113 | 'hiddengli' => "yes" },
|
---|
[10340] | 114 | { 'name' => "importdir",
|
---|
| 115 | 'desc' => "{import.importdir}",
|
---|
| 116 | 'type' => "string",
|
---|
| 117 | 'reqd' => "no",
|
---|
| 118 | 'hiddengli' => "yes" },
|
---|
[14925] | 119 | { 'name' => "site",
|
---|
| 120 | 'desc' => "{import.site}",
|
---|
| 121 | 'type' => "string",
|
---|
| 122 | 'deft' => "",
|
---|
| 123 | 'reqd' => "no",
|
---|
| 124 | 'hiddengli' => "yes" },
|
---|
[8879] | 125 | { 'name' => "collectdir",
|
---|
| 126 | 'desc' => "{export.collectdir}",
|
---|
| 127 | 'type' => "string",
|
---|
[14925] | 128 | # parsearg left "" as default
|
---|
| 129 | #'deft' => &util::filename_cat ($ENV{'GSDLHOME'}, "collect"),
|
---|
| 130 | 'reqd' => "no",
|
---|
[8879] | 131 | 'hiddengli' => "yes" },
|
---|
[9233] | 132 | { 'name' => "listall",
|
---|
[12691] | 133 | 'desc' => "{export.listall}",
|
---|
[9233] | 134 | 'type' => "flag",
|
---|
| 135 | 'reqd' => "no" },
|
---|
[8879] | 136 | { 'name' => "debug",
|
---|
| 137 | 'desc' => "{export.debug}",
|
---|
| 138 | 'type' => "flag",
|
---|
| 139 | 'reqd' => "no",
|
---|
| 140 | 'hiddengli' => "yes" },
|
---|
| 141 | { 'name' => "faillog",
|
---|
| 142 | 'desc' => "{export.faillog}",
|
---|
| 143 | 'type' => "string",
|
---|
[10340] | 144 | 'deft' => "",
|
---|
[8879] | 145 | 'reqd' => "no",
|
---|
| 146 | 'modegli' => "4" },
|
---|
| 147 | { 'name' => "keepold",
|
---|
| 148 | 'desc' => "{export.keepold}",
|
---|
| 149 | 'type' => "flag",
|
---|
| 150 | 'reqd' => "no",
|
---|
| 151 | 'hiddengli' => "yes" },
|
---|
[10340] | 152 | { 'name' => "removeold",
|
---|
| 153 | 'desc' => "{export.removeold}",
|
---|
| 154 | 'type' => "flag",
|
---|
| 155 | 'reqd' => "no",
|
---|
| 156 | 'modegli' => "3" },
|
---|
[8879] | 157 | { 'name' => "language",
|
---|
| 158 | 'desc' => "{scripts.language}",
|
---|
| 159 | 'type' => "string",
|
---|
| 160 | 'reqd' => "no",
|
---|
| 161 | 'modegli' => "4" },
|
---|
| 162 | { 'name' => "maxdocs",
|
---|
| 163 | 'desc' => "{export.maxdocs}",
|
---|
| 164 | 'type' => "int",
|
---|
| 165 | 'reqd' => "no",
|
---|
| 166 | 'range' => "1,",
|
---|
| 167 | 'modegli' => "1" },
|
---|
[12691] | 168 | { 'name' => "OIDtype",
|
---|
| 169 | 'desc' => "{import.OIDtype}",
|
---|
| 170 | 'type' => "enum",
|
---|
| 171 | 'list' => $oidtype_list,
|
---|
| 172 | # parsearg left "" as default
|
---|
| 173 | #'deft' => "hash",
|
---|
| 174 | 'reqd' => "no",
|
---|
| 175 | 'modegli' => "3" },
|
---|
| 176 | { 'name' => "OIDmetadata",
|
---|
| 177 | 'desc' => "{import.OIDmetadata}",
|
---|
| 178 | 'type' => "metadata",
|
---|
| 179 | 'deft' => "dc.Identifier",
|
---|
| 180 | 'reqd' => "no",
|
---|
| 181 | 'modegli' => "3" },
|
---|
[8879] | 182 | { 'name' => "out",
|
---|
| 183 | 'desc' => "{export.out}",
|
---|
| 184 | 'type' => "string",
|
---|
| 185 | 'deft' => "STDERR",
|
---|
| 186 | 'reqd' => "no",
|
---|
| 187 | 'hiddengli' => "yes" },
|
---|
[9951] | 188 | { 'name' => "statsfile",
|
---|
| 189 | 'desc' => "{export.statsfile}",
|
---|
| 190 | 'type' => "string",
|
---|
| 191 | 'deft' => "STDERR",
|
---|
| 192 | 'reqd' => "no",
|
---|
| 193 | 'hiddengli' => "yes" },
|
---|
[12333] | 194 | { 'name' => "xsltfile",
|
---|
| 195 | 'desc' => "{BasPlugout.xslt_file}",
|
---|
| 196 | 'type' => "string",
|
---|
| 197 | 'reqd' => "no",
|
---|
| 198 | 'hiddengli' => "yes" },
|
---|
| 199 | { 'name' => "xslt_txt",
|
---|
| 200 | 'desc' => "{METSPlugout.xslt_txt}",
|
---|
| 201 | 'type' => "string",
|
---|
| 202 | 'reqd' => "no",
|
---|
| 203 | 'hiddengli' => "no" },
|
---|
| 204 | { 'name' => "xslt_mets",
|
---|
| 205 | 'desc' => "{METSPlugout.xslt_mets}",
|
---|
| 206 | 'type' => "string",
|
---|
| 207 | 'reqd' => "no",
|
---|
| 208 | 'hiddengli' => "no" },
|
---|
[12598] | 209 | { 'name' => "mapping_file",
|
---|
| 210 | 'desc' => "{MARCXMLPlugout.mapping_file}",
|
---|
| 211 | 'type' => "string",
|
---|
| 212 | 'reqd' => "no",
|
---|
| 213 | 'hiddengli' => "no" },
|
---|
[12333] | 214 | { 'name' => "group_marc",
|
---|
| 215 | 'desc' => "{MARCXMLPlugout.group}",
|
---|
| 216 | 'type' => "flag",
|
---|
| 217 | 'reqd' => "no",
|
---|
| 218 | 'hiddengli' => "no" },
|
---|
[8879] | 219 | { 'name' => "verbosity",
|
---|
| 220 | 'desc' => "{export.verbosity}",
|
---|
| 221 | 'type' => "int",
|
---|
| 222 | 'range' => "0,3",
|
---|
| 223 | 'deft' => "2",
|
---|
| 224 | 'reqd' => "no",
|
---|
[10340] | 225 | 'modegli' => "4" },
|
---|
| 226 | { 'name' => "gli",
|
---|
| 227 | 'desc' => "",
|
---|
| 228 | 'type' => "flag",
|
---|
| 229 | 'reqd' => "no",
|
---|
| 230 | 'hiddengli' => "yes" },
|
---|
| 231 | { 'name' => "xml",
|
---|
| 232 | 'desc' => "{scripts.xml}",
|
---|
| 233 | 'type' => "flag",
|
---|
| 234 | 'reqd' => "no",
|
---|
| 235 | 'hiddengli' => "yes" }
|
---|
| 236 | ];
|
---|
[8879] | 237 |
|
---|
| 238 | my $options = { 'name' => "export.pl",
|
---|
| 239 | 'desc' => "{export.desc}",
|
---|
| 240 | 'args' => $arguments };
|
---|
| 241 |
|
---|
[9233] | 242 | my $listall_options = { 'name' => "export.pl",
|
---|
| 243 | 'desc' => "{export.desc}",
|
---|
| 244 | 'args' => [ $saveas_argument ] };
|
---|
| 245 |
|
---|
[8879] | 246 | sub gsprintf
|
---|
| 247 | {
|
---|
| 248 | return &gsprintf::gsprintf(@_);
|
---|
| 249 | }
|
---|
| 250 |
|
---|
| 251 |
|
---|
| 252 | &main();
|
---|
| 253 |
|
---|
| 254 | sub main {
|
---|
[10340] | 255 | # params
|
---|
[14925] | 256 | my ($language, $verbosity, $importdir, $exportdir, $site, $keepold, $listall,
|
---|
[12691] | 257 | $removeold, $saveas, $saveas_version, $debug, $OIDtype, $OIDmetadata,
|
---|
[14925] | 258 | $maxdocs, $statsfile, $xsltfile, $mapping_file, $out, $faillog, $gs_mode, $collectcfg,
|
---|
[12965] | 259 | $collectdir, $gli,$xslt_mets,$xslt_txt,$group_marc);
|
---|
[8879] | 260 | my $xml = 0;
|
---|
[10340] | 261 |
|
---|
| 262 | # other vars
|
---|
| 263 | my ($configfilename, $collection, $export_info_filename, $export_info, $processor, $pluginfo);
|
---|
[8879] | 264 | my $service = "export";
|
---|
| 265 |
|
---|
[10340] | 266 | my $hashParsingResult = {};
|
---|
| 267 | # general options available to all plugins
|
---|
| 268 | my $intArgLeftinAfterParsing = parse2::parse(\@ARGV,$arguments,$hashParsingResult,"allow_extra_options");
|
---|
[12545] | 269 |
|
---|
| 270 | # If parse returns -1 then something has gone wrong
|
---|
| 271 | if ($intArgLeftinAfterParsing == -1)
|
---|
| 272 | {
|
---|
| 273 | &PrintUsage::print_txt_usage($options, "{export.params}");
|
---|
| 274 | die "\n";
|
---|
| 275 | }
|
---|
| 276 |
|
---|
[10340] | 277 | foreach my $strVariable (keys %$hashParsingResult)
|
---|
| 278 | {
|
---|
| 279 | eval "\$$strVariable = \$hashParsingResult->{\"\$strVariable\"}";
|
---|
[8879] | 280 | }
|
---|
| 281 |
|
---|
[10340] | 282 |
|
---|
| 283 | # these are options used by other things - we just set default values
|
---|
| 284 | # undef means will be set from config file if there
|
---|
| 285 | my $gzip = undef;
|
---|
| 286 | my $groupsize = 1;
|
---|
[12691] | 287 | #my $OIDtype = undef;
|
---|
[10340] | 288 | my $sortmeta = undef;
|
---|
[9233] | 289 |
|
---|
[9235] | 290 | my $explicit_exportdir = (defined $exportdir) ? 1 : 0;
|
---|
| 291 |
|
---|
[10417] | 292 | # save these command line settings. don't want config file settings in one
|
---|
| 293 | # coll used for other colls
|
---|
| 294 | # does this apply to other vars???
|
---|
| 295 | my $global_removeold = $removeold;
|
---|
| 296 | my $global_keepold = $keepold;
|
---|
[8879] | 297 | # If $language has been specified, load the appropriate resource bundle
|
---|
| 298 | # (Otherwise, the default resource bundle will be loaded automatically)
|
---|
| 299 | if ($language) {
|
---|
| 300 | &gsprintf::load_language_specific_resource_bundle($language);
|
---|
| 301 | }
|
---|
| 302 |
|
---|
[9233] | 303 | if ($listall) {
|
---|
| 304 | if ($xml) {
|
---|
| 305 | &PrintUsage::print_xml_usage($listall_options);
|
---|
| 306 | }
|
---|
| 307 | else
|
---|
| 308 | {
|
---|
| 309 | &PrintUsage::print_txt_usage($listall_options,"{export.params}");
|
---|
| 310 | }
|
---|
| 311 | die "\n";
|
---|
| 312 | }
|
---|
| 313 | elsif ($xml) {
|
---|
[8879] | 314 | &PrintUsage::print_xml_usage($options);
|
---|
| 315 | die "\n";
|
---|
| 316 | }
|
---|
| 317 |
|
---|
[12545] | 318 | # can have more than one collection name,
|
---|
| 319 | # if the first extra option is -h, then output the help
|
---|
| 320 | if (scalar(@ARGV) == 0 || (@ARGV && $ARGV[0] =~ /^\-+h/)) {
|
---|
[10340] | 321 | &PrintUsage::print_txt_usage($options, "{export.params}");
|
---|
| 322 | die "\n";
|
---|
| 323 | }
|
---|
| 324 |
|
---|
[8879] | 325 | if ($gli) { # the gli wants strings to be in UTF-8
|
---|
| 326 | &gsprintf::output_strings_in_UTF8;
|
---|
| 327 | }
|
---|
| 328 | my $close_out = 0;
|
---|
| 329 | if ($out !~ /^(STDERR|STDOUT)$/i) {
|
---|
| 330 | open (OUT, ">$out") ||
|
---|
| 331 | (&gsprintf(STDERR, "{common.cannot_open_output_file}\n", $out) && die);
|
---|
| 332 | $out = 'export::OUT';
|
---|
| 333 | $close_out = 1;
|
---|
| 334 | }
|
---|
| 335 | $out->autoflush(1);
|
---|
| 336 |
|
---|
[9233] | 337 | while (scalar(@ARGV)>0) {
|
---|
| 338 | my $collect_name = shift @ARGV;
|
---|
| 339 | $ENV{'GSDLCOLLECTION'} = $collect_name;
|
---|
[8879] | 340 |
|
---|
[9233] | 341 | eval {
|
---|
| 342 | # get and check the collection name
|
---|
[14925] | 343 | print STDERR "**** site = $site\n";
|
---|
| 344 | if (($collection = &colcfg::use_collection($site, $collect_name, $collectdir)) eq "") {
|
---|
[9233] | 345 | &PrintUsage::print_txt_usage($options, "{export.params}");
|
---|
| 346 | die "\n";
|
---|
| 347 | }
|
---|
[12358] | 348 | # add collection's perllib dir into include path in
|
---|
| 349 | # case we have collection specific modules
|
---|
| 350 | unshift (@INC, "$ENV{'GSDLCOLLECTDIR'}/perllib");
|
---|
| 351 |
|
---|
[9233] | 352 | if ($faillog eq "") {
|
---|
| 353 | $faillog = &util::filename_cat($ENV{'GSDLCOLLECTDIR'}, "etc", "fail.log");
|
---|
| 354 | }
|
---|
| 355 | open (FAILLOG, ">$faillog") ||
|
---|
| 356 | (&gsprintf(STDERR, "{export.cannot_open_fail_log}\n", $faillog) && die);
|
---|
| 357 | my $faillogname = $faillog;
|
---|
| 358 | $faillog = 'export::FAILLOG';
|
---|
| 359 | $faillog->autoflush(1);
|
---|
| 360 |
|
---|
| 361 | # check sortmeta
|
---|
| 362 | $sortmeta = undef unless defined $sortmeta && $sortmeta =~ /\S/;
|
---|
| 363 | if (defined $sortmeta && $groupsize > 1) {
|
---|
| 364 | &gsprintf($out, "{export.cannot_sort}\n\n");
|
---|
| 365 | $sortmeta = undef;
|
---|
| 366 | }
|
---|
| 367 |
|
---|
| 368 | # get the list of plugins for this collection and set any options that
|
---|
| 369 | # were specified in the collect.cfg (all export.pl options except
|
---|
| 370 | # -collectdir, -out and -faillog may be specified in the collect.cfg (these
|
---|
| 371 | # options must be known before we read the collect.cfg))
|
---|
| 372 | my $plugins = [];
|
---|
| 373 | my @global_opts = ();
|
---|
| 374 |
|
---|
[14925] | 375 | # Read in the collection configuration file.
|
---|
| 376 | ($configfilename, $gs_mode) = &colcfg::get_collect_cfg_name($out);
|
---|
| 377 |
|
---|
| 378 | if ($gs_mode eq "gs2") {
|
---|
| 379 | $collectcfg = &colcfg::read_collect_cfg ($configfilename);
|
---|
| 380 | } elsif ($gs_mode eq "gs3") {
|
---|
| 381 | $collectcfg = &colcfg::read_collection_cfg_xml ($configfilename);
|
---|
[10417] | 382 | }
|
---|
[14925] | 383 |
|
---|
[10417] | 384 | if (defined $collectcfg->{'plugin'}) {
|
---|
| 385 | $plugins = $collectcfg->{'plugin'};
|
---|
| 386 | }
|
---|
| 387 |
|
---|
| 388 | if ($verbosity !~ /\d+/) {
|
---|
| 389 | if (defined $collectcfg->{'verbosity'} && $collectcfg->{'verbosity'} =~ /\d+/) {
|
---|
| 390 | $verbosity = $collectcfg->{'verbosity'};
|
---|
| 391 | } else {
|
---|
| 392 | $verbosity = 2; # the default
|
---|
[9233] | 393 | }
|
---|
[10417] | 394 | }
|
---|
| 395 | if (defined $collectcfg->{'importdir'} && $importdir eq "") {
|
---|
| 396 | $importdir = $collectcfg->{'importdir'};
|
---|
| 397 | }
|
---|
| 398 | if (defined $collectcfg->{'exportdir'} && $exportdir eq "") {
|
---|
| 399 | $exportdir = $collectcfg->{'exportdir'};
|
---|
| 400 | }
|
---|
| 401 |
|
---|
| 402 | if (defined $collectcfg->{'gzip'} && !$gzip) {
|
---|
| 403 | if ($collectcfg->{'gzip'} =~ /^true$/i) {
|
---|
| 404 | $gzip = 1;
|
---|
[9233] | 405 | }
|
---|
[10417] | 406 | }
|
---|
| 407 | if ($maxdocs !~ /\-?\d+/) {
|
---|
| 408 | if (defined $collectcfg->{'maxdocs'} && $collectcfg->{'maxdocs'} =~ /\-?\d+/) {
|
---|
| 409 | $maxdocs = $collectcfg->{'maxdocs'};
|
---|
| 410 | } else {
|
---|
| 411 | $maxdocs = -1; # the default
|
---|
[9233] | 412 | }
|
---|
[10417] | 413 | }
|
---|
| 414 | if ($groupsize == 1) {
|
---|
| 415 | if (defined $collectcfg->{'groupsize'} && $collectcfg->{'groupsize'} =~ /\d+/) {
|
---|
| 416 | $groupsize = $collectcfg->{'groupsize'};
|
---|
[9233] | 417 | }
|
---|
[10417] | 418 | }
|
---|
[12691] | 419 | if (!defined $OIDtype || ($OIDtype !~ /^(hash|incremental|assigned|dirname)$/)) {
|
---|
[10417] | 420 | if (defined $collectcfg->{'OIDtype'} && $collectcfg->{'OIDtype'} =~ /^(hash|incremental)$/) {
|
---|
| 421 | $OIDtype = $collectcfg->{'OIDtype'};
|
---|
| 422 | } else {
|
---|
| 423 | $OIDtype = "hash"; # the default
|
---|
[9233] | 424 | }
|
---|
[8879] | 425 | }
|
---|
[10417] | 426 | if (defined $collectcfg->{'sortmeta'} && $sortmeta eq "") {
|
---|
| 427 | $sortmeta = $collectcfg->{'sortmeta'};
|
---|
| 428 | }
|
---|
| 429 | if (defined $collectcfg->{'debug'} && $collectcfg->{'debug'} =~ /^true$/i) {
|
---|
| 430 | $debug = 1;
|
---|
| 431 | }
|
---|
| 432 | if (defined $collectcfg->{'gli'} && $collectcfg->{'gli'} =~ /^true$/i) {
|
---|
| 433 | $gli = 1;
|
---|
| 434 | }
|
---|
[9233] | 435 |
|
---|
[10417] | 436 | # global plugin stuff
|
---|
| 437 | if (defined $collectcfg->{'separate_cjk'}&& $collectcfg->{'separate_cjk'} =~ /^true$/i) {
|
---|
| 438 | push @global_opts, "-separate_cjk";
|
---|
| 439 | }
|
---|
| 440 |
|
---|
[12965] | 441 | ($removeold, $keepold) = &scriptutil::check_removeold_and_keepold($global_removeold, $global_keepold, 0, "export", $collectcfg);
|
---|
[10417] | 442 |
|
---|
[9233] | 443 | $gli = 0 unless defined $gli;
|
---|
| 444 |
|
---|
| 445 | print STDERR "<export>\n" if $gli;
|
---|
| 446 |
|
---|
| 447 | # fill in the default import and export directories if none
|
---|
| 448 | # were supplied, turn all \ into / and remove trailing /
|
---|
| 449 | $importdir = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "import") if $importdir eq "";
|
---|
| 450 | $importdir =~ s/[\\\/]+/\//g;
|
---|
| 451 | $importdir =~ s/\/$//;
|
---|
| 452 | $exportdir = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "export") if $exportdir eq "";
|
---|
| 453 | $exportdir =~ s/[\\\/]+/\//g;
|
---|
| 454 | $exportdir =~ s/\/$//;
|
---|
| 455 |
|
---|
| 456 | # load all the plugins
|
---|
| 457 | $pluginfo = &plugin::load_plugins ($plugins, $verbosity, $out, $faillog, \@global_opts);
|
---|
| 458 |
|
---|
| 459 | if (scalar(@$pluginfo) == 0) {
|
---|
| 460 | &gsprintf($out, "{import.no_plugins_loaded}\n");
|
---|
| 461 | die "\n";
|
---|
[8879] | 462 | }
|
---|
[9233] | 463 |
|
---|
| 464 | # remove the old contents of the export directory if needed
|
---|
| 465 | if ($removeold && -e $exportdir) {
|
---|
| 466 | &gsprintf($out, "{export.removing_export}\n");
|
---|
| 467 | &util::rm_r ($exportdir);
|
---|
[8879] | 468 | }
|
---|
[9233] | 469 |
|
---|
| 470 | # read the export information file
|
---|
[13169] | 471 |
|
---|
| 472 | # Export to DSpace Archive format or METs format
|
---|
| 473 | # If saveas=DSpace, a "contents" file will be created, otherwise "export.inf"
|
---|
[9233] | 474 |
|
---|
[13169] | 475 | # the plugouts should be doing this!!
|
---|
| 476 | if ($saveas eq "DSpace"){
|
---|
| 477 | $export_info_filename = &util::filename_cat ($exportdir, "contents");
|
---|
| 478 | } elsif ($saveas eq "METS" || $saveas eq "GA" || $saveas eq "MARC" ) {
|
---|
| 479 | $export_info_filename = &util::filename_cat ($exportdir, "export.inf");
|
---|
| 480 | }
|
---|
| 481 |
|
---|
| 482 | $export_info = new arcinfo();
|
---|
| 483 | $export_info -> load_info ($export_info_filename);
|
---|
| 484 |
|
---|
[14733] | 485 | my ($plugout);
|
---|
| 486 | if (defined $collectcfg->{'plugout'}) {
|
---|
| 487 | $plugout = $collectcfg->{'plugout'};
|
---|
| 488 | }
|
---|
| 489 | else{
|
---|
| 490 | if ($saveas !~ /^(GA|METS|DSpace|MARCXML)$/) {
|
---|
| 491 | push @$plugout,"GAPlugout";
|
---|
[9233] | 492 | }
|
---|
[14733] | 493 | else{
|
---|
| 494 | push @$plugout,$saveas."Plugout";
|
---|
| 495 | }
|
---|
[8879] | 496 | }
|
---|
[14733] | 497 |
|
---|
| 498 | my $plugout_name = $plugout->[0];
|
---|
[9233] | 499 |
|
---|
[14733] | 500 | push @$plugout,("-output_info",$export_info) if (defined $export_info);
|
---|
| 501 | push @$plugout,("-verbosity",$verbosity) if (defined $verbosity);
|
---|
| 502 | push @$plugout,("-debug") if ($debug);
|
---|
| 503 | push @$plugout,("-gzip_output",$gzip) if (defined $gzip);
|
---|
| 504 | push @$plugout,("-group_size",$groupsize) if (defined $groupsize);
|
---|
| 505 | push @$plugout,("-output_handle",$out) if (defined $out);
|
---|
| 506 | push @$plugout,("-xslt_file",$xsltfile) if (defined $xsltfile);
|
---|
| 507 | push @$plugout,("-group") if ($group_marc && $plugout_name =~ /^MARCXMLPlugout$/);
|
---|
| 508 | push @$plugout,("-mapping_file",$mapping_file) if (defined $mapping_file && $plugout_name =~ /^MARCXMLPlugout$/);
|
---|
| 509 | push @$plugout,("-saveas_version",$saveas_version) if (defined $saveas_version && $plugout_name =~ /^METSPlugout$/);
|
---|
| 510 | push @$plugout,("-xslt_mets",$xslt_mets) if (defined $xslt_mets && $plugout_name =~ /^METSPlugout$/);
|
---|
| 511 | push @$plugout,("-xslt_txt",$xslt_txt) if (defined $xslt_txt && $plugout_name =~ /^METSPlugout$/);
|
---|
| 512 | $processor = &plugout::load_plugout($plugout);
|
---|
[13169] | 513 |
|
---|
| 514 | $processor->setoutputdir ($exportdir);
|
---|
| 515 |
|
---|
| 516 | $processor->set_sortmeta ($sortmeta) if defined $sortmeta;
|
---|
| 517 | $processor->set_OIDtype ($OIDtype, $OIDmetadata);
|
---|
| 518 |
|
---|
[9233] | 519 | &plugin::begin($pluginfo, $importdir, $processor, $maxdocs);
|
---|
| 520 |
|
---|
| 521 | # process the import directory
|
---|
[9854] | 522 | &plugin::read ($pluginfo, $importdir, "", {}, $processor, $maxdocs,0, $gli);
|
---|
[9233] | 523 |
|
---|
| 524 | &plugin::end($pluginfo, $processor);
|
---|
[10162] | 525 |
|
---|
| 526 | &plugin::deinit($pluginfo, $processor);
|
---|
[9233] | 527 |
|
---|
| 528 | # write out the export information file
|
---|
[13169] | 529 | $processor->close_file_output() if $groupsize > 1;
|
---|
| 530 | $processor->close_group_output() if $processor->is_group();
|
---|
| 531 | if ($saveas eq "METS") {
|
---|
| 532 | $export_info->save_info($export_info_filename);
|
---|
[8879] | 533 | }
|
---|
[9233] | 534 |
|
---|
[9951] | 535 | # write out export stats
|
---|
| 536 | my $close_stats = 0;
|
---|
| 537 | if ($statsfile !~ /^(STDERR|STDOUT)$/i) {
|
---|
| 538 | if (open (STATS, ">$statsfile")) {
|
---|
| 539 | $statsfile = 'import::STATS';
|
---|
| 540 | $close_stats = 1;
|
---|
| 541 | } else {
|
---|
| 542 | &gsprintf($out, "{import.cannot_open_stats_file}", $statsfile);
|
---|
| 543 | &gsprintf($out, "{import.stats_backup}\n");
|
---|
| 544 | $statsfile = 'STDERR';
|
---|
| 545 | }
|
---|
| 546 | }
|
---|
| 547 |
|
---|
| 548 | &gsprintf($out, "\n");
|
---|
| 549 | &gsprintf($out, "*********************************************\n");
|
---|
| 550 |
|
---|
| 551 | &plugin::write_stats($pluginfo, $statsfile, $faillogname, $gli);
|
---|
| 552 | if ($close_stats) {
|
---|
| 553 | close STATS;
|
---|
| 554 | }
|
---|
| 555 |
|
---|
| 556 | &gsprintf($out, "*********************************************\n");
|
---|
| 557 |
|
---|
| 558 | close OUT if $close_out;
|
---|
| 559 |
|
---|
[9233] | 560 | close FAILLOG;
|
---|
| 561 | };
|
---|
[8879] | 562 |
|
---|
[9951] | 563 | if ($@) {
|
---|
| 564 | print STDERR $@;
|
---|
| 565 | }
|
---|
| 566 |
|
---|
[9233] | 567 | ## $ENV{'GSDLCOLLECTION'} = undef;
|
---|
| 568 | $importdir = "";
|
---|
[9235] | 569 | $removeold = 0 if ($explicit_exportdir);
|
---|
[9233] | 570 |
|
---|
[10340] | 571 | } # while processing ARGV
|
---|
[9233] | 572 |
|
---|
[8879] | 573 | &gsprintf($out, "\n");
|
---|
| 574 | &gsprintf($out, "*********************************************\n");
|
---|
[9951] | 575 | &gsprintf($out, "* {export.complete}\n");
|
---|
| 576 | &gsprintf($out, "*********************************************\n");
|
---|
[8879] | 577 |
|
---|
| 578 | }
|
---|