[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 | #
|
---|
[17142] | 10 | # Copyright (C) 2004 New Zealand Digital Library Project
|
---|
[8879] | 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 |
|
---|
| 31 | package export;
|
---|
| 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/plugins");
|
---|
[12333] | 39 | unshift (@INC, "$ENV{'GSDLHOME'}/perllib/plugouts");
|
---|
[14942] | 40 |
|
---|
| 41 | if (defined $ENV{'GSDLEXTS'}) {
|
---|
| 42 | my @extensions = split(/:/,$ENV{'GSDLEXTS'});
|
---|
| 43 | foreach my $e (@extensions) {
|
---|
| 44 | my $ext_prefix = "$ENV{'GSDLHOME'}/ext/$e";
|
---|
| 45 |
|
---|
| 46 | unshift (@INC, "$ext_prefix/perllib");
|
---|
| 47 | unshift (@INC, "$ext_prefix/perllib/cpan");
|
---|
[17142] | 48 | unshift (@INC, "$ext_prefix/perllib/plugins");
|
---|
| 49 | unshift (@INC, "$ext_prefix/perllib/plugouts");
|
---|
[14942] | 50 | }
|
---|
| 51 | }
|
---|
[8879] | 52 | }
|
---|
| 53 |
|
---|
[10340] | 54 | use strict;
|
---|
| 55 | no strict 'refs'; # allow filehandles to be variables and vice versa
|
---|
| 56 | no strict 'subs'; # allow barewords (eg STDERR) as function arguments
|
---|
| 57 |
|
---|
[10162] | 58 | use arcinfo;
|
---|
[8879] | 59 | use colcfg;
|
---|
| 60 | use plugin;
|
---|
[12333] | 61 | use plugout;
|
---|
[14935] | 62 | use manifest;
|
---|
[8879] | 63 | use util;
|
---|
[10417] | 64 | use scriptutil;
|
---|
[8879] | 65 | use FileHandle;
|
---|
[14935] | 66 | use gsprintf 'gsprintf';
|
---|
[8879] | 67 | use printusage;
|
---|
[10340] | 68 | use parse2;
|
---|
[8879] | 69 |
|
---|
[10340] | 70 |
|
---|
[8879] | 71 | my $oidtype_list =
|
---|
| 72 | [ { 'name' => "hash",
|
---|
[12691] | 73 | 'desc' => "{import.OIDtype.hash}" },
|
---|
[14935] | 74 | { 'name' => "assigned",
|
---|
| 75 | 'desc' => "{import.OIDtype.assigned}" },
|
---|
[8879] | 76 | { 'name' => "incremental",
|
---|
[12691] | 77 | 'desc' => "{import.OIDtype.incremental}" },
|
---|
| 78 | { 'name' => "dirname",
|
---|
| 79 | 'desc' => "{import.OIDtype.dirname}" } ];
|
---|
[8879] | 80 |
|
---|
[17142] | 81 | # what format to export as
|
---|
[8879] | 82 | my $saveas_list =
|
---|
[17142] | 83 | [ { 'name' => "GreenstoneMETS",
|
---|
[14935] | 84 | 'desc' => "{export.saveas.GreenstoneMETS}"},
|
---|
| 85 | { 'name' => "FedoraMETS",
|
---|
| 86 | 'desc' => "{export.saveas.FedoraMETS}"},
|
---|
[12333] | 87 | { 'name' => "MARCXML",
|
---|
[17142] | 88 | 'desc' => "{export.saveas.MARCXML}"},
|
---|
| 89 | { 'name' => "DSpace",
|
---|
| 90 | 'desc' => "{export.saveas.DSpace}" }
|
---|
[12333] | 91 | ];
|
---|
[8879] | 92 |
|
---|
| 93 |
|
---|
| 94 | # Possible attributes for each argument
|
---|
| 95 | # name: The name of the argument
|
---|
| 96 | # desc: A description (or more likely a reference to a description) for this argument
|
---|
[12361] | 97 | # type: The type of control used to represent the argument. Options include: string, int, flag, regexp, metadata, language, enum etc
|
---|
[8879] | 98 | # reqd: Is this argument required?
|
---|
| 99 | # hiddengli: Is this argument hidden in GLI?
|
---|
| 100 | # modegli: The lowest detail mode this argument is visible at in GLI
|
---|
| 101 |
|
---|
[14935] | 102 | my $saveas_argument =
|
---|
[9233] | 103 | { 'name' => "saveas",
|
---|
| 104 | 'desc' => "{export.saveas}",
|
---|
| 105 | 'type' => "enum",
|
---|
| 106 | 'list' => $saveas_list,
|
---|
[17142] | 107 | 'deft' => "GreenstoneMETS",
|
---|
[9233] | 108 | 'reqd' => "no",
|
---|
| 109 | 'modegli' => "3" };
|
---|
| 110 |
|
---|
| 111 |
|
---|
[8879] | 112 | my $arguments =
|
---|
[10340] | 113 | [
|
---|
| 114 | $saveas_argument,
|
---|
| 115 | { 'name' => "exportdir",
|
---|
[8879] | 116 | 'desc' => "{export.exportdir}",
|
---|
| 117 | 'type' => "string",
|
---|
| 118 | 'reqd' => "no",
|
---|
| 119 | 'hiddengli' => "yes" },
|
---|
[10340] | 120 | { 'name' => "importdir",
|
---|
| 121 | 'desc' => "{import.importdir}",
|
---|
| 122 | 'type' => "string",
|
---|
| 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"),
|
---|
[14935] | 130 | 'deft' => "",
|
---|
| 131 | 'reqd' => "no",
|
---|
| 132 | 'hiddengli' => "yes" },
|
---|
[17142] | 133 | { 'name' => "site",
|
---|
| 134 | 'desc' => "{import.site}",
|
---|
| 135 | 'type' => "string",
|
---|
| 136 | 'deft' => "",
|
---|
| 137 | 'reqd' => "no",
|
---|
| 138 | 'hiddengli' => "yes" },
|
---|
| 139 | { 'name' => "manifest",
|
---|
[14935] | 140 | 'desc' => "{import.manifest}",
|
---|
| 141 | 'type' => "string",
|
---|
| 142 | 'deft' => "",
|
---|
| 143 | 'reqd' => "no",
|
---|
[8879] | 144 | 'hiddengli' => "yes" },
|
---|
[9233] | 145 | { 'name' => "listall",
|
---|
[12691] | 146 | 'desc' => "{export.listall}",
|
---|
[9233] | 147 | 'type' => "flag",
|
---|
| 148 | 'reqd' => "no" },
|
---|
[8879] | 149 | { 'name' => "debug",
|
---|
| 150 | 'desc' => "{export.debug}",
|
---|
| 151 | 'type' => "flag",
|
---|
| 152 | 'reqd' => "no",
|
---|
| 153 | 'hiddengli' => "yes" },
|
---|
| 154 | { 'name' => "faillog",
|
---|
| 155 | 'desc' => "{export.faillog}",
|
---|
| 156 | 'type' => "string",
|
---|
[10340] | 157 | 'deft' => "",
|
---|
[8879] | 158 | 'reqd' => "no",
|
---|
[18590] | 159 | 'modegli' => "3" },
|
---|
[17142] | 160 | # does this make sense?
|
---|
| 161 | # { 'name' => "incremental",
|
---|
| 162 | # 'desc' => "{import.incremental}",
|
---|
| 163 | # 'type' => "flag",
|
---|
| 164 | # 'hiddengli' => "yes" },
|
---|
[8879] | 165 | { 'name' => "keepold",
|
---|
| 166 | 'desc' => "{export.keepold}",
|
---|
| 167 | 'type' => "flag",
|
---|
| 168 | 'reqd' => "no",
|
---|
[14935] | 169 | 'hiddengli' => "yes" },
|
---|
[10340] | 170 | { 'name' => "removeold",
|
---|
| 171 | 'desc' => "{export.removeold}",
|
---|
| 172 | 'type' => "flag",
|
---|
| 173 | 'reqd' => "no",
|
---|
| 174 | 'modegli' => "3" },
|
---|
[8879] | 175 | { 'name' => "language",
|
---|
| 176 | 'desc' => "{scripts.language}",
|
---|
| 177 | 'type' => "string",
|
---|
| 178 | 'reqd' => "no",
|
---|
[18590] | 179 | 'modegli' => "3" },
|
---|
[8879] | 180 | { 'name' => "maxdocs",
|
---|
| 181 | 'desc' => "{export.maxdocs}",
|
---|
| 182 | 'type' => "int",
|
---|
| 183 | 'reqd' => "no",
|
---|
| 184 | 'range' => "1,",
|
---|
| 185 | 'modegli' => "1" },
|
---|
[12691] | 186 | { 'name' => "OIDtype",
|
---|
| 187 | 'desc' => "{import.OIDtype}",
|
---|
| 188 | 'type' => "enum",
|
---|
| 189 | 'list' => $oidtype_list,
|
---|
| 190 | # parsearg left "" as default
|
---|
| 191 | #'deft' => "hash",
|
---|
| 192 | 'reqd' => "no",
|
---|
[18590] | 193 | 'modegli' => "2" },
|
---|
[12691] | 194 | { 'name' => "OIDmetadata",
|
---|
| 195 | 'desc' => "{import.OIDmetadata}",
|
---|
[19625] | 196 | 'type' => "string",
|
---|
| 197 | #'type' => "metadata", #doesn't work properly in GLI
|
---|
[12691] | 198 | 'deft' => "dc.Identifier",
|
---|
| 199 | 'reqd' => "no",
|
---|
[18590] | 200 | 'modegli' => "2" },
|
---|
[8879] | 201 | { 'name' => "out",
|
---|
| 202 | 'desc' => "{export.out}",
|
---|
| 203 | 'type' => "string",
|
---|
| 204 | 'deft' => "STDERR",
|
---|
| 205 | 'reqd' => "no",
|
---|
| 206 | 'hiddengli' => "yes" },
|
---|
[9951] | 207 | { 'name' => "statsfile",
|
---|
| 208 | 'desc' => "{export.statsfile}",
|
---|
| 209 | 'type' => "string",
|
---|
| 210 | 'deft' => "STDERR",
|
---|
| 211 | 'reqd' => "no",
|
---|
| 212 | 'hiddengli' => "yes" },
|
---|
[12333] | 213 | { 'name' => "xsltfile",
|
---|
| 214 | 'desc' => "{BasPlugout.xslt_file}",
|
---|
| 215 | 'type' => "string",
|
---|
| 216 | 'reqd' => "no",
|
---|
| 217 | 'hiddengli' => "yes" },
|
---|
| 218 | { 'name' => "xslt_txt",
|
---|
| 219 | 'desc' => "{METSPlugout.xslt_txt}",
|
---|
| 220 | 'type' => "string",
|
---|
| 221 | 'reqd' => "no",
|
---|
| 222 | 'hiddengli' => "no" },
|
---|
| 223 | { 'name' => "xslt_mets",
|
---|
| 224 | 'desc' => "{METSPlugout.xslt_mets}",
|
---|
| 225 | 'type' => "string",
|
---|
| 226 | 'reqd' => "no",
|
---|
| 227 | 'hiddengli' => "no" },
|
---|
[14935] | 228 | { 'name' => "fedora_namespace",
|
---|
| 229 | 'desc' => "{FedoraMETSPlugout.fedora_namespace}",
|
---|
| 230 | 'type' => "string",
|
---|
| 231 | 'deft' => "greenstone",
|
---|
| 232 | 'reqd' => "no",
|
---|
| 233 | 'hiddengli' => "no" },
|
---|
[12598] | 234 | { 'name' => "mapping_file",
|
---|
| 235 | 'desc' => "{MARCXMLPlugout.mapping_file}",
|
---|
| 236 | 'type' => "string",
|
---|
| 237 | 'reqd' => "no",
|
---|
| 238 | 'hiddengli' => "no" },
|
---|
[12333] | 239 | { 'name' => "group_marc",
|
---|
| 240 | 'desc' => "{MARCXMLPlugout.group}",
|
---|
| 241 | 'type' => "flag",
|
---|
| 242 | 'reqd' => "no",
|
---|
| 243 | 'hiddengli' => "no" },
|
---|
[8879] | 244 | { 'name' => "verbosity",
|
---|
| 245 | 'desc' => "{export.verbosity}",
|
---|
| 246 | 'type' => "int",
|
---|
| 247 | 'range' => "0,3",
|
---|
| 248 | 'deft' => "2",
|
---|
| 249 | 'reqd' => "no",
|
---|
[18590] | 250 | 'modegli' => "3" },
|
---|
[10340] | 251 | { 'name' => "gli",
|
---|
[17142] | 252 | 'desc' => "{scripts.gli}",
|
---|
[10340] | 253 | 'type' => "flag",
|
---|
| 254 | 'reqd' => "no",
|
---|
| 255 | 'hiddengli' => "yes" },
|
---|
| 256 | { 'name' => "xml",
|
---|
| 257 | 'desc' => "{scripts.xml}",
|
---|
| 258 | 'type' => "flag",
|
---|
| 259 | 'reqd' => "no",
|
---|
| 260 | 'hiddengli' => "yes" }
|
---|
| 261 | ];
|
---|
[8879] | 262 |
|
---|
| 263 | my $options = { 'name' => "export.pl",
|
---|
| 264 | 'desc' => "{export.desc}",
|
---|
| 265 | 'args' => $arguments };
|
---|
| 266 |
|
---|
[9233] | 267 | my $listall_options = { 'name' => "export.pl",
|
---|
| 268 | 'desc' => "{export.desc}",
|
---|
| 269 | 'args' => [ $saveas_argument ] };
|
---|
| 270 |
|
---|
[14935] | 271 |
|
---|
[8879] | 272 | &main();
|
---|
| 273 |
|
---|
| 274 | sub main {
|
---|
[10340] | 275 | # params
|
---|
[14935] | 276 | my ($language, $verbosity, $debug,
|
---|
[17142] | 277 | $collectdir, $importdir, $exportdir, $site, $manifest,
|
---|
| 278 | $incremental, $keepold, $removeold,
|
---|
| 279 | $saveas,
|
---|
[14935] | 280 | $OIDtype, $OIDmetadata,
|
---|
| 281 | $maxdocs, $statsfile,
|
---|
[17142] | 282 | $out, $faillog, $gli, $listall,
|
---|
| 283 | # plugout specific ones
|
---|
| 284 | $mapping_file, $xsltfile,
|
---|
[14935] | 285 | $xslt_mets, $xslt_txt, $fedora_namespace, $group_marc);
|
---|
| 286 |
|
---|
[8879] | 287 | my $xml = 0;
|
---|
[10340] | 288 |
|
---|
| 289 | # other vars
|
---|
[17142] | 290 | my ($configfilename, $collection, $collectcfg,
|
---|
[18440] | 291 | $expinfo_doc_filename, $export_info,
|
---|
[17142] | 292 | $gs_mode,
|
---|
[14935] | 293 | $processor, $pluginfo);
|
---|
| 294 |
|
---|
[8879] | 295 | my $service = "export";
|
---|
| 296 |
|
---|
[10340] | 297 | my $hashParsingResult = {};
|
---|
| 298 | # general options available to all plugins
|
---|
| 299 | my $intArgLeftinAfterParsing = parse2::parse(\@ARGV,$arguments,$hashParsingResult,"allow_extra_options");
|
---|
[12545] | 300 |
|
---|
| 301 | # If parse returns -1 then something has gone wrong
|
---|
| 302 | if ($intArgLeftinAfterParsing == -1)
|
---|
| 303 | {
|
---|
| 304 | &PrintUsage::print_txt_usage($options, "{export.params}");
|
---|
| 305 | die "\n";
|
---|
| 306 | }
|
---|
| 307 |
|
---|
[10340] | 308 | foreach my $strVariable (keys %$hashParsingResult)
|
---|
| 309 | {
|
---|
| 310 | eval "\$$strVariable = \$hashParsingResult->{\"\$strVariable\"}";
|
---|
[8879] | 311 | }
|
---|
| 312 |
|
---|
[10340] | 313 |
|
---|
| 314 | # these are options used by other things - we just set default values
|
---|
| 315 | # undef means will be set from config file if there
|
---|
| 316 | my $gzip = undef;
|
---|
[9233] | 317 |
|
---|
[8879] | 318 | # If $language has been specified, load the appropriate resource bundle
|
---|
| 319 | # (Otherwise, the default resource bundle will be loaded automatically)
|
---|
[17142] | 320 | if ($language && $language =~ /\S/) {
|
---|
[8879] | 321 | &gsprintf::load_language_specific_resource_bundle($language);
|
---|
| 322 | }
|
---|
| 323 |
|
---|
[9233] | 324 | if ($listall) {
|
---|
| 325 | if ($xml) {
|
---|
| 326 | &PrintUsage::print_xml_usage($listall_options);
|
---|
| 327 | }
|
---|
| 328 | else
|
---|
| 329 | {
|
---|
| 330 | &PrintUsage::print_txt_usage($listall_options,"{export.params}");
|
---|
| 331 | }
|
---|
| 332 | die "\n";
|
---|
| 333 | }
|
---|
[17142] | 334 |
|
---|
| 335 | if ($xml) {
|
---|
[8879] | 336 | &PrintUsage::print_xml_usage($options);
|
---|
| 337 | die "\n";
|
---|
| 338 | }
|
---|
| 339 |
|
---|
[17142] | 340 | if ($gli) { # the gli wants strings to be in UTF-8
|
---|
| 341 | &gsprintf::output_strings_in_UTF8;
|
---|
| 342 | }
|
---|
| 343 |
|
---|
| 344 | # now check that we had exactly one leftover arg, which should be
|
---|
| 345 | # the collection name. We don't want to do this earlier, cos
|
---|
| 346 | # -xml arg doesn't need a collection name
|
---|
| 347 | # Or if the user specified -h, then we output the usage also
|
---|
| 348 | if ($intArgLeftinAfterParsing != 1 || (@ARGV && $ARGV[0] =~ /^\-+h/))
|
---|
| 349 | {
|
---|
[10340] | 350 | &PrintUsage::print_txt_usage($options, "{export.params}");
|
---|
| 351 | die "\n";
|
---|
| 352 | }
|
---|
| 353 |
|
---|
[8879] | 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 = 'export::OUT';
|
---|
| 359 | $close_out = 1;
|
---|
| 360 | }
|
---|
| 361 | $out->autoflush(1);
|
---|
| 362 |
|
---|
[17142] | 363 | # get and check the collection name
|
---|
| 364 | if (($collection = &colcfg::use_collection($site, @ARGV, $collectdir)) eq "") {
|
---|
| 365 | &PrintUsage::print_txt_usage($options, "{export.params}");
|
---|
| 366 | die "\n";
|
---|
| 367 | }
|
---|
| 368 | # add collection's perllib dir into include path in
|
---|
| 369 | # case we have collection specific modules
|
---|
| 370 | unshift (@INC, "$ENV{'GSDLCOLLECTDIR'}/perllib");
|
---|
| 371 |
|
---|
| 372 | # check that we can open the faillog
|
---|
| 373 | if ($faillog eq "") {
|
---|
| 374 | $faillog = &util::filename_cat($ENV{'GSDLCOLLECTDIR'}, "etc", "fail.log");
|
---|
| 375 | }
|
---|
| 376 | open (FAILLOG, ">$faillog") ||
|
---|
| 377 | (&gsprintf(STDERR, "{export.cannot_open_fail_log}\n", $faillog) && die);
|
---|
| 378 | my $faillogname = $faillog;
|
---|
| 379 | $faillog = 'export::FAILLOG';
|
---|
| 380 | $faillog->autoflush(1);
|
---|
[12358] | 381 |
|
---|
[17142] | 382 | # Read in the collection configuration file.
|
---|
| 383 | ($configfilename, $gs_mode) = &colcfg::get_collect_cfg_name($out);
|
---|
[9233] | 384 |
|
---|
[17142] | 385 |
|
---|
| 386 | # Read in the collection configuration file.
|
---|
| 387 | ($configfilename, $gs_mode) = &colcfg::get_collect_cfg_name($out);
|
---|
| 388 |
|
---|
| 389 | if ($gs_mode eq "gs2") {
|
---|
| 390 | $collectcfg = &colcfg::read_collect_cfg ($configfilename);
|
---|
| 391 | } elsif ($gs_mode eq "gs3") {
|
---|
| 392 | $collectcfg = &colcfg::read_collection_cfg_xml ($configfilename);
|
---|
| 393 | }
|
---|
[14935] | 394 |
|
---|
[17142] | 395 | if (defined $collectcfg->{'importdir'} && $importdir eq "") {
|
---|
| 396 | $importdir = $collectcfg->{'importdir'};
|
---|
| 397 | }
|
---|
| 398 | if (defined $collectcfg->{'exportdir'} && $exportdir eq "") {
|
---|
| 399 | $exportdir = $collectcfg->{'exportdir'};
|
---|
| 400 | }
|
---|
[14935] | 401 |
|
---|
[17142] | 402 | # fill in the default import and export directories if none
|
---|
| 403 | # were supplied, turn all \ into / and remove trailing /
|
---|
| 404 | $importdir = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "import") if $importdir eq "";
|
---|
| 405 | $importdir =~ s/[\\\/]+/\//g;
|
---|
| 406 | $importdir =~ s/\/$//;
|
---|
| 407 | if (!-e $importdir) {
|
---|
| 408 | &gsprintf($out, "{import.no_import_dir}\n\n", $importdir);
|
---|
| 409 | die "\n";
|
---|
| 410 | }
|
---|
[14925] | 411 |
|
---|
[17142] | 412 | $exportdir = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "export") if $exportdir eq "";
|
---|
| 413 | $exportdir =~ s/[\\\/]+/\//g;
|
---|
| 414 | $exportdir =~ s/\/$//;
|
---|
| 415 |
|
---|
| 416 | my $plugins = [];
|
---|
| 417 | if (defined $collectcfg->{'plugin'}) {
|
---|
| 418 | $plugins = $collectcfg->{'plugin'};
|
---|
| 419 | }
|
---|
| 420 | # some global options for the plugins
|
---|
| 421 | my @global_opts = ();
|
---|
[14935] | 422 |
|
---|
[17142] | 423 | if ($verbosity !~ /\d+/) {
|
---|
| 424 | if (defined $collectcfg->{'verbosity'} && $collectcfg->{'verbosity'} =~ /\d+/) {
|
---|
| 425 | $verbosity = $collectcfg->{'verbosity'};
|
---|
| 426 | } else {
|
---|
| 427 | $verbosity = 2; # the default
|
---|
| 428 | }
|
---|
| 429 | }
|
---|
| 430 |
|
---|
| 431 | if (defined $collectcfg->{'gzip'} && !$gzip) {
|
---|
| 432 | if ($collectcfg->{'gzip'} =~ /^true$/i) {
|
---|
| 433 | $gzip = 1;
|
---|
| 434 | }
|
---|
| 435 | }
|
---|
| 436 | if ($maxdocs !~ /\-?\d+/) {
|
---|
| 437 | if (defined $collectcfg->{'maxdocs'} && $collectcfg->{'maxdocs'} =~ /\-?\d+/) {
|
---|
| 438 | $maxdocs = $collectcfg->{'maxdocs'};
|
---|
| 439 | } else {
|
---|
| 440 | $maxdocs = -1; # the default
|
---|
| 441 | }
|
---|
| 442 | }
|
---|
| 443 |
|
---|
| 444 | if (!defined $OIDtype || ($OIDtype !~ /^(hash|incremental|assigned|dirname)$/)) {
|
---|
| 445 | if (defined $collectcfg->{'OIDtype'} && $collectcfg->{'OIDtype'} =~ /^(hash|incremental|assigned|dirname)$/) {
|
---|
| 446 | $OIDtype = $collectcfg->{'OIDtype'};
|
---|
| 447 | } else {
|
---|
| 448 | $OIDtype = "hash"; # the default
|
---|
| 449 | }
|
---|
| 450 | }
|
---|
[14935] | 451 |
|
---|
[17142] | 452 | if (defined $collectcfg->{'debug'} && $collectcfg->{'debug'} =~ /^true$/i) {
|
---|
| 453 | $debug = 1;
|
---|
| 454 | }
|
---|
| 455 | if (defined $collectcfg->{'gli'} && $collectcfg->{'gli'} =~ /^true$/i) {
|
---|
| 456 | $gli = 1;
|
---|
| 457 | }
|
---|
| 458 | $gli = 0 unless defined $gli;
|
---|
[14935] | 459 |
|
---|
[17142] | 460 | # check keepold and removeold
|
---|
| 461 | ($removeold, $keepold, $incremental) = &scriptutil::check_removeold_and_keepold($removeold, $keepold, $incremental, "export", $collectcfg);
|
---|
[10417] | 462 |
|
---|
[17142] | 463 | print STDERR "<export>\n" if $gli;
|
---|
| 464 |
|
---|
| 465 | my $manifest_lookup = new manifest();
|
---|
| 466 | if ($manifest ne "") {
|
---|
| 467 | my $manifest_filename = $manifest;
|
---|
[10417] | 468 |
|
---|
[17142] | 469 | if ($manifest_filename !~ m/^[\\\/]/) {
|
---|
| 470 | $manifest_filename = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, $manifest_filename);
|
---|
| 471 | }
|
---|
[9233] | 472 |
|
---|
[17142] | 473 | $manifest =~ s/[\\\/]+/\//g;
|
---|
| 474 | $manifest =~ s/\/$//;
|
---|
| 475 |
|
---|
| 476 | $manifest_lookup->parse($manifest_filename);
|
---|
| 477 | }
|
---|
| 478 |
|
---|
| 479 | # load all the plugins
|
---|
| 480 | $pluginfo = &plugin::load_plugins ($plugins, $verbosity, $out, $faillog, \@global_opts);
|
---|
[9233] | 481 |
|
---|
[17142] | 482 | if (scalar(@$pluginfo) == 0) {
|
---|
| 483 | &gsprintf($out, "{import.no_plugins_loaded}\n");
|
---|
| 484 | die "\n";
|
---|
| 485 | }
|
---|
| 486 |
|
---|
| 487 | # remove the old contents of the export directory if needed
|
---|
| 488 | if ($removeold && -e $exportdir) {
|
---|
| 489 | &gsprintf($out, "{export.removing_export}\n");
|
---|
| 490 | &util::rm_r ($exportdir);
|
---|
| 491 | }
|
---|
| 492 |
|
---|
| 493 | # create the export dir if needed
|
---|
| 494 | &util::mk_all_dir($exportdir);
|
---|
| 495 |
|
---|
| 496 | # read the export information file
|
---|
| 497 | # If saveas=DSpace, a "contents" file will be created, otherwise "export.inf"
|
---|
| 498 |
|
---|
| 499 | # the plugouts should be doing this!!
|
---|
| 500 | if ($saveas eq "DSpace"){
|
---|
[18440] | 501 | $expinfo_doc_filename = &util::filename_cat ($exportdir, "contents");
|
---|
[17142] | 502 | } elsif ($saveas =~ m/^.*METS$/ || $saveas eq "MARC" ) {
|
---|
[18440] | 503 | ## $expinfo_doc_filename = &util::filename_cat ($exportdir, "export.inf");
|
---|
[18660] | 504 | my $doc_db = "archiveinf-doc";
|
---|
[18440] | 505 | $expinfo_doc_filename = &util::filename_cat ($exportdir, $doc_db);
|
---|
[18660] | 506 | &util::rename_gdbm_file($expinfo_doc_filename); # ensures gdb in case we have an existing legacy ldb one - can this happen?
|
---|
| 507 | $expinfo_doc_filename .= ".gdb";
|
---|
| 508 |
|
---|
[17142] | 509 | }
|
---|
[9233] | 510 |
|
---|
[17142] | 511 | $export_info = new arcinfo();
|
---|
[18440] | 512 | $export_info -> load_info ($expinfo_doc_filename);
|
---|
[9233] | 513 |
|
---|
[17142] | 514 | my ($plugout);
|
---|
| 515 | if (defined $collectcfg->{'plugout'} && $collectcfg->{'plugout'} =~ /^(.*METS|DSpace|MARCXML)Plugout/) {
|
---|
| 516 | $plugout = $collectcfg->{'plugout'};
|
---|
| 517 | }
|
---|
| 518 | else{
|
---|
| 519 | if ($saveas !~ /^(.*METS|DSpace|MARCXML)$/) {
|
---|
| 520 | push @$plugout,"GreenstoneMETSPlugout";
|
---|
| 521 | }
|
---|
| 522 | else{
|
---|
| 523 | push @$plugout,$saveas."Plugout";
|
---|
| 524 | }
|
---|
| 525 | }
|
---|
| 526 |
|
---|
| 527 | my $plugout_name = $plugout->[0];
|
---|
[9233] | 528 |
|
---|
[17142] | 529 | push @$plugout,("-output_info",$export_info) if (defined $export_info);
|
---|
| 530 | push @$plugout,("-verbosity",$verbosity) if (defined $verbosity);
|
---|
| 531 | push @$plugout,("-debug") if ($debug);
|
---|
| 532 | push @$plugout,("-gzip_output",$gzip) if (defined $gzip);
|
---|
| 533 | push @$plugout,("-output_handle",$out) if (defined $out);
|
---|
| 534 | push @$plugout,("-xslt_file",$xsltfile) if (defined $xsltfile);
|
---|
| 535 | push @$plugout,("-group") if ($group_marc && $plugout_name =~ m/^MARCXMLPlugout$/);
|
---|
| 536 | push @$plugout,("-mapping_file",$mapping_file) if (defined $mapping_file && $plugout_name =~ m/^MARCXMLPlugout$/);
|
---|
| 537 | push @$plugout,("-xslt_mets",$xslt_mets) if (defined $xslt_mets && $plugout_name =~ m/^.*METSPlugout$/);
|
---|
| 538 | push @$plugout,("-xslt_txt",$xslt_txt) if (defined $xslt_txt && $plugout_name =~ m/^.*METSPlugout$/);
|
---|
| 539 | push @$plugout,("-fedora_namespace",$fedora_namespace) if (defined $fedora_namespace && $plugout_name eq "FedoraMETSPlugout");
|
---|
| 540 |
|
---|
| 541 | $processor = &plugout::load_plugout($plugout);
|
---|
| 542 | $processor->setoutputdir ($exportdir);
|
---|
[9233] | 543 |
|
---|
[17142] | 544 | $processor->set_OIDtype ($OIDtype, $OIDmetadata);
|
---|
[13169] | 545 |
|
---|
[17142] | 546 | &plugin::begin($pluginfo, $importdir, $processor, $maxdocs, $gli);
|
---|
[13169] | 547 |
|
---|
[17142] | 548 | if ($manifest eq "") {
|
---|
| 549 | # process the import directory
|
---|
| 550 | my $block_hash = {};
|
---|
| 551 | my $metadata = {};
|
---|
| 552 | # gobal blocking pass may set up some metadata
|
---|
| 553 | &plugin::file_block_read($pluginfo, $importdir, "", $block_hash, $metadata, $gli);
|
---|
| 554 | &plugin::read ($pluginfo, $importdir, "", $block_hash, $metadata, $processor, $maxdocs, 0, $gli);
|
---|
| 555 | }
|
---|
| 556 | else {
|
---|
| 557 | # process any files marked for exporting
|
---|
[18440] | 558 | foreach my $file (keys %{$manifest_lookup->{'index'}}) {
|
---|
[17142] | 559 | &plugin::read ($pluginfo, $importdir, $file, {}, {}, $processor, $maxdocs, 0, $gli);
|
---|
| 560 | }
|
---|
| 561 | }
|
---|
[14733] | 562 |
|
---|
[17142] | 563 | if ($saveas eq "FedoraMETS") {
|
---|
| 564 | # create collection "doc obj" for Fedora that contains
|
---|
| 565 | # collection-level metadata
|
---|
| 566 |
|
---|
| 567 | my $doc_obj = new doc($configfilename,"nonindexed_doc");
|
---|
| 568 | $doc_obj->set_OID("collection");
|
---|
| 569 |
|
---|
| 570 | my $col_name = undef;
|
---|
| 571 | my $col_meta = $collectcfg->{'collectionmeta'};
|
---|
| 572 |
|
---|
| 573 | if (defined $col_meta) {
|
---|
[9233] | 574 |
|
---|
[17142] | 575 | store_collectionmeta($col_meta,"collectionname",$doc_obj); # in GS3 this is a collection's name
|
---|
| 576 | store_collectionmeta($col_meta,"collectionextra",$doc_obj); # in GS3 this is a collection's description
|
---|
[13169] | 577 |
|
---|
[17142] | 578 | }
|
---|
| 579 | $processor->process($doc_obj);
|
---|
| 580 | }
|
---|
[13169] | 581 |
|
---|
[17142] | 582 | &plugin::end($pluginfo, $processor);
|
---|
| 583 |
|
---|
| 584 | &plugin::deinit($pluginfo, $processor);
|
---|
[13169] | 585 |
|
---|
[17142] | 586 | # write out the export information file
|
---|
| 587 | #$processor->close_file_output() if $groupsize > 1;
|
---|
| 588 | $processor->close_group_output() if $processor->is_group();
|
---|
[18440] | 589 |
|
---|
| 590 | if (($saveas =~ m/^.*METS$/) || ($saveas eq "MARC")) {
|
---|
| 591 | # Not all export types need this (e.g. DSpace)
|
---|
| 592 | $export_info->save_info($expinfo_doc_filename);
|
---|
[17142] | 593 | }
|
---|
[9233] | 594 |
|
---|
[17142] | 595 | # write out export stats
|
---|
| 596 | my $close_stats = 0;
|
---|
| 597 | if ($statsfile !~ /^(STDERR|STDOUT)$/i) {
|
---|
| 598 | if (open (STATS, ">$statsfile")) {
|
---|
| 599 | $statsfile = 'import::STATS';
|
---|
| 600 | $close_stats = 1;
|
---|
| 601 | } else {
|
---|
| 602 | &gsprintf($out, "{import.cannot_open_stats_file}", $statsfile);
|
---|
| 603 | &gsprintf($out, "{import.stats_backup}\n");
|
---|
| 604 | $statsfile = 'STDERR';
|
---|
| 605 | }
|
---|
| 606 | }
|
---|
[14935] | 607 |
|
---|
[17142] | 608 | &gsprintf($out, "\n");
|
---|
| 609 | &gsprintf($out, "*********************************************\n");
|
---|
| 610 | &gsprintf($out, "{export.complete}\n");
|
---|
| 611 | &gsprintf($out, "*********************************************\n");
|
---|
| 612 |
|
---|
| 613 | &plugin::write_stats($pluginfo, $statsfile, $faillogname, $gli);
|
---|
| 614 | if ($close_stats) {
|
---|
| 615 | close STATS;
|
---|
| 616 | }
|
---|
| 617 |
|
---|
| 618 | close OUT if $close_out;
|
---|
| 619 | close FAILLOG;
|
---|
| 620 | }
|
---|
[16425] | 621 |
|
---|
[14935] | 622 |
|
---|
[17142] | 623 | sub store_collectionmeta
|
---|
| 624 | {
|
---|
| 625 | my ($collectionmeta,$field,$doc_obj) = @_;
|
---|
[10162] | 626 |
|
---|
[17142] | 627 | my $section = $doc_obj->get_top_section();
|
---|
[9951] | 628 |
|
---|
[17142] | 629 | my $field_hash = $collectionmeta->{$field};
|
---|
[9951] | 630 |
|
---|
[17142] | 631 | foreach my $k (keys %$field_hash)
|
---|
| 632 | {
|
---|
| 633 | my $val = $field_hash->{$k};
|
---|
[9951] | 634 |
|
---|
[17142] | 635 | ### print STDERR "*** $k = $field_hash->{$k}\n";
|
---|
[9951] | 636 |
|
---|
[17142] | 637 | my $md_label = "ex.$field";
|
---|
[9951] | 638 |
|
---|
[8879] | 639 |
|
---|
[17142] | 640 | if ($k =~ m/^\[l=(.*?)\]$/)
|
---|
| 641 | {
|
---|
| 642 |
|
---|
| 643 | my $md_suffix = $1;
|
---|
| 644 | $md_label .= "^$md_suffix";
|
---|
[9951] | 645 | }
|
---|
| 646 |
|
---|
[9233] | 647 |
|
---|
[17142] | 648 | $doc_obj->add_utf8_metadata($section,$md_label, $val);
|
---|
| 649 |
|
---|
| 650 | # see cfgread4gs3.pm: GS2's "collectionextra" is called "description" in GS3,
|
---|
| 651 | # while "collectionname" in GS2 is called "name" in GS3.
|
---|
| 652 | # Variable $nameMap variable in cfgread4gs3.pm maps between GS2 and GS3
|
---|
| 653 | if (($md_label eq "ex.collectionname^en") || ($md_label eq "ex.collectionname"))
|
---|
| 654 | {
|
---|
| 655 | $doc_obj->add_utf8_metadata($section,"dc.Title", $val);
|
---|
| 656 | }
|
---|
[8879] | 657 |
|
---|
[17142] | 658 | }
|
---|
[8879] | 659 | }
|
---|
[17142] | 660 |
|
---|
| 661 |
|
---|
| 662 |
|
---|
| 663 |
|
---|