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) 2004 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 |
|
---|
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");
|
---|
39 | unshift (@INC, "$ENV{'GSDLHOME'}/perllib/plugouts");
|
---|
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");
|
---|
48 | unshift (@INC, "$ext_prefix/perllib/plugins");
|
---|
49 | unshift (@INC, "$ext_prefix/perllib/plugouts");
|
---|
50 | }
|
---|
51 | }
|
---|
52 | }
|
---|
53 |
|
---|
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 |
|
---|
58 | use arcinfo;
|
---|
59 | use colcfg;
|
---|
60 | use plugin;
|
---|
61 | use plugout;
|
---|
62 | use manifest;
|
---|
63 | use util;
|
---|
64 | use scriptutil;
|
---|
65 | use FileHandle;
|
---|
66 | use gsprintf 'gsprintf';
|
---|
67 | use printusage;
|
---|
68 | use parse2;
|
---|
69 |
|
---|
70 |
|
---|
71 | my $oidtype_list =
|
---|
72 | [ { 'name' => "hash",
|
---|
73 | 'desc' => "{import.OIDtype.hash}" },
|
---|
74 | { 'name' => "assigned",
|
---|
75 | 'desc' => "{import.OIDtype.assigned}" },
|
---|
76 | { 'name' => "incremental",
|
---|
77 | 'desc' => "{import.OIDtype.incremental}" },
|
---|
78 | { 'name' => "dirname",
|
---|
79 | 'desc' => "{import.OIDtype.dirname}" } ];
|
---|
80 |
|
---|
81 | # what format to export as
|
---|
82 | my $saveas_list =
|
---|
83 | [ { 'name' => "GreenstoneMETS",
|
---|
84 | 'desc' => "{export.saveas.GreenstoneMETS}"},
|
---|
85 | { 'name' => "FedoraMETS",
|
---|
86 | 'desc' => "{export.saveas.FedoraMETS}"},
|
---|
87 | { 'name' => "MARCXML",
|
---|
88 | 'desc' => "{export.saveas.MARCXML}"},
|
---|
89 | { 'name' => "DSpace",
|
---|
90 | 'desc' => "{export.saveas.DSpace}" }
|
---|
91 | ];
|
---|
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
|
---|
97 | # type: The type of control used to represent the argument. Options include: string, int, flag, regexp, metadata, language, enum etc
|
---|
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 |
|
---|
102 | my $saveas_argument =
|
---|
103 | { 'name' => "saveas",
|
---|
104 | 'desc' => "{export.saveas}",
|
---|
105 | 'type' => "enum",
|
---|
106 | 'list' => $saveas_list,
|
---|
107 | 'deft' => "GreenstoneMETS",
|
---|
108 | 'reqd' => "no",
|
---|
109 | 'modegli' => "3" };
|
---|
110 |
|
---|
111 |
|
---|
112 | my $arguments =
|
---|
113 | [
|
---|
114 | $saveas_argument,
|
---|
115 | { 'name' => "exportdir",
|
---|
116 | 'desc' => "{export.exportdir}",
|
---|
117 | 'type' => "string",
|
---|
118 | 'reqd' => "no",
|
---|
119 | 'hiddengli' => "yes" },
|
---|
120 | { 'name' => "importdir",
|
---|
121 | 'desc' => "{import.importdir}",
|
---|
122 | 'type' => "string",
|
---|
123 | 'reqd' => "no",
|
---|
124 | 'hiddengli' => "yes" },
|
---|
125 | { 'name' => "collectdir",
|
---|
126 | 'desc' => "{export.collectdir}",
|
---|
127 | 'type' => "string",
|
---|
128 | # parsearg left "" as default
|
---|
129 | #'deft' => &util::filename_cat ($ENV{'GSDLHOME'}, "collect"),
|
---|
130 | 'deft' => "",
|
---|
131 | 'reqd' => "no",
|
---|
132 | 'hiddengli' => "yes" },
|
---|
133 | { 'name' => "site",
|
---|
134 | 'desc' => "{import.site}",
|
---|
135 | 'type' => "string",
|
---|
136 | 'deft' => "",
|
---|
137 | 'reqd' => "no",
|
---|
138 | 'hiddengli' => "yes" },
|
---|
139 | { 'name' => "manifest",
|
---|
140 | 'desc' => "{import.manifest}",
|
---|
141 | 'type' => "string",
|
---|
142 | 'deft' => "",
|
---|
143 | 'reqd' => "no",
|
---|
144 | 'hiddengli' => "yes" },
|
---|
145 | { 'name' => "listall",
|
---|
146 | 'desc' => "{export.listall}",
|
---|
147 | 'type' => "flag",
|
---|
148 | 'reqd' => "no" },
|
---|
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",
|
---|
157 | 'deft' => "",
|
---|
158 | 'reqd' => "no",
|
---|
159 | 'modegli' => "3" },
|
---|
160 | # does this make sense?
|
---|
161 | # { 'name' => "incremental",
|
---|
162 | # 'desc' => "{import.incremental}",
|
---|
163 | # 'type' => "flag",
|
---|
164 | # 'hiddengli' => "yes" },
|
---|
165 | { 'name' => "keepold",
|
---|
166 | 'desc' => "{export.keepold}",
|
---|
167 | 'type' => "flag",
|
---|
168 | 'reqd' => "no",
|
---|
169 | 'hiddengli' => "yes" },
|
---|
170 | { 'name' => "removeold",
|
---|
171 | 'desc' => "{export.removeold}",
|
---|
172 | 'type' => "flag",
|
---|
173 | 'reqd' => "no",
|
---|
174 | 'modegli' => "3" },
|
---|
175 | { 'name' => "language",
|
---|
176 | 'desc' => "{scripts.language}",
|
---|
177 | 'type' => "string",
|
---|
178 | 'reqd' => "no",
|
---|
179 | 'modegli' => "3" },
|
---|
180 | { 'name' => "maxdocs",
|
---|
181 | 'desc' => "{export.maxdocs}",
|
---|
182 | 'type' => "int",
|
---|
183 | 'reqd' => "no",
|
---|
184 | 'range' => "1,",
|
---|
185 | 'modegli' => "1" },
|
---|
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",
|
---|
193 | 'modegli' => "2" },
|
---|
194 | { 'name' => "OIDmetadata",
|
---|
195 | 'desc' => "{import.OIDmetadata}",
|
---|
196 | 'type' => "string",
|
---|
197 | #'type' => "metadata", #doesn't work properly in GLI
|
---|
198 | 'deft' => "dc.Identifier",
|
---|
199 | 'reqd' => "no",
|
---|
200 | 'modegli' => "2" },
|
---|
201 | { 'name' => "out",
|
---|
202 | 'desc' => "{export.out}",
|
---|
203 | 'type' => "string",
|
---|
204 | 'deft' => "STDERR",
|
---|
205 | 'reqd' => "no",
|
---|
206 | 'hiddengli' => "yes" },
|
---|
207 | { 'name' => "statsfile",
|
---|
208 | 'desc' => "{export.statsfile}",
|
---|
209 | 'type' => "string",
|
---|
210 | 'deft' => "STDERR",
|
---|
211 | 'reqd' => "no",
|
---|
212 | 'hiddengli' => "yes" },
|
---|
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" },
|
---|
228 | { 'name' => "fedora_namespace",
|
---|
229 | 'desc' => "{FedoraMETSPlugout.fedora_namespace}",
|
---|
230 | 'type' => "string",
|
---|
231 | 'deft' => "greenstone",
|
---|
232 | 'reqd' => "no",
|
---|
233 | 'hiddengli' => "no" },
|
---|
234 | { 'name' => "mapping_file",
|
---|
235 | 'desc' => "{MARCXMLPlugout.mapping_file}",
|
---|
236 | 'type' => "string",
|
---|
237 | 'reqd' => "no",
|
---|
238 | 'hiddengli' => "no" },
|
---|
239 | { 'name' => "group_marc",
|
---|
240 | 'desc' => "{MARCXMLPlugout.group}",
|
---|
241 | 'type' => "flag",
|
---|
242 | 'reqd' => "no",
|
---|
243 | 'hiddengli' => "no" },
|
---|
244 | { 'name' => "verbosity",
|
---|
245 | 'desc' => "{export.verbosity}",
|
---|
246 | 'type' => "int",
|
---|
247 | 'range' => "0,3",
|
---|
248 | 'deft' => "2",
|
---|
249 | 'reqd' => "no",
|
---|
250 | 'modegli' => "3" },
|
---|
251 | { 'name' => "gli",
|
---|
252 | 'desc' => "{scripts.gli}",
|
---|
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 | ];
|
---|
262 |
|
---|
263 | my $options = { 'name' => "export.pl",
|
---|
264 | 'desc' => "{export.desc}",
|
---|
265 | 'args' => $arguments };
|
---|
266 |
|
---|
267 | my $listall_options = { 'name' => "export.pl",
|
---|
268 | 'desc' => "{export.desc}",
|
---|
269 | 'args' => [ $saveas_argument ] };
|
---|
270 |
|
---|
271 |
|
---|
272 | &main();
|
---|
273 |
|
---|
274 | sub main {
|
---|
275 | # params
|
---|
276 | my ($language, $verbosity, $debug,
|
---|
277 | $collectdir, $importdir, $exportdir, $site, $manifest,
|
---|
278 | $incremental, $keepold, $removeold,
|
---|
279 | $saveas,
|
---|
280 | $OIDtype, $OIDmetadata,
|
---|
281 | $maxdocs, $statsfile,
|
---|
282 | $out, $faillog, $gli, $listall,
|
---|
283 | # plugout specific ones
|
---|
284 | $mapping_file, $xsltfile,
|
---|
285 | $xslt_mets, $xslt_txt, $fedora_namespace, $group_marc);
|
---|
286 |
|
---|
287 | my $xml = 0;
|
---|
288 |
|
---|
289 | # other vars
|
---|
290 | my ($configfilename, $collection, $collectcfg,
|
---|
291 | $expinfo_doc_filename, $export_info,
|
---|
292 | $gs_mode,
|
---|
293 | $processor, $pluginfo);
|
---|
294 |
|
---|
295 | my $service = "export";
|
---|
296 |
|
---|
297 | my $hashParsingResult = {};
|
---|
298 | # general options available to all plugins
|
---|
299 | my $intArgLeftinAfterParsing = parse2::parse(\@ARGV,$arguments,$hashParsingResult,"allow_extra_options");
|
---|
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 |
|
---|
308 | foreach my $strVariable (keys %$hashParsingResult)
|
---|
309 | {
|
---|
310 | eval "\$$strVariable = \$hashParsingResult->{\"\$strVariable\"}";
|
---|
311 | }
|
---|
312 |
|
---|
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;
|
---|
317 |
|
---|
318 | # If $language has been specified, load the appropriate resource bundle
|
---|
319 | # (Otherwise, the default resource bundle will be loaded automatically)
|
---|
320 | if ($language && $language =~ /\S/) {
|
---|
321 | &gsprintf::load_language_specific_resource_bundle($language);
|
---|
322 | }
|
---|
323 |
|
---|
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 | }
|
---|
334 |
|
---|
335 | if ($xml) {
|
---|
336 | &PrintUsage::print_xml_usage($options);
|
---|
337 | die "\n";
|
---|
338 | }
|
---|
339 |
|
---|
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 | {
|
---|
350 | &PrintUsage::print_txt_usage($options, "{export.params}");
|
---|
351 | die "\n";
|
---|
352 | }
|
---|
353 |
|
---|
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 |
|
---|
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);
|
---|
381 |
|
---|
382 | # Read in the collection configuration file.
|
---|
383 | ($configfilename, $gs_mode) = &colcfg::get_collect_cfg_name($out);
|
---|
384 |
|
---|
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 | }
|
---|
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 | # 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 | }
|
---|
411 |
|
---|
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 = ();
|
---|
422 |
|
---|
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 | }
|
---|
451 |
|
---|
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;
|
---|
459 |
|
---|
460 | # check keepold and removeold
|
---|
461 | ($removeold, $keepold, $incremental) = &scriptutil::check_removeold_and_keepold($removeold, $keepold, $incremental, "export", $collectcfg);
|
---|
462 |
|
---|
463 | print STDERR "<export>\n" if $gli;
|
---|
464 |
|
---|
465 | my $manifest_lookup = new manifest();
|
---|
466 | if ($manifest ne "") {
|
---|
467 | my $manifest_filename = $manifest;
|
---|
468 |
|
---|
469 | if ($manifest_filename !~ m/^[\\\/]/) {
|
---|
470 | $manifest_filename = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, $manifest_filename);
|
---|
471 | }
|
---|
472 |
|
---|
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);
|
---|
481 |
|
---|
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"){
|
---|
501 | $expinfo_doc_filename = &util::filename_cat ($exportdir, "contents");
|
---|
502 | } elsif ($saveas =~ m/^.*METS$/ || $saveas eq "MARC" ) {
|
---|
503 | ## $expinfo_doc_filename = &util::filename_cat ($exportdir, "export.inf");
|
---|
504 | my $doc_db = "archiveinf-doc";
|
---|
505 | $expinfo_doc_filename = &util::filename_cat ($exportdir, $doc_db);
|
---|
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 |
|
---|
509 | }
|
---|
510 |
|
---|
511 | $export_info = new arcinfo();
|
---|
512 | $export_info -> load_info ($expinfo_doc_filename);
|
---|
513 |
|
---|
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];
|
---|
528 |
|
---|
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);
|
---|
543 |
|
---|
544 | $processor->set_OIDtype ($OIDtype, $OIDmetadata);
|
---|
545 |
|
---|
546 | &plugin::begin($pluginfo, $importdir, $processor, $maxdocs, $gli);
|
---|
547 |
|
---|
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
|
---|
558 | foreach my $file (keys %{$manifest_lookup->{'index'}}) {
|
---|
559 | &plugin::read ($pluginfo, $importdir, $file, {}, {}, $processor, $maxdocs, 0, $gli);
|
---|
560 | }
|
---|
561 | }
|
---|
562 |
|
---|
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) {
|
---|
574 |
|
---|
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
|
---|
577 |
|
---|
578 | }
|
---|
579 | $processor->process($doc_obj);
|
---|
580 | }
|
---|
581 |
|
---|
582 | &plugin::end($pluginfo, $processor);
|
---|
583 |
|
---|
584 | &plugin::deinit($pluginfo, $processor);
|
---|
585 |
|
---|
586 | # write out the export information file
|
---|
587 | #$processor->close_file_output() if $groupsize > 1;
|
---|
588 | $processor->close_group_output() if $processor->is_group();
|
---|
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);
|
---|
593 | }
|
---|
594 |
|
---|
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 | }
|
---|
607 |
|
---|
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 | }
|
---|
621 |
|
---|
622 |
|
---|
623 | sub store_collectionmeta
|
---|
624 | {
|
---|
625 | my ($collectionmeta,$field,$doc_obj) = @_;
|
---|
626 |
|
---|
627 | my $section = $doc_obj->get_top_section();
|
---|
628 |
|
---|
629 | my $field_hash = $collectionmeta->{$field};
|
---|
630 |
|
---|
631 | foreach my $k (keys %$field_hash)
|
---|
632 | {
|
---|
633 | my $val = $field_hash->{$k};
|
---|
634 |
|
---|
635 | ### print STDERR "*** $k = $field_hash->{$k}\n";
|
---|
636 |
|
---|
637 | my $md_label = "ex.$field";
|
---|
638 |
|
---|
639 |
|
---|
640 | if ($k =~ m/^\[l=(.*?)\]$/)
|
---|
641 | {
|
---|
642 |
|
---|
643 | my $md_suffix = $1;
|
---|
644 | $md_label .= "^$md_suffix";
|
---|
645 | }
|
---|
646 |
|
---|
647 |
|
---|
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 | }
|
---|
657 |
|
---|
658 | }
|
---|
659 | }
|
---|
660 |
|
---|
661 |
|
---|
662 |
|
---|
663 |
|
---|