source: gsdl/trunk/bin/script/export.pl@ 20690

Last change on this file since 20690 was 20690, checked in by kjdon, 15 years ago

added saveas info for a couple of plugout specific options

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 23.2 KB
RevLine 
[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
[20616]29# This program will export a particular collection into a specific Format (e.g. METS or DSpace) by importing then saving as a different format.
[8879]30
31package export;
32
33BEGIN {
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");
[20616]38 unshift (@INC, "$ENV{'GSDLHOME'}/perllib/cpan/perl-5.8");
[8879]39 unshift (@INC, "$ENV{'GSDLHOME'}/perllib/plugins");
[12333]40 unshift (@INC, "$ENV{'GSDLHOME'}/perllib/plugouts");
[14942]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");
[17142]49 unshift (@INC, "$ext_prefix/perllib/plugins");
50 unshift (@INC, "$ext_prefix/perllib/plugouts");
[14942]51 }
52 }
[8879]53}
54
[10340]55use strict;
56no strict 'refs'; # allow filehandles to be variables and vice versa
57no strict 'subs'; # allow barewords (eg STDERR) as function arguments
58
[10162]59use arcinfo;
[8879]60use colcfg;
61use plugin;
[12333]62use plugout;
[14935]63use manifest;
[20616]64use inexport;
[8879]65use util;
[10417]66use scriptutil;
[8879]67use FileHandle;
[14935]68use gsprintf 'gsprintf';
[8879]69use printusage;
[10340]70use parse2;
[8879]71
[10340]72
[8879]73my $oidtype_list =
74 [ { 'name' => "hash",
[12691]75 'desc' => "{import.OIDtype.hash}" },
[14935]76 { 'name' => "assigned",
77 'desc' => "{import.OIDtype.assigned}" },
[8879]78 { 'name' => "incremental",
[12691]79 'desc' => "{import.OIDtype.incremental}" },
80 { 'name' => "dirname",
81 'desc' => "{import.OIDtype.dirname}" } ];
[8879]82
[17142]83# what format to export as
[8879]84my $saveas_list =
[17142]85 [ { 'name' => "GreenstoneMETS",
[14935]86 'desc' => "{export.saveas.GreenstoneMETS}"},
87 { 'name' => "FedoraMETS",
88 'desc' => "{export.saveas.FedoraMETS}"},
[12333]89 { 'name' => "MARCXML",
[17142]90 'desc' => "{export.saveas.MARCXML}"},
91 { 'name' => "DSpace",
92 'desc' => "{export.saveas.DSpace}" }
[12333]93 ];
[8879]94
95
96# Possible attributes for each argument
97# name: The name of the argument
98# desc: A description (or more likely a reference to a description) for this argument
[12361]99# type: The type of control used to represent the argument. Options include: string, int, flag, regexp, metadata, language, enum etc
[8879]100# reqd: Is this argument required?
101# hiddengli: Is this argument hidden in GLI?
102# modegli: The lowest detail mode this argument is visible at in GLI
103
[14935]104my $saveas_argument =
[9233]105 { 'name' => "saveas",
106 'desc' => "{export.saveas}",
107 'type' => "enum",
108 'list' => $saveas_list,
[17142]109 'deft' => "GreenstoneMETS",
[9233]110 'reqd' => "no",
111 'modegli' => "3" };
112
113
[8879]114my $arguments =
[10340]115 [
116 $saveas_argument,
117 { 'name' => "exportdir",
[8879]118 'desc' => "{export.exportdir}",
119 'type' => "string",
120 'reqd' => "no",
121 'hiddengli' => "yes" },
[10340]122 { 'name' => "importdir",
123 'desc' => "{import.importdir}",
124 'type' => "string",
125 'reqd' => "no",
126 'hiddengli' => "yes" },
[8879]127 { 'name' => "collectdir",
128 'desc' => "{export.collectdir}",
129 'type' => "string",
[14925]130 # parsearg left "" as default
131 #'deft' => &util::filename_cat ($ENV{'GSDLHOME'}, "collect"),
[14935]132 'deft' => "",
133 'reqd' => "no",
134 'hiddengli' => "yes" },
[17142]135 { 'name' => "site",
136 'desc' => "{import.site}",
137 'type' => "string",
138 'deft' => "",
139 'reqd' => "no",
140 'hiddengli' => "yes" },
141 { 'name' => "manifest",
[14935]142 'desc' => "{import.manifest}",
143 'type' => "string",
144 'deft' => "",
145 'reqd' => "no",
[8879]146 'hiddengli' => "yes" },
147 { 'name' => "debug",
148 'desc' => "{export.debug}",
149 'type' => "flag",
150 'reqd' => "no",
151 'hiddengli' => "yes" },
152 { 'name' => "faillog",
153 'desc' => "{export.faillog}",
154 'type' => "string",
[10340]155 'deft' => "",
[8879]156 'reqd' => "no",
[18590]157 'modegli' => "3" },
[17142]158 # does this make sense?
[20616]159 { 'name' => "incremental",
160 'desc' => "{import.incremental}",
161 'type' => "flag",
162 'hiddengli' => "yes" },
[8879]163 { 'name' => "keepold",
164 'desc' => "{export.keepold}",
165 'type' => "flag",
166 'reqd' => "no",
[14935]167 'hiddengli' => "yes" },
[10340]168 { 'name' => "removeold",
169 'desc' => "{export.removeold}",
170 'type' => "flag",
171 'reqd' => "no",
[20616]172 'hiddengli' => "yes" },
[8879]173 { 'name' => "language",
174 'desc' => "{scripts.language}",
175 'type' => "string",
176 'reqd' => "no",
[20616]177 'hiddengli' => "yes" },
[8879]178 { 'name' => "maxdocs",
179 'desc' => "{export.maxdocs}",
180 'type' => "int",
181 'reqd' => "no",
182 'range' => "1,",
183 'modegli' => "1" },
[12691]184 { 'name' => "OIDtype",
185 'desc' => "{import.OIDtype}",
186 'type' => "enum",
187 'list' => $oidtype_list,
188 # parsearg left "" as default
189 #'deft' => "hash",
190 'reqd' => "no",
[18590]191 'modegli' => "2" },
[12691]192 { 'name' => "OIDmetadata",
193 'desc' => "{import.OIDmetadata}",
[19625]194 'type' => "string",
195 #'type' => "metadata", #doesn't work properly in GLI
[12691]196 'deft' => "dc.Identifier",
197 'reqd' => "no",
[18590]198 'modegli' => "2" },
[8879]199 { 'name' => "out",
200 'desc' => "{export.out}",
201 'type' => "string",
202 'deft' => "STDERR",
203 'reqd' => "no",
204 'hiddengli' => "yes" },
[9951]205 { 'name' => "statsfile",
206 'desc' => "{export.statsfile}",
207 'type' => "string",
208 'deft' => "STDERR",
209 'reqd' => "no",
210 'hiddengli' => "yes" },
[12333]211 { 'name' => "xsltfile",
212 'desc' => "{BasPlugout.xslt_file}",
213 'type' => "string",
214 'reqd' => "no",
215 'hiddengli' => "yes" },
216 { 'name' => "xslt_txt",
217 'desc' => "{METSPlugout.xslt_txt}",
218 'type' => "string",
219 'reqd' => "no",
220 'hiddengli' => "no" },
221 { 'name' => "xslt_mets",
222 'desc' => "{METSPlugout.xslt_mets}",
223 'type' => "string",
224 'reqd' => "no",
225 'hiddengli' => "no" },
[14935]226 { 'name' => "fedora_namespace",
[20690]227 'desc' => "{FedoraMETSPlugout.fedora_namespace} (-saveas FedoraMETS)",
[14935]228 'type' => "string",
229 'deft' => "greenstone",
230 'reqd' => "no",
231 'hiddengli' => "no" },
[12598]232 { 'name' => "mapping_file",
[20690]233 'desc' => "{MARCXMLPlugout.mapping_file} (-saveas MARCXML)",
[12598]234 'type' => "string",
235 'reqd' => "no",
236 'hiddengli' => "no" },
[12333]237 { 'name' => "group_marc",
[20690]238 'desc' => "{MARCXMLPlugout.group} (-saveas MARCXML)",
[12333]239 'type' => "flag",
240 'reqd' => "no",
241 'hiddengli' => "no" },
[8879]242 { 'name' => "verbosity",
243 'desc' => "{export.verbosity}",
244 'type' => "int",
245 'range' => "0,3",
246 'deft' => "2",
247 'reqd' => "no",
[18590]248 'modegli' => "3" },
[10340]249 { 'name' => "gli",
[17142]250 'desc' => "{scripts.gli}",
[10340]251 'type' => "flag",
252 'reqd' => "no",
253 'hiddengli' => "yes" },
[20616]254 { 'name' => "listall",
255 'desc' => "{export.listall}",
256 'type' => "flag",
257 'reqd' => "no" },
[10340]258 { 'name' => "xml",
259 'desc' => "{scripts.xml}",
260 'type' => "flag",
261 'reqd' => "no",
262 'hiddengli' => "yes" }
263 ];
[8879]264
265my $options = { 'name' => "export.pl",
266 'desc' => "{export.desc}",
267 'args' => $arguments };
268
[9233]269my $listall_options = { 'name' => "export.pl",
270 'desc' => "{export.desc}",
271 'args' => [ $saveas_argument ] };
272
[14935]273
[8879]274&main();
275
276sub main {
[10340]277 # params
[14935]278 my ($language, $verbosity, $debug,
[17142]279 $collectdir, $importdir, $exportdir, $site, $manifest,
[20571]280 $incremental, $incremental_mode, $keepold, $removeold,
[17142]281 $saveas,
[14935]282 $OIDtype, $OIDmetadata,
283 $maxdocs, $statsfile,
[20616]284 $gzip,
[17142]285 $out, $faillog, $gli, $listall,
286 # plugout specific ones
287 $mapping_file, $xsltfile,
[14935]288 $xslt_mets, $xslt_txt, $fedora_namespace, $group_marc);
289
[8879]290 my $xml = 0;
[10340]291
292 # other vars
[17142]293 my ($configfilename, $collection, $collectcfg,
[20616]294 $expinfo_doc_filename, $expinfo_src_filename, $export_info,
[17142]295 $gs_mode,
[14935]296 $processor, $pluginfo);
297
[8879]298 my $service = "export";
299
[10340]300 my $hashParsingResult = {};
301 # general options available to all plugins
302 my $intArgLeftinAfterParsing = parse2::parse(\@ARGV,$arguments,$hashParsingResult,"allow_extra_options");
[12545]303
304 # If parse returns -1 then something has gone wrong
305 if ($intArgLeftinAfterParsing == -1)
306 {
307 &PrintUsage::print_txt_usage($options, "{export.params}");
308 die "\n";
309 }
310
[10340]311 foreach my $strVariable (keys %$hashParsingResult)
312 {
313 eval "\$$strVariable = \$hashParsingResult->{\"\$strVariable\"}";
[8879]314 }
315
[20616]316
[8879]317 # If $language has been specified, load the appropriate resource bundle
318 # (Otherwise, the default resource bundle will be loaded automatically)
[17142]319 if ($language && $language =~ /\S/) {
[8879]320 &gsprintf::load_language_specific_resource_bundle($language);
321 }
322
[9233]323 if ($listall) {
324 if ($xml) {
325 &PrintUsage::print_xml_usage($listall_options);
326 }
327 else
328 {
329 &PrintUsage::print_txt_usage($listall_options,"{export.params}");
330 }
331 die "\n";
332 }
[17142]333
334 if ($xml) {
[8879]335 &PrintUsage::print_xml_usage($options);
336 die "\n";
337 }
338
[17142]339 if ($gli) { # the gli wants strings to be in UTF-8
340 &gsprintf::output_strings_in_UTF8;
341 }
342
343 # now check that we had exactly one leftover arg, which should be
344 # the collection name. We don't want to do this earlier, cos
345 # -xml arg doesn't need a collection name
346 # Or if the user specified -h, then we output the usage also
347 if ($intArgLeftinAfterParsing != 1 || (@ARGV && $ARGV[0] =~ /^\-+h/))
348 {
[10340]349 &PrintUsage::print_txt_usage($options, "{export.params}");
350 die "\n";
351 }
352
[8879]353 my $close_out = 0;
354 if ($out !~ /^(STDERR|STDOUT)$/i) {
355 open (OUT, ">$out") ||
356 (&gsprintf(STDERR, "{common.cannot_open_output_file}\n", $out) && die);
357 $out = 'export::OUT';
358 $close_out = 1;
359 }
360 $out->autoflush(1);
361
[17142]362 # get and check the collection name
363 if (($collection = &colcfg::use_collection($site, @ARGV, $collectdir)) eq "") {
364 &PrintUsage::print_txt_usage($options, "{export.params}");
365 die "\n";
366 }
367 # add collection's perllib dir into include path in
368 # case we have collection specific modules
369 unshift (@INC, "$ENV{'GSDLCOLLECTDIR'}/perllib");
370
371 # check that we can open the faillog
372 if ($faillog eq "") {
373 $faillog = &util::filename_cat($ENV{'GSDLCOLLECTDIR'}, "etc", "fail.log");
374 }
375 open (FAILLOG, ">$faillog") ||
376 (&gsprintf(STDERR, "{export.cannot_open_fail_log}\n", $faillog) && die);
377 my $faillogname = $faillog;
378 $faillog = 'export::FAILLOG';
379 $faillog->autoflush(1);
[12358]380
[17142]381 # Read in the collection configuration file.
382 ($configfilename, $gs_mode) = &colcfg::get_collect_cfg_name($out);
[20098]383 $collectcfg = &colcfg::read_collection_cfg ($configfilename, $gs_mode);
[17142]384
385 if (defined $collectcfg->{'importdir'} && $importdir eq "") {
386 $importdir = $collectcfg->{'importdir'};
387 }
388 if (defined $collectcfg->{'exportdir'} && $exportdir eq "") {
389 $exportdir = $collectcfg->{'exportdir'};
390 }
[14935]391
[17142]392 # fill in the default import and export directories if none
393 # were supplied, turn all \ into / and remove trailing /
394 $importdir = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "import") if $importdir eq "";
395 $importdir =~ s/[\\\/]+/\//g;
396 $importdir =~ s/\/$//;
397 if (!-e $importdir) {
398 &gsprintf($out, "{import.no_import_dir}\n\n", $importdir);
399 die "\n";
400 }
[14925]401
[17142]402 $exportdir = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "export") if $exportdir eq "";
403 $exportdir =~ s/[\\\/]+/\//g;
404 $exportdir =~ s/\/$//;
405
406 my $plugins = [];
407 if (defined $collectcfg->{'plugin'}) {
408 $plugins = $collectcfg->{'plugin'};
409 }
410 # some global options for the plugins
411 my @global_opts = ();
[14935]412
[17142]413 if ($verbosity !~ /\d+/) {
414 if (defined $collectcfg->{'verbosity'} && $collectcfg->{'verbosity'} =~ /\d+/) {
415 $verbosity = $collectcfg->{'verbosity'};
416 } else {
417 $verbosity = 2; # the default
418 }
419 }
420
[20616]421 if (defined $collectcfg->{'manifest'} && $manifest eq "") {
422 $manifest = $collectcfg->{'manifest'};
423 }
[17142]424 if (defined $collectcfg->{'gzip'} && !$gzip) {
425 if ($collectcfg->{'gzip'} =~ /^true$/i) {
426 $gzip = 1;
427 }
428 }
429 if ($maxdocs !~ /\-?\d+/) {
430 if (defined $collectcfg->{'maxdocs'} && $collectcfg->{'maxdocs'} =~ /\-?\d+/) {
431 $maxdocs = $collectcfg->{'maxdocs'};
432 } else {
433 $maxdocs = -1; # the default
434 }
435 }
436
[20616]437 # groupsize is in import - does it make sense here??
438
[17142]439 if (!defined $OIDtype || ($OIDtype !~ /^(hash|incremental|assigned|dirname)$/)) {
440 if (defined $collectcfg->{'OIDtype'} && $collectcfg->{'OIDtype'} =~ /^(hash|incremental|assigned|dirname)$/) {
441 $OIDtype = $collectcfg->{'OIDtype'};
442 } else {
443 $OIDtype = "hash"; # the default
444 }
445 }
[14935]446
[20616]447 if ((!defined $OIDmetadata) || ($OIDmetadata eq "")) {
448 if (defined $collectcfg->{'OIDmetadata'}) {
449 $OIDmetadata = $collectcfg->{'OIDmetadata'};
450 } else {
451 $OIDmetadata = "dc.Identifier"; # the default
452 }
453 }
454
[17142]455 if (defined $collectcfg->{'debug'} && $collectcfg->{'debug'} =~ /^true$/i) {
456 $debug = 1;
457 }
458 if (defined $collectcfg->{'gli'} && $collectcfg->{'gli'} =~ /^true$/i) {
459 $gli = 1;
460 }
461 $gli = 0 unless defined $gli;
[14935]462
[17142]463 # check keepold and removeold
[20571]464 ($removeold, $keepold, $incremental, $incremental_mode)
465 = &scriptutil::check_removeold_and_keepold($removeold, $keepold,
466 $incremental, "export",
467 $collectcfg);
[10417]468
[17142]469 print STDERR "<export>\n" if $gli;
470
471 my $manifest_lookup = new manifest();
472 if ($manifest ne "") {
473 my $manifest_filename = $manifest;
[10417]474
[17142]475 if ($manifest_filename !~ m/^[\\\/]/) {
476 $manifest_filename = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, $manifest_filename);
477 }
[9233]478
[17142]479 $manifest =~ s/[\\\/]+/\//g;
480 $manifest =~ s/\/$//;
481
482 $manifest_lookup->parse($manifest_filename);
483 }
484
485 # load all the plugins
[20571]486 $pluginfo = &plugin::load_plugins ($plugins, $verbosity, $out, $faillog, \@global_opts, $incremental_mode);
[9233]487
[17142]488 if (scalar(@$pluginfo) == 0) {
489 &gsprintf($out, "{import.no_plugins_loaded}\n");
490 die "\n";
491 }
492
493 # remove the old contents of the export directory if needed
[20652]494 if ($removeold) {
495 if (-e $exportdir) {
496 &gsprintf($out, "{export.removing_export}\n");
497 &util::rm_r ($exportdir);
498 }
499 my $tmpdir = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "tmp");
500 $tmpdir =~ s/[\\\/]+/\//g;
501 $tmpdir =~ s/\/$//;
502 if (-e $tmpdir) {
503 &gsprintf($out, "{import.removing_tmpdir}\n");
504 &util::rm_r ($tmpdir);
505 }
[17142]506 }
507
508 # create the export dir if needed
509 &util::mk_all_dir($exportdir);
510
511 # read the export information file
512
513 # the plugouts should be doing this!!
[20652]514## $expinfo_doc_filename = &util::filename_cat ($exportdir, "export.inf");
515 $expinfo_doc_filename = &util::filename_cat ($exportdir,"archiveinf-doc" );
516 &util::rename_gdbm_file($expinfo_doc_filename); # ensures gdb in case we have an existing legacy ldb one - can this happen?
517 $expinfo_doc_filename .= ".gdb";
518
519 $expinfo_src_filename = &util::filename_cat ($exportdir,"archiveinf-src" );
520 &util::rename_gdbm_file($expinfo_src_filename); # ensures gdb in case we have an existing legacy ldb one - can this happen?
521 $expinfo_src_filename .= ".gdb";
[18660]522
[9233]523
[17142]524 $export_info = new arcinfo();
[18440]525 $export_info -> load_info ($expinfo_doc_filename);
[9233]526
[20616]527 if ($manifest eq "") {
528 # Load in list of files in export folder from last export (if present)
529 $export_info->load_prev_import_filelist ($expinfo_src_filename);
530 }
531
[17142]532 my ($plugout);
533 if (defined $collectcfg->{'plugout'} && $collectcfg->{'plugout'} =~ /^(.*METS|DSpace|MARCXML)Plugout/) {
534 $plugout = $collectcfg->{'plugout'};
535 }
536 else{
[20616]537 if ($saveas !~ /^(GreenstoneMETS|FedoraMETS|DSpace|MARCXML)$/) {
[17142]538 push @$plugout,"GreenstoneMETSPlugout";
539 }
540 else{
541 push @$plugout,$saveas."Plugout";
542 }
543 }
544
545 my $plugout_name = $plugout->[0];
[9233]546
[17142]547 push @$plugout,("-output_info",$export_info) if (defined $export_info);
548 push @$plugout,("-verbosity",$verbosity) if (defined $verbosity);
549 push @$plugout,("-debug") if ($debug);
[20616]550 push @$plugout,("-gzip_output") if ($gzip);
[17142]551 push @$plugout,("-output_handle",$out) if (defined $out);
[20319]552 push @$plugout,("-xslt_file",$xsltfile) if (defined $xsltfile && $xsltfile ne "");
[17142]553 push @$plugout,("-group") if ($group_marc && $plugout_name =~ m/^MARCXMLPlugout$/);
[20319]554 push @$plugout,("-mapping_file",$mapping_file) if (defined $mapping_file && $mapping_file ne "" && $plugout_name =~ m/^MARCXMLPlugout$/);
555 push @$plugout,("-xslt_mets",$xslt_mets) if (defined $xslt_mets && $xslt_mets ne "" && $plugout_name =~ m/^.*METSPlugout$/);
556 push @$plugout,("-xslt_txt",$xslt_txt) if (defined $xslt_txt && $xslt_txt ne "" && $plugout_name =~ m/^.*METSPlugout$/);
557 push @$plugout,("-fedora_namespace",$fedora_namespace) if (defined $fedora_namespace && $fedora_namespace ne "" && $plugout_name eq "FedoraMETSPlugout");
[17142]558
559 $processor = &plugout::load_plugout($plugout);
560 $processor->setoutputdir ($exportdir);
[9233]561
[17142]562 $processor->set_OIDtype ($OIDtype, $OIDmetadata);
[13169]563
[17142]564 &plugin::begin($pluginfo, $importdir, $processor, $maxdocs, $gli);
[13169]565
[17142]566 if ($manifest eq "") {
567 # process the import directory
568 my $block_hash = {};
569 my $metadata = {};
570 # gobal blocking pass may set up some metadata
571 &plugin::file_block_read($pluginfo, $importdir, "", $block_hash, $metadata, $gli);
[20616]572 #&plugin::read ($pluginfo, $importdir, "", $block_hash, $metadata, $processor, $maxdocs, 0, $gli);
573 ### section below copied from import.pl
574 if ($incremental) {
575 # equivalent to saying ($keepold && ($incremental_mode eq "all"))
576
577 &inexport::prime_doc_oid_count($exportdir);
578
579
580 # Can now work out which files were new, already existed, and have
581 # been deleted
582
583 &inexport::new_vs_old_import_diff($export_info,$block_hash,$importdir,
584 $exportdir,$verbosity,$incremental_mode);
585
586 my @deleted_files = sort keys %{$block_hash->{'deleted_files'}};
587 # Filter out any in gsdl/tmp area
588 my @filtered_deleted_files = ();
589 my $gsdl_tmp_area = &util::filename_cat($ENV{'GSDLHOME'}, "tmp");
590 my $collect_tmp_area = &util::filename_cat($ENV{'GSDLCOLLECTDIR'}, "tmp");
591 $gsdl_tmp_area = &util::filename_to_regex($gsdl_tmp_area);
592 $collect_tmp_area = &util::filename_to_regex($collect_tmp_area);
593
594
595 foreach my $df (@deleted_files) {
596 next if ($df =~ m/^$gsdl_tmp_area/);
597 next if ($df =~ m/^$collect_tmp_area/);
598
599 push(@filtered_deleted_files,$df);
600 }
601
602
603 @deleted_files = @filtered_deleted_files;
604
605 if (scalar(@deleted_files>0)) {
606 print STDERR "Files deleted since last import:\n ";
607 print STDERR join("\n ",@deleted_files), "\n";
608 }
609
610 my @new_files = sort keys %{$block_hash->{'new_files'}};
611 if (scalar(@new_files>0)) {
612 print STDERR "New files since last import:\n ";
613 print STDERR join("\n ",@new_files), "\n";
614 }
615
616 &inexport::mark_docs_for_deletion($export_info,$block_hash,\@deleted_files,
617 $exportdir,$verbosity);
618
619 &inexport::mark_docs_for_reindex($export_info,$block_hash,
620 $exportdir,$verbosity);
621
622 my @reindex_files = sort keys %{$block_hash->{'reindex_files'}};
623
624 if (scalar(@reindex_files>0)) {
625 print STDERR "Files to reindex since last import:\n ";
626 print STDERR join("\n ",@reindex_files), "\n";
627 }
628
629
630 # not sure if the following will work -- will the metadata data-structure be correctly initialized
631 # in the right order?
632# foreach my $file (@new_files, @reindex_files) {
633# &plugin::read ($pluginfo, $importdir, $file, $block_hash, $metadata, $processor, $maxdocs, 0, $gli);
634# }
635
636
637 # Play it safe, and run through the entire folder, only processing new or edited files
638 &plugin::read ($pluginfo, $importdir, "", $block_hash, $metadata, $processor, $maxdocs, 0, $gli);
639
640 }
641 else {
642 &plugin::read ($pluginfo, $importdir, "", $block_hash, $metadata, $processor, $maxdocs, 0, $gli);
643 }
644
645 ### end copy
[17142]646 }
647 else {
648 # process any files marked for exporting
[18440]649 foreach my $file (keys %{$manifest_lookup->{'index'}}) {
[17142]650 &plugin::read ($pluginfo, $importdir, $file, {}, {}, $processor, $maxdocs, 0, $gli);
651 }
[20616]652
653 my @deleted_files = keys %{$manifest_lookup->{'delete'}};
654
655 &inexport::mark_docs_for_deletion($export_info,{},\@deleted_files,$exportdir);
656
[17142]657 }
[14733]658
[17142]659 if ($saveas eq "FedoraMETS") {
660 # create collection "doc obj" for Fedora that contains
661 # collection-level metadata
662
[20415]663 my $doc_obj = new doc($configfilename,"nonindexed_doc","none");
[17142]664 $doc_obj->set_OID("collection");
665
666 my $col_name = undef;
667 my $col_meta = $collectcfg->{'collectionmeta'};
668
669 if (defined $col_meta) {
[9233]670
[17142]671 store_collectionmeta($col_meta,"collectionname",$doc_obj); # in GS3 this is a collection's name
672 store_collectionmeta($col_meta,"collectionextra",$doc_obj); # in GS3 this is a collection's description
[13169]673
[17142]674 }
675 $processor->process($doc_obj);
676 }
[13169]677
[17142]678 &plugin::end($pluginfo, $processor);
679
680 &plugin::deinit($pluginfo, $processor);
[13169]681
[20616]682 # Store the value of OIDCount (used in doc.pm) so it can be
683 # restored correctly to this value on an incremental build
684 &inexport::store_doc_oid_count($exportdir);
685
[17142]686 # write out the export information file
687 #$processor->close_file_output() if $groupsize > 1;
688 $processor->close_group_output() if $processor->is_group();
[18440]689
[20571]690# if (($saveas =~ m/^.*METS$/) || ($saveas eq "MARCXML")) {
691# # Not all export types need this,
692
693## $export_info->save_info($expinfo_doc_filename);
694# }
695
696
697 # for backwards compatability with archvies.inf file
698 if ($expinfo_doc_filename =~ m/(contents)|(\.inf)$/) {
[18440]699 $export_info->save_info($expinfo_doc_filename);
[17142]700 }
[20571]701 else {
702 $export_info->save_revinfo_gdbm($expinfo_src_filename);
703 }
704
[9233]705
[17142]706 # write out export stats
707 my $close_stats = 0;
708 if ($statsfile !~ /^(STDERR|STDOUT)$/i) {
709 if (open (STATS, ">$statsfile")) {
710 $statsfile = 'import::STATS';
711 $close_stats = 1;
712 } else {
713 &gsprintf($out, "{import.cannot_open_stats_file}", $statsfile);
714 &gsprintf($out, "{import.stats_backup}\n");
715 $statsfile = 'STDERR';
716 }
717 }
[14935]718
[17142]719 &gsprintf($out, "\n");
720 &gsprintf($out, "*********************************************\n");
721 &gsprintf($out, "{export.complete}\n");
722 &gsprintf($out, "*********************************************\n");
723
724 &plugin::write_stats($pluginfo, $statsfile, $faillogname, $gli);
725 if ($close_stats) {
726 close STATS;
727 }
728
729 close OUT if $close_out;
730 close FAILLOG;
731}
[16425]732
[14935]733
[17142]734sub store_collectionmeta
735{
736 my ($collectionmeta,$field,$doc_obj) = @_;
[10162]737
[17142]738 my $section = $doc_obj->get_top_section();
[9951]739
[17142]740 my $field_hash = $collectionmeta->{$field};
[9951]741
[17142]742 foreach my $k (keys %$field_hash)
743 {
744 my $val = $field_hash->{$k};
[9951]745
[17142]746 ### print STDERR "*** $k = $field_hash->{$k}\n";
[9951]747
[17142]748 my $md_label = "ex.$field";
[9951]749
[8879]750
[17142]751 if ($k =~ m/^\[l=(.*?)\]$/)
752 {
753
754 my $md_suffix = $1;
755 $md_label .= "^$md_suffix";
[9951]756 }
757
[9233]758
[17142]759 $doc_obj->add_utf8_metadata($section,$md_label, $val);
760
[20098]761 # see collConfigxml.pm: GS2's "collectionextra" is called "description" in GS3,
[17142]762 # while "collectionname" in GS2 is called "name" in GS3.
[20098]763 # Variable $nameMap variable in collConfigxml.pm maps between GS2 and GS3
[17142]764 if (($md_label eq "ex.collectionname^en") || ($md_label eq "ex.collectionname"))
765 {
766 $doc_obj->add_utf8_metadata($section,"dc.Title", $val);
767 }
[8879]768
[17142]769 }
[8879]770}
[17142]771
772
773
774
Note: See TracBrowser for help on using the repository browser.