root/main/trunk/greenstone2/bin/script/export.pl @ 22421

Revision 22421, 8.3 KB (checked in by davidb, 10 years ago)

Continued work on refactoring code to have better shared support for import.pl and export.pl

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
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
72my $oidtype_list =
73    [ { 'name' => "hash",
74        'desc' => "{import.OIDtype.hash}" },
75      { 'name' => "assigned",
76        'desc' => "{import.OIDtype.assigned}" },
77      { 'name' => "incremental",
78        'desc' => "{import.OIDtype.incremental}" },
79      { 'name' => "dirname",
80        'desc' => "{import.OIDtype.dirname}" } ];
81
82# what format to export as
83my $saveas_list =
84    [ { 'name' => "GreenstoneMETS",
85        'desc' => "{export.saveas.GreenstoneMETS}"},
86      { 'name' => "FedoraMETS",
87        'desc' => "{export.saveas.FedoraMETS}"},
88      { 'name' => "MARCXML",
89        'desc' => "{export.saveas.MARCXML}"},
90      { 'name' => "DSpace",
91        'desc' => "{export.saveas.DSpace}" }
92     ];
93
94
95# Possible attributes for each argument
96# name: The name of the argument
97# desc: A description (or more likely a reference to a description) for this argument
98# type: The type of control used to represent the argument. Options include: string, int, flag, regexp, metadata, language, enum etc
99# reqd: Is this argument required?
100# hiddengli: Is this argument hidden in GLI?
101# modegli: The lowest detail mode this argument is visible at in GLI
102
103my $saveas_argument =
104      { 'name' => "saveas",
105    'desc' => "{export.saveas}",
106    'type' => "enum",
107    'list' => $saveas_list,
108    'deft' => "GreenstoneMETS",
109    'reqd' => "no",
110    'modegli' => "3" };
111
112
113my $arguments =
114    [
115      $saveas_argument,
116      { 'name' => "archivedir",
117    'desc' => "{export.archivedir}",
118    'type' => "string",
119    'reqd' => "no",
120        'hiddengli' => "yes" },
121      { 'name' => "importdir",
122    'desc' => "{import.importdir}",
123    'type' => "string",
124    'reqd' => "no",
125        'hiddengli' => "yes" },
126      { 'name' => "collectdir",
127    'desc' => "{export.collectdir}",
128    'type' => "string",
129    # parsearg left "" as default
130    #'deft' => &util::filename_cat ($ENV{'GSDLHOME'}, "collect"),
131    'deft' => "",
132    'reqd' => "no",
133    'hiddengli' => "yes" },
134      { 'name' => "site",
135    'desc' => "{import.site}",
136    'type' => "string",
137    'deft' => "",
138    'reqd' => "no",
139        'hiddengli' => "yes" },
140     { 'name' => "manifest",
141    'desc' => "{import.manifest}",
142    'type' => "string",
143    'deft' => "",
144    'reqd' => "no",
145        'hiddengli' => "yes" },
146      { 'name' => "debug",
147    'desc' => "{export.debug}",
148    'type' => "flag",
149    'reqd' => "no",
150        'hiddengli' => "yes" },
151      { 'name' => "faillog",
152    'desc' => "{export.faillog}",
153    'type' => "string",
154    'deft' => "",
155    'reqd' => "no",
156        'modegli' => "3" },
157      # does this make sense?
158      { 'name' => "incremental",
159    'desc' => "{import.incremental}",
160    'type' => "flag",
161    'hiddengli' => "yes" },
162      { 'name' => "keepold",
163    'desc' => "{export.keepold}",
164    'type' => "flag",
165    'reqd' => "no",
166    'hiddengli' => "yes" },
167      { 'name' => "removeold",
168    'desc' => "{export.removeold}",
169    'type' => "flag",
170    'reqd' => "no",
171    'hiddengli' => "yes" },
172      { 'name' => "language",
173    'desc' => "{scripts.language}",
174    'type' => "string",
175    'reqd' => "no",
176    'hiddengli' => "yes" },
177      { 'name' => "maxdocs",
178    'desc' => "{export.maxdocs}",
179    'type' => "int",
180    'reqd' => "no",
181    'range' => "1,",
182    'modegli' => "1" },
183      { 'name' => "OIDtype",
184    'desc' => "{import.OIDtype}",
185    'type' => "enum",
186    'list' => $oidtype_list,
187    # parsearg left "" as default
188    #'deft' => "hash",
189    'reqd' => "no",
190    'modegli' => "2" },
191      { 'name' => "OIDmetadata",
192    'desc' => "{import.OIDmetadata}",
193    'type' => "string",
194    #'type' => "metadata", #doesn't work properly in GLI
195    'deft' => "dc.Identifier",
196    'reqd' => "no",
197    'modegli' => "2" },
198      { 'name' => "out",
199    'desc' => "{export.out}",
200    'type' => "string",
201    'deft' => "STDERR",
202    'reqd' => "no",
203        'hiddengli' => "yes" },
204      { 'name' => "statsfile",
205    'desc' => "{export.statsfile}",
206    'type' => "string",
207    'deft' => "STDERR",
208    'reqd' => "no",
209        'hiddengli' => "yes" },
210      { 'name' => "xsltfile",
211    'desc' => "{BasPlugout.xslt_file}",
212    'type' => "string",
213    'reqd' => "no",
214        'hiddengli' => "yes" },
215      { 'name' => "xslt_txt",
216    'desc' => "{METSPlugout.xslt_txt}",
217    'type' => "string",
218    'reqd' => "no",
219        'hiddengli' => "no" },
220      { 'name' => "xslt_mets",
221    'desc' => "{METSPlugout.xslt_mets}",
222    'type' => "string",
223    'reqd' => "no",
224        'hiddengli' => "no" },
225      { 'name' => "fedora_namespace",
226    'desc' => "{FedoraMETSPlugout.fedora_namespace} (-saveas FedoraMETS)",
227    'type' => "string",
228    'deft' => "greenstone",
229    'reqd' => "no",
230        'hiddengli' => "no" },
231      { 'name' => "mapping_file",
232    'desc' => "{MARCXMLPlugout.mapping_file} (-saveas MARCXML)",
233    'type' => "string",
234    'reqd' => "no",
235        'hiddengli' => "no" },
236      { 'name' => "group_marc",
237    'desc' => "{MARCXMLPlugout.group} (-saveas MARCXML)",
238    'type' => "flag",
239    'reqd' => "no",
240        'hiddengli' => "no" },
241      { 'name' => "verbosity",
242    'desc' => "{export.verbosity}",
243    'type' => "int",
244    'range' => "0,3",
245    'deft' => "2",
246    'reqd' => "no",
247    'modegli' => "3" },
248      { 'name' => "gli",
249    'desc' => "{scripts.gli}",
250    'type' => "flag",
251    'reqd' => "no",
252    'hiddengli' => "yes" },
253      { 'name' => "listall",
254    'desc' => "{export.listall}",
255    'type' => "flag",
256    'reqd' => "no" },
257      { 'name' => "xml",
258    'desc' => "{scripts.xml}",
259    'type' => "flag",
260    'reqd' => "no",
261    'hiddengli' => "yes" }
262      ];
263
264my $options = { 'name' => "export.pl",
265        'desc' => "{export.desc}",
266        'args' => $arguments };
267
268my $listall_options = { 'name' => "export.pl",
269                'desc' => "{export.desc}",
270                'args' => [ $saveas_argument ] };
271
272
273
274sub main
275{
276    my $inexport = new inexport("export",\@ARGV,$options,$listall_options);
277   
278    my $collection = $inexport->get_collection();
279    my ($config_filename,$collect_cfg) = $inexport->read_collection_cfg($collection,$options);   
280    $inexport->set_collection_options($collect_cfg);
281   
282    my $pluginfo = $inexport->process_files($config_filename,$collect_cfg);
283
284    $inexport->generate_statistics($pluginfo);
285}
286
287
288&main();
289
290
Note: See TracBrowser for help on using the browser.