source: gsdl/trunk/bin/script/g2f-buildcol.pl@ 14959

Last change on this file since 14959 was 14959, checked in by davidb, 15 years ago

Greenstone to Fedora scripts. Similar to import.pl and buildcol.pl, g2f-import.pl first converts documents into FedoraMETS and then g2f-buildcol.pl ingests them into a Fedora repository. Needs to have FEDORA_HOME set.

  • Property svn:executable set to *
File size: 5.9 KB
Line 
1#!/usr/bin/perl -w
2
3BEGIN
4{
5 if (!defined $ENV{'GSDLHOME'}) {
6 print STDERR "Environment variable GSDLHOME not set.\n";
7 print STDERR " Have you sourced Greenstone's 'setup.bash' file?\n";
8 exit 1;
9 }
10
11 if (!defined $ENV{'JAVA_HOME'}) {
12 print STDERR "Environment variable JAVA_HOME not set.\n";
13 print STDERR "Needed by Fedora command line scripts.\n";
14 exit 1;
15 }
16
17 $ENV{'FEDORA_HOSTNAME'} = "localhost" if (!defined $ENV{'FEDORA_HOSTNAME'});
18 $ENV{'FEDORA_SERVER_PORT'} = "8080" if (!defined $ENV{'FEDORA_SERVER_PORT'});
19 $ENV{'FEDORA_USER'} = "fedoraAdmin" if (!defined $ENV{'FEDORA_USER'});
20 $ENV{'FEDORA_PASS'} = "fedoraAdmin" if (!defined $ENV{'FEDORA_PASS'});
21 $ENV{'FEDORA_PROTOCOL'} = "http" if (!defined $ENV{'FEDORA_PROTOCOL'});
22 $ENV{'FEDORA_PID_NAMESPACE'} = "greenstone" if (!defined $ENV{'FEDORA_PID_NAMESPACE'});
23
24 unshift (@INC, "$ENV{'GSDLHOME'}/perllib/");
25
26}
27
28
29use strict;
30no strict 'refs'; # allow filehandles to be variables and vice versa
31no strict 'subs'; # allow barewords (e.g. STDERR) as function arguments
32
33use util;
34use gsprintf 'gsprintf';
35use printusage;
36use parse2;
37
38use g2futil;
39
40
41my $arguments =
42 [
43 { 'name' => "verbosity",
44 'desc' => "Level of verbosity generated",
45 'type' => "string",
46 'deft' => '1',
47 'reqd' => "no",
48 'hiddengli' => "no" },
49 { 'name' => "hostname",
50 'desc' => "Domain hostname of Fedora server",
51 'type' => "string",
52 'deft' => $ENV{'FEDORA_HOSTNAME'},
53 'reqd' => "no",
54 'hiddengli' => "no" },
55 { 'name' => "port",
56 'desc' => "Port that the Fedora server is running on.",
57 'type' => "string",
58 'deft' => $ENV{'FEDORA_SERVER_PORT'},
59 'reqd' => "no",
60 'hiddengli' => "no" },
61 { 'name' => "username",
62 'desc' => "Fedora admin username",
63 'type' => "string",
64 'deft' => $ENV{'FEDORA_USER'},
65 'reqd' => "no",
66 'hiddengli' => "no" },
67 { 'name' => "password",
68 'desc' => "Fedora admin password",
69 'type' => "string",
70 'deft' => $ENV{'FEDORA_PASS'},
71 'reqd' => "no",
72 'hiddengli' => "no" },
73 { 'name' => "protocol",
74 'desc' => "Fedora protocol, e.g. 'http' or 'https'",
75 'type' => "string",
76 'deft' => $ENV{'FEDORA_PROTOCOL'},
77 'reqd' => "no",
78 'hiddengli' => "no" },
79 { 'name' => "pidnamespace",
80 'desc' => "Fedora prefix for PIDs",
81 'type' => "string",
82 'deft' => $ENV{'FEDORA_PID_NAMESPACE'},
83 'reqd' => "no",
84 'hiddengli' => "no" },
85 { 'name' => "gli",
86 'desc' => "",
87 'type' => "flag",
88 'reqd' => "no",
89 'hiddengli' => "yes" },
90 { 'name' => "xml",
91 'desc' => "{scripts.xml}",
92 'type' => "flag",
93 'reqd' => "no",
94 'hiddengli' => "yes" },
95 { 'name' => "removeold",
96 'desc' => "{import.removeold}",
97 'type' => "flag",
98 'reqd' => "no",
99 'modegli' => "3" },
100 { 'name' => "language",
101 'desc' => "{scripts.language}",
102 'type' => "string",
103 'reqd' => "no",
104 'modegli' => "4" },
105 { 'name' => "collectdir",
106 'desc' => "{import.collectdir}",
107 'type' => "string",
108 'deft' => "",
109 'reqd' => "no",
110 'hiddengli' => "yes" }
111 ];
112
113my $prog_options
114 = { 'name' => "g2fbuildcol.pl",
115 'desc' => "Ingest Greenstone directory of FedoraMETS documents into Fedora",
116 'args' => $arguments };
117
118
119sub main
120{
121 my (@ARGV) = @_;
122
123 my $GSDLHOME = $ENV{'GSDLHOME'};
124
125
126 my $options = {};
127 # general options available to all plugins
128 my $intArgLeftinAfterParsing = parse2::parse(\@ARGV,$arguments,$options,"allow_extra_options");
129
130 # Something went wrong with parsing
131 if ($intArgLeftinAfterParsing ==-1)
132 {
133 &PrintUsage::print_txt_usage($prog_options, "[options] greenstone-col");
134 die "\n";
135 }
136
137 my $xml = $options->{'xml'};
138 my $gli = $options->{'gli'};
139
140 if ($intArgLeftinAfterParsing != 1)
141 {
142 if ($xml) {
143 &PrintUsage::print_xml_usage($prog_options);
144 print "\n";
145 return;
146 }
147 else {
148 &PrintUsage::print_txt_usage($prog_options, "[options] greenstone-col");
149 print "\n";
150 return;
151 }
152
153 }
154
155 my $gs_col = $ARGV[0];
156
157 my $verbosity = $options->{'verbosity'};
158 my $hostname = $options->{'hostname'};
159 my $port = $options->{'port'};
160 my $username = $options->{'username'};
161 my $password = $options->{'password'};
162 my $protocol = $options->{'protocol'};
163 my $pid_namespace = $options->{'pidnamespace'};
164
165 # The following are needed in the FedoraMETS plugout
166 $ENV{'FEDORA_HOSTNAME'} = $hostname;
167 $ENV{'FEDORA_SERVER_PORT'} = $port;
168
169 my $collectdir = $options->{'collectdir'};
170
171 if (!$collectdir) {
172 ## my $collect_dir = util::filename_cat($ENV{'GREENSTONE3_HOME'},
173 ## "web","sites","localsite","collect");
174
175
176 $collectdir = util::filename_cat($ENV{'GSDLHOME'},"collect");
177 }
178
179 my $full_gs_col = util::filename_cat($collectdir,$gs_col);
180
181
182 if (!-e $full_gs_col ) {
183 print STDERR "Unable to find Greenstone collection $full_gs_col\n";
184 exit 1;
185 }
186
187## my $archives_dir = &util::filename_cat($full_gs_col,"archives");
188 my $export_dir = &util::filename_cat($full_gs_col,"export");
189
190
191 print "***\n";
192 print "* Ingesting Greenstone processed files into Fedora $pid_namespace\n";
193 print "***\n";
194
195 # Following falls foul of Schematron rule checking
196 my $fd_add_prog = "fedora-ingest";
197# my $fd_add_cmd;
198# $fd_add_args = "dir $export_dir O metslikefedora1 $hostname:$port $username $password \\\n";
199# $fd_add_args .= " \"Automated_ingest_by_gs2fed.pl\"";
200
201# &g2futil::run_cmd($fd_add_prog,$fd_add_args,$options);
202
203
204 # => Ingest individually!
205
206 if (opendir(DIR, $export_dir)) {
207 my @hash_dirs = grep { /\.dir$/ } readdir(DIR);
208 closedir DIR;
209
210
211 # for each hash dir, purge its respective PID
212 foreach my $hd (@hash_dirs) {
213
214 my $docmets_filename
215 = &util::filename_cat($export_dir,$hd,"docmets.xml");
216
217 print STDERR "<Build>\n" if $gli;
218
219 print "Ingesting $docmets_filename\n";
220
221 &g2futil::run_ingest($docmets_filename,$options);
222 print STDERR "</Build>\n" if $gli;
223
224 }
225 }
226 else {
227 print STDERR "Error: Unable to open directory $export_dir: $!\n";
228 exit;
229 }
230
231
232}
233
234&main(@ARGV);
235
236
237
Note: See TracBrowser for help on using the repository browser.