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

Last change on this file since 33171 was 33171, checked in by wy59, 5 years ago

First part of commit: following Dr Bainbridge's suggestion for how best to determine what phase of building we're in from within doc.pm. Needs a package level variable, used existing coding pattern in the file that used the our keyword.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 5.9 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;
71use doc; # for the variable our $cmd_line_mode ($doc::cmd_line_mode)
72
73
74
75# what format to export as
76my $saveas_list =
77 [ { 'name' => "GreenstoneXML",
78 'desc' => "{export.saveas.GreenstoneXML}"},
79 { 'name' => "GreenstoneMETS",
80 'desc' => "{export.saveas.GreenstoneMETS}"},
81 { 'name' => "FedoraMETS",
82 'desc' => "{export.saveas.FedoraMETS}"},
83 { 'name' => "MARCXML",
84 'desc' => "{export.saveas.MARCXML}"},
85 { 'name' => "DSpace",
86 'desc' => "{export.saveas.DSpace}" }
87 ];
88
89
90# Possible attributes for each argument
91# name: The name of the argument
92# desc: A description (or more likely a reference to a description) for this argument
93# type: The type of control used to represent the argument. Options include: string, int, flag, regexp, metadata, language, enum etc
94# reqd: Is this argument required?
95# hiddengli: Is this argument hidden in GLI?
96# modegli: The lowest detail mode this argument is visible at in GLI
97
98my $saveas_argument =
99 { 'name' => "saveas",
100 'desc' => "{export.saveas}",
101 'type' => "enum",
102 'list' => $saveas_list,
103 'deft' => "GreenstoneMETS",
104 'reqd' => "no",
105 'modegli' => "3" };
106
107
108my $arguments =
109 [
110 $saveas_argument,
111 { 'name' => "saveas_options",
112 'desc' => "{import.saveas_options}",
113 'type' => "string",
114 'reqd' => "no" },
115 { 'name' => "include_auxiliary_database_files",
116 'desc' => "{export.include_auxiliary_database_files}",
117 'type' => "flag",
118 'reqd' => "no" },
119 { 'name' => "exportdir",
120 'desc' => "{export.exportdir}",
121 'type' => "string",
122 'reqd' => "no",
123 'deft' => "export",
124 'hiddengli' => "yes" },
125 @$inexport::directory_arguments,
126 { 'name' => "xsltfile",
127 'desc' => "{BasPlugout.xslt_file}",
128 'type' => "string",
129 'reqd' => "no",
130 'hiddengli' => "yes" },
131 { 'name' => "listall",
132 'desc' => "{export.listall}",
133 'type' => "flag",
134 'reqd' => "no" },
135 @$inexport::arguments
136 ];
137
138my $options = { 'name' => "export.pl",
139 'desc' => "{export.desc}",
140 'args' => $arguments };
141
142my $listall_options = { 'name' => "export.pl",
143 'desc' => "{export.desc}",
144 'args' => [ $saveas_argument ] };
145
146
147
148sub main
149{
150 $doc::cmd_line_mode = "export";
151
152 my $inexport = new inexport("export",\@ARGV,$options,$listall_options);
153
154 my $collection = $inexport->get_collection();
155
156 if (defined $collection) {
157 my ($config_filename,$collect_cfg)
158 = $inexport->read_collection_cfg($collection,$options);
159
160 &set_collection_options($inexport, $collect_cfg);
161
162 my $pluginfo = $inexport->process_files($config_filename,$collect_cfg);
163
164 $inexport->generate_statistics($pluginfo);
165 }
166
167 $inexport->deinit();
168}
169
170sub set_collection_options
171{
172 my ($inexport, $collectcfg) = @_;
173
174 if (defined $inexport->{'default_saveas'}) {
175 # we had set the value from the arg default, not from the user
176 if (defined $collectcfg->{'saveas'}
177 && $collectcfg->{'saveas'} =~ /^(GreenstoneXML|GreenstoneMETS|FedoraMETS|MARCXML|DSPace)$/) {
178 $inexport->{'saveas'} = $collectcfg->{'saveas'};
179 } else {
180 $inexport->{'saveas'} = "GreenstoneMETS"; # the default
181 }
182 }
183
184 if (!defined $inexport->{'saveas_options'} || $inexport->{'saveas_options'} eq "") {
185 if (defined $collectcfg->{'saveas_options'} ){
186 $inexport->{'saveas_options'} = $collectcfg->{'saveas_options'};
187 }
188 }
189
190 $inexport->set_collection_options($collectcfg);
191}
192&main();
193
194
195
196
Note: See TracBrowser for help on using the repository browser.