[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 |
|
---|
| 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");
|
---|
[22331] | 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 | }
|
---|
[21292] | 53 | if (defined $ENV{'GSDL3EXTS'}) {
|
---|
| 54 | my @extensions = split(/:/,$ENV{'GSDL3EXTS'});
|
---|
| 55 | foreach my $e (@extensions) {
|
---|
| 56 | my $ext_prefix = "$ENV{'GSDL3SRCHOME'}/ext/$e";
|
---|
| 57 |
|
---|
| 58 | unshift (@INC, "$ext_prefix/perllib");
|
---|
| 59 | unshift (@INC, "$ext_prefix/perllib/cpan");
|
---|
| 60 | unshift (@INC, "$ext_prefix/perllib/plugins");
|
---|
| 61 | unshift (@INC, "$ext_prefix/perllib/plugouts");
|
---|
| 62 | }
|
---|
| 63 | }
|
---|
| 64 |
|
---|
[8879] | 65 | }
|
---|
| 66 |
|
---|
[10340] | 67 | use strict;
|
---|
[22421] | 68 | #no strict 'refs'; # allow filehandles to be variables and vice versa
|
---|
| 69 | #no strict 'subs'; # allow barewords (eg STDERR) as function arguments
|
---|
[20616] | 70 | use inexport;
|
---|
[8879] | 71 |
|
---|
| 72 |
|
---|
[28639] | 73 |
|
---|
[17142] | 74 | # what format to export as
|
---|
[8879] | 75 | my $saveas_list =
|
---|
[17142] | 76 | [ { 'name' => "GreenstoneMETS",
|
---|
[14935] | 77 | 'desc' => "{export.saveas.GreenstoneMETS}"},
|
---|
| 78 | { 'name' => "FedoraMETS",
|
---|
| 79 | 'desc' => "{export.saveas.FedoraMETS}"},
|
---|
[12333] | 80 | { 'name' => "MARCXML",
|
---|
[17142] | 81 | 'desc' => "{export.saveas.MARCXML}"},
|
---|
| 82 | { 'name' => "DSpace",
|
---|
| 83 | 'desc' => "{export.saveas.DSpace}" }
|
---|
[12333] | 84 | ];
|
---|
[8879] | 85 |
|
---|
| 86 |
|
---|
| 87 | # Possible attributes for each argument
|
---|
| 88 | # name: The name of the argument
|
---|
| 89 | # desc: A description (or more likely a reference to a description) for this argument
|
---|
[12361] | 90 | # type: The type of control used to represent the argument. Options include: string, int, flag, regexp, metadata, language, enum etc
|
---|
[8879] | 91 | # reqd: Is this argument required?
|
---|
| 92 | # hiddengli: Is this argument hidden in GLI?
|
---|
| 93 | # modegli: The lowest detail mode this argument is visible at in GLI
|
---|
| 94 |
|
---|
[14935] | 95 | my $saveas_argument =
|
---|
[9233] | 96 | { 'name' => "saveas",
|
---|
| 97 | 'desc' => "{export.saveas}",
|
---|
| 98 | 'type' => "enum",
|
---|
| 99 | 'list' => $saveas_list,
|
---|
[17142] | 100 | 'deft' => "GreenstoneMETS",
|
---|
[9233] | 101 | 'reqd' => "no",
|
---|
| 102 | 'modegli' => "3" };
|
---|
| 103 |
|
---|
| 104 |
|
---|
[8879] | 105 | my $arguments =
|
---|
[10340] | 106 | [
|
---|
| 107 | $saveas_argument,
|
---|
[28639] | 108 | { 'name' => "saveas_options",
|
---|
| 109 | 'desc' => "{import.saveas_options}",
|
---|
| 110 | 'type' => "string",
|
---|
| 111 | 'reqd' => "no" },
|
---|
[22460] | 112 | { 'name' => "exportdir",
|
---|
[27140] | 113 | 'desc' => "{export.exportdir}",
|
---|
[8879] | 114 | 'type' => "string",
|
---|
| 115 | 'reqd' => "no",
|
---|
| 116 | 'hiddengli' => "yes" },
|
---|
[28639] | 117 | @$inexport::directory_arguments,
|
---|
[12333] | 118 | { 'name' => "xsltfile",
|
---|
| 119 | 'desc' => "{BasPlugout.xslt_file}",
|
---|
| 120 | 'type' => "string",
|
---|
| 121 | 'reqd' => "no",
|
---|
| 122 | 'hiddengli' => "yes" },
|
---|
| 123 | { 'name' => "xslt_txt",
|
---|
| 124 | 'desc' => "{METSPlugout.xslt_txt}",
|
---|
| 125 | 'type' => "string",
|
---|
| 126 | 'reqd' => "no",
|
---|
| 127 | 'hiddengli' => "no" },
|
---|
| 128 | { 'name' => "xslt_mets",
|
---|
| 129 | 'desc' => "{METSPlugout.xslt_mets}",
|
---|
| 130 | 'type' => "string",
|
---|
| 131 | 'reqd' => "no",
|
---|
| 132 | 'hiddengli' => "no" },
|
---|
[14935] | 133 | { 'name' => "fedora_namespace",
|
---|
[20690] | 134 | 'desc' => "{FedoraMETSPlugout.fedora_namespace} (-saveas FedoraMETS)",
|
---|
[14935] | 135 | 'type' => "string",
|
---|
| 136 | 'deft' => "greenstone",
|
---|
| 137 | 'reqd' => "no",
|
---|
| 138 | 'hiddengli' => "no" },
|
---|
[12598] | 139 | { 'name' => "mapping_file",
|
---|
[20690] | 140 | 'desc' => "{MARCXMLPlugout.mapping_file} (-saveas MARCXML)",
|
---|
[12598] | 141 | 'type' => "string",
|
---|
| 142 | 'reqd' => "no",
|
---|
| 143 | 'hiddengli' => "no" },
|
---|
[12333] | 144 | { 'name' => "group_marc",
|
---|
[20690] | 145 | 'desc' => "{MARCXMLPlugout.group} (-saveas MARCXML)",
|
---|
[12333] | 146 | 'type' => "flag",
|
---|
| 147 | 'reqd' => "no",
|
---|
| 148 | 'hiddengli' => "no" },
|
---|
[23828] | 149 | { 'name' => "metadata_prefix",
|
---|
| 150 | 'desc' => "{DSpacePlugout.metadata_prefix} (-saveas DSpace)}",
|
---|
| 151 | 'type' => "string",
|
---|
| 152 | 'reqd' => "no",
|
---|
| 153 | 'hiddengli' => "no" },
|
---|
[20616] | 154 | { 'name' => "listall",
|
---|
| 155 | 'desc' => "{export.listall}",
|
---|
| 156 | 'type' => "flag",
|
---|
| 157 | 'reqd' => "no" },
|
---|
[28639] | 158 | @$inexport::arguments
|
---|
[10340] | 159 | ];
|
---|
[8879] | 160 |
|
---|
| 161 | my $options = { 'name' => "export.pl",
|
---|
| 162 | 'desc' => "{export.desc}",
|
---|
| 163 | 'args' => $arguments };
|
---|
| 164 |
|
---|
[9233] | 165 | my $listall_options = { 'name' => "export.pl",
|
---|
| 166 | 'desc' => "{export.desc}",
|
---|
| 167 | 'args' => [ $saveas_argument ] };
|
---|
| 168 |
|
---|
[14935] | 169 |
|
---|
[8879] | 170 |
|
---|
[22421] | 171 | sub main
|
---|
| 172 | {
|
---|
| 173 | my $inexport = new inexport("export",\@ARGV,$options,$listall_options);
|
---|
[10340] | 174 |
|
---|
[22421] | 175 | my $collection = $inexport->get_collection();
|
---|
[22459] | 176 |
|
---|
| 177 | if (defined $collection) {
|
---|
| 178 | my ($config_filename,$collect_cfg)
|
---|
| 179 | = $inexport->read_collection_cfg($collection,$options);
|
---|
| 180 |
|
---|
[28639] | 181 | &set_collection_options($inexport, $collect_cfg);
|
---|
[12545] | 182 |
|
---|
[22459] | 183 | my $pluginfo = $inexport->process_files($config_filename,$collect_cfg);
|
---|
| 184 |
|
---|
| 185 | $inexport->generate_statistics($pluginfo);
|
---|
| 186 | }
|
---|
[28639] | 187 |
|
---|
| 188 | $inexport->deinit();
|
---|
[17142] | 189 | }
|
---|
[16425] | 190 |
|
---|
[28639] | 191 | sub set_collection_options
|
---|
| 192 | {
|
---|
| 193 | my ($inexport, $collectcfg) = @_;
|
---|
[14935] | 194 |
|
---|
[28639] | 195 | if (!defined $inexport->{'saveas'}) {
|
---|
| 196 | if (defined $collectcfg->{'saveas'}
|
---|
| 197 | && $collectcfg->{'saveas'} =~ /^(GreenstoneMETS|FedoraMETS|MARCXML|DSPace)$/) {
|
---|
| 198 | $inexport->{'saveas'} = $collectcfg->{'saveas'};
|
---|
| 199 | } else {
|
---|
| 200 | $inexport->{'saveas'} = "GreenstoneMETS"; # the default
|
---|
| 201 | }
|
---|
| 202 | }
|
---|
| 203 |
|
---|
| 204 | if (!defined $inexport->{'saveas_options'}) {
|
---|
| 205 | if (defined $collectcfg->{'saveas_options'} ){
|
---|
| 206 | $inexport->{'saveas'} = $collectcfg->{'saveas_options'};
|
---|
| 207 | }
|
---|
| 208 | }
|
---|
| 209 |
|
---|
| 210 | $inexport->set_collection_options($collectcfg);
|
---|
| 211 | }
|
---|
[22421] | 212 | &main();
|
---|
[10162] | 213 |
|
---|
[9951] | 214 |
|
---|
[28639] | 215 |
|
---|
| 216 |
|
---|