source: main/trunk/greenstone2/bin/script/export.pl@ 28639

Last change on this file since 28639 was 28639, checked in by kjdon, 10 years ago

moving common import/export args into inexport.pm. added set_collection_options into import/export.pl so that these files handle their own specific options, while inexport handles the common ones

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 6.3 KB
Line 
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) by importing then saving as a different format.
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");
38# unshift (@INC, "$ENV{'GSDLHOME'}/perllib/cpan/perl-5.8");
39 unshift (@INC, "$ENV{'GSDLHOME'}/perllib/plugins");
40 unshift (@INC, "$ENV{'GSDLHOME'}/perllib/plugouts");
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");
49 unshift (@INC, "$ext_prefix/perllib/plugins");
50 unshift (@INC, "$ext_prefix/perllib/plugouts");
51 }
52 }
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
65}
66
67use strict;
68#no strict 'refs'; # allow filehandles to be variables and vice versa
69#no strict 'subs'; # allow barewords (eg STDERR) as function arguments
70use inexport;
71
72
73
74# what format to export as
75my $saveas_list =
76 [ { 'name' => "GreenstoneMETS",
77 'desc' => "{export.saveas.GreenstoneMETS}"},
78 { 'name' => "FedoraMETS",
79 'desc' => "{export.saveas.FedoraMETS}"},
80 { 'name' => "MARCXML",
81 'desc' => "{export.saveas.MARCXML}"},
82 { 'name' => "DSpace",
83 'desc' => "{export.saveas.DSpace}" }
84 ];
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
90# type: The type of control used to represent the argument. Options include: string, int, flag, regexp, metadata, language, enum etc
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
95my $saveas_argument =
96 { 'name' => "saveas",
97 'desc' => "{export.saveas}",
98 'type' => "enum",
99 'list' => $saveas_list,
100 'deft' => "GreenstoneMETS",
101 'reqd' => "no",
102 'modegli' => "3" };
103
104
105my $arguments =
106 [
107 $saveas_argument,
108 { 'name' => "saveas_options",
109 'desc' => "{import.saveas_options}",
110 'type' => "string",
111 'reqd' => "no" },
112 { 'name' => "exportdir",
113 'desc' => "{export.exportdir}",
114 'type' => "string",
115 'reqd' => "no",
116 'hiddengli' => "yes" },
117 @$inexport::directory_arguments,
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" },
133 { 'name' => "fedora_namespace",
134 'desc' => "{FedoraMETSPlugout.fedora_namespace} (-saveas FedoraMETS)",
135 'type' => "string",
136 'deft' => "greenstone",
137 'reqd' => "no",
138 'hiddengli' => "no" },
139 { 'name' => "mapping_file",
140 'desc' => "{MARCXMLPlugout.mapping_file} (-saveas MARCXML)",
141 'type' => "string",
142 'reqd' => "no",
143 'hiddengli' => "no" },
144 { 'name' => "group_marc",
145 'desc' => "{MARCXMLPlugout.group} (-saveas MARCXML)",
146 'type' => "flag",
147 'reqd' => "no",
148 'hiddengli' => "no" },
149 { 'name' => "metadata_prefix",
150 'desc' => "{DSpacePlugout.metadata_prefix} (-saveas DSpace)}",
151 'type' => "string",
152 'reqd' => "no",
153 'hiddengli' => "no" },
154 { 'name' => "listall",
155 'desc' => "{export.listall}",
156 'type' => "flag",
157 'reqd' => "no" },
158 @$inexport::arguments
159 ];
160
161my $options = { 'name' => "export.pl",
162 'desc' => "{export.desc}",
163 'args' => $arguments };
164
165my $listall_options = { 'name' => "export.pl",
166 'desc' => "{export.desc}",
167 'args' => [ $saveas_argument ] };
168
169
170
171sub main
172{
173 my $inexport = new inexport("export",\@ARGV,$options,$listall_options);
174
175 my $collection = $inexport->get_collection();
176
177 if (defined $collection) {
178 my ($config_filename,$collect_cfg)
179 = $inexport->read_collection_cfg($collection,$options);
180
181 &set_collection_options($inexport, $collect_cfg);
182
183 my $pluginfo = $inexport->process_files($config_filename,$collect_cfg);
184
185 $inexport->generate_statistics($pluginfo);
186 }
187
188 $inexport->deinit();
189}
190
191sub set_collection_options
192{
193 my ($inexport, $collectcfg) = @_;
194
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}
212&main();
213
214
215
216
Note: See TracBrowser for help on using the repository browser.