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