[14959] | 1 | #!/usr/bin/perl -w
|
---|
| 2 |
|
---|
| 3 | BEGIN
|
---|
| 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 | $ENV{'FEDORA_HOSTNAME'} = "localhost" if (!defined $ENV{'FEDORA_HOSTNAME'});
|
---|
| 12 | $ENV{'FEDORA_SERVER_PORT'} = "8080" if (!defined $ENV{'FEDORA_SERVER_PORT'});
|
---|
| 13 | $ENV{'FEDORA_USER'} = "fedoraAdmin" if (!defined $ENV{'FEDORA_USER'});
|
---|
| 14 | $ENV{'FEDORA_PASS'} = "fedoraAdmin" if (!defined $ENV{'FEDORA_PASS'});
|
---|
| 15 | $ENV{'FEDORA_PROTOCOL'} = "http" if (!defined $ENV{'FEDORA_PROTOCOL'});
|
---|
| 16 | $ENV{'FEDORA_PID_NAMESPACE'} = "greenstone" if (!defined $ENV{'FEDORA_PID_NAMESPACE'});
|
---|
| 17 |
|
---|
| 18 | unshift (@INC, "$ENV{'GSDLHOME'}/perllib/");
|
---|
| 19 | }
|
---|
| 20 |
|
---|
| 21 |
|
---|
| 22 | use strict;
|
---|
| 23 | no strict 'refs'; # allow filehandles to be variables and vice versa
|
---|
| 24 | no strict 'subs'; # allow barewords (e.g. STDERR) as function arguments
|
---|
| 25 |
|
---|
| 26 | use util;
|
---|
| 27 | use gsprintf 'gsprintf';
|
---|
| 28 | use printusage;
|
---|
| 29 | use parse2;
|
---|
| 30 |
|
---|
| 31 |
|
---|
| 32 | use g2futil;
|
---|
| 33 |
|
---|
| 34 |
|
---|
| 35 | my $arguments =
|
---|
| 36 | [
|
---|
| 37 | { 'name' => "verbosity",
|
---|
[17215] | 38 | 'desc' => "{import.verbosity}",
|
---|
[14959] | 39 | 'type' => "string",
|
---|
| 40 | 'deft' => '1',
|
---|
| 41 | 'reqd' => "no",
|
---|
| 42 | 'hiddengli' => "no" },
|
---|
| 43 | { 'name' => "hostname",
|
---|
| 44 | 'desc' => "Domain hostname of Fedora server",
|
---|
| 45 | 'type' => "string",
|
---|
| 46 | 'deft' => $ENV{'FEDORA_HOSTNAME'},
|
---|
| 47 | 'reqd' => "no",
|
---|
| 48 | 'hiddengli' => "no" },
|
---|
| 49 | { 'name' => "port",
|
---|
| 50 | 'desc' => "Port that the Fedora server is running on.",
|
---|
| 51 | 'type' => "string",
|
---|
| 52 | 'deft' => $ENV{'FEDORA_SERVER_PORT'},
|
---|
| 53 | 'reqd' => "no",
|
---|
| 54 | 'hiddengli' => "no" },
|
---|
| 55 | { 'name' => "username",
|
---|
| 56 | 'desc' => "Fedora admin username",
|
---|
| 57 | 'type' => "string",
|
---|
| 58 | 'deft' => $ENV{'FEDORA_USER'},
|
---|
| 59 | 'reqd' => "no",
|
---|
| 60 | 'hiddengli' => "no" },
|
---|
| 61 | { 'name' => "password",
|
---|
| 62 | 'desc' => "Fedora admin password",
|
---|
| 63 | 'type' => "string",
|
---|
| 64 | 'deft' => $ENV{'FEDORA_PASS'},
|
---|
| 65 | 'reqd' => "no",
|
---|
| 66 | 'hiddengli' => "no" },
|
---|
| 67 | { 'name' => "protocol",
|
---|
| 68 | 'desc' => "Fedora protocol, e.g. 'http' or 'https'",
|
---|
| 69 | 'type' => "string",
|
---|
| 70 | 'deft' => $ENV{'FEDORA_PROTOCOL'},
|
---|
| 71 | 'reqd' => "no",
|
---|
| 72 | 'hiddengli' => "no" },
|
---|
| 73 | { 'name' => "pidnamespace",
|
---|
| 74 | 'desc' => "Fedora prefix for PIDs",
|
---|
| 75 | 'type' => "string",
|
---|
| 76 | 'deft' => $ENV{'FEDORA_PID_NAMESPACE'},
|
---|
| 77 | 'reqd' => "no",
|
---|
| 78 | 'hiddengli' => "no" },
|
---|
| 79 | { 'name' => "maxdocs",
|
---|
| 80 | 'desc' => "{import.maxdocs}",
|
---|
| 81 | 'type' => "int",
|
---|
| 82 | 'reqd' => "no",
|
---|
| 83 | 'range' => "1,",
|
---|
| 84 | 'modegli' => "1" },
|
---|
| 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",
|
---|
[18590] | 104 | 'modegli' => "3" },
|
---|
[14959] | 105 | { 'name' => "collectdir",
|
---|
| 106 | 'desc' => "{import.collectdir}",
|
---|
| 107 | 'type' => "string",
|
---|
| 108 | 'deft' => "",
|
---|
| 109 | 'reqd' => "no",
|
---|
| 110 | 'hiddengli' => "yes" },
|
---|
| 111 |
|
---|
| 112 |
|
---|
| 113 | ];
|
---|
| 114 |
|
---|
| 115 | my $prog_options
|
---|
| 116 | = { 'name' => "g2fimport.pl",
|
---|
| 117 | 'desc' => "Generate Fedora METS format using Greenstone document processing capabilities",
|
---|
| 118 | 'args' => $arguments };
|
---|
| 119 |
|
---|
| 120 |
|
---|
| 121 | sub main
|
---|
| 122 | {
|
---|
| 123 | my (@ARGV) = @_;
|
---|
| 124 |
|
---|
| 125 | my $GSDLHOME = $ENV{'GSDLHOME'};
|
---|
| 126 |
|
---|
| 127 |
|
---|
| 128 | my $options = {};
|
---|
| 129 | # general options available to all plugins
|
---|
| 130 | my $intArgLeftinAfterParsing = parse2::parse(\@ARGV,$arguments,$options,"allow_extra_options");
|
---|
| 131 |
|
---|
| 132 | # Something went wrong with parsing
|
---|
| 133 | if ($intArgLeftinAfterParsing ==-1)
|
---|
| 134 | {
|
---|
| 135 | &PrintUsage::print_txt_usage($prog_options, "[options] greenstone-col");
|
---|
| 136 | die "\n";
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | my $xml = $options->{'xml'};
|
---|
| 140 | my $gli = $options->{'gli'};
|
---|
| 141 |
|
---|
| 142 | if ($intArgLeftinAfterParsing != 1)
|
---|
| 143 | {
|
---|
| 144 | if ($xml) {
|
---|
| 145 | &PrintUsage::print_xml_usage($prog_options);
|
---|
| 146 | print "\n";
|
---|
| 147 | return;
|
---|
| 148 | }
|
---|
| 149 | else {
|
---|
| 150 | &PrintUsage::print_txt_usage($prog_options, "[options] greenstone-col");
|
---|
| 151 | print "\n";
|
---|
| 152 | return;
|
---|
| 153 | }
|
---|
| 154 |
|
---|
| 155 | }
|
---|
| 156 |
|
---|
| 157 | if ($gli) { # the gli wants strings to be in UTF-8
|
---|
| 158 | &gsprintf::output_strings_in_UTF8;
|
---|
| 159 | }
|
---|
| 160 |
|
---|
| 161 | my $gs_col = $ARGV[0];
|
---|
| 162 |
|
---|
| 163 | my $verbosity = $options->{'verbosity'};
|
---|
| 164 | my $hostname = $options->{'hostname'};
|
---|
| 165 | my $port = $options->{'port'};
|
---|
| 166 | my $username = $options->{'username'};
|
---|
| 167 | my $password = $options->{'password'};
|
---|
| 168 | my $protocol = $options->{'protocol'};
|
---|
| 169 | my $pid_namespace = $options->{'pidnamespace'};
|
---|
| 170 |
|
---|
| 171 | # The following are needed in the FedoraMETS plugout
|
---|
| 172 | $ENV{'FEDORA_HOSTNAME'} = $hostname;
|
---|
| 173 | $ENV{'FEDORA_SERVER_PORT'} = $port;
|
---|
| 174 |
|
---|
| 175 | my $language = $options->{'language'};
|
---|
| 176 | my $collectdir = $options->{'collectdir'};
|
---|
| 177 | my $removeold = $options->{'removeold'};
|
---|
| 178 | my $maxdocs = $options->{'maxdocs'};
|
---|
| 179 |
|
---|
| 180 | if (!$collectdir) {
|
---|
[21687] | 181 | # Explicitly set one, depending on whether it's GS2 or GS3
|
---|
| 182 | if($ENV{'GSDL3HOME'}) {
|
---|
| 183 | $collectdir = &util::filename_cat($ENV{'GSDL3HOME'},"sites","localsite","collect");
|
---|
| 184 | } else {
|
---|
| 185 | $collectdir = &util::filename_cat($ENV{'GSDLHOME'},"collect");
|
---|
| 186 | }
|
---|
| 187 | }
|
---|
[14959] | 188 |
|
---|
[21687] | 189 | # if GS3, and if Fedora uses Greenstone's tomcat, then we do not need to write out the file gsdl.xml into Fedora's tomcat
|
---|
| 190 | my $localfedora = &util::filename_cat($ENV{'GSDL3SRCHOME'}, "packages", "tomcat", "conf", "Catalina", "localhost", "fedora.xml");
|
---|
| 191 | unless($ENV{'GSDL3SRCHOME'} && -e $localfedora) {
|
---|
| 192 | # method that will tell Fedora where the ultimate output of g2f-import and g2f-build
|
---|
| 193 | # will be found: Points Fedora to the collect directory where FedoraMETS will be output.
|
---|
| 194 | &g2futil::write_gsdl_xml_file($hostname, $collectdir, $options);
|
---|
[14959] | 195 | }
|
---|
| 196 |
|
---|
[16364] | 197 | my $full_gs_col = &util::filename_cat($collectdir,$gs_col);
|
---|
[14959] | 198 |
|
---|
| 199 | if (!-e $full_gs_col ) {
|
---|
| 200 | print STDERR "Unable to find Greenstone collection $full_gs_col\n";
|
---|
| 201 | exit 1;
|
---|
| 202 | }
|
---|
| 203 |
|
---|
| 204 | my $export_dir = &util::filename_cat($full_gs_col,"export");
|
---|
| 205 |
|
---|
| 206 | if ( -e $export_dir ) {
|
---|
| 207 | print "***\n";
|
---|
[16102] | 208 | print "* Updating existing Greenstone $gs_col objects from Fedora $pid_namespace\n";
|
---|
[14959] | 209 | print "***\n";
|
---|
| 210 |
|
---|
| 211 | # readdir
|
---|
| 212 | if (opendir(DIR, $export_dir)) {
|
---|
[16102] | 213 |
|
---|
[14959] | 214 | closedir DIR;
|
---|
[16102] | 215 | my @hash_dirs = &g2futil::get_all_hash_dirs($export_dir,$maxdocs);
|
---|
[14959] | 216 |
|
---|
| 217 | # for each hash dir, purge its respective PID
|
---|
[16102] | 218 | foreach my $full_hd (@hash_dirs) {
|
---|
[14959] | 219 |
|
---|
| 220 | my $hash_id = &g2futil::get_hash_id($full_hd);
|
---|
| 221 |
|
---|
| 222 | next if !defined $hash_id;
|
---|
| 223 |
|
---|
| 224 | my $pid = "$pid_namespace:$gs_col-$hash_id";
|
---|
| 225 |
|
---|
| 226 | my $dsinfo_status = &g2futil::run_datastore_info($pid,$options);
|
---|
| 227 |
|
---|
| 228 | if ($dsinfo_status == 0) {
|
---|
[16102] | 229 | print " $pid being updated.\n";
|
---|
[14959] | 230 | &g2futil::run_purge($pid,$options);
|
---|
| 231 | }
|
---|
| 232 | else {
|
---|
| 233 | print " $pid not present.\n";
|
---|
| 234 | }
|
---|
| 235 | }
|
---|
| 236 | }
|
---|
| 237 | else {
|
---|
| 238 | print STDERR "Error: Unable to open directory $export_dir: $!\n";
|
---|
| 239 | exit;
|
---|
| 240 | }
|
---|
| 241 | }
|
---|
| 242 |
|
---|
| 243 | print "***\n";
|
---|
| 244 | print "* Processing $gs_col into FedoraMETS format\n";
|
---|
| 245 | print "***\n";
|
---|
| 246 |
|
---|
| 247 | my $gs_export_opts = "-saveas FedoraMETS -fedora_namespace $pid_namespace -verbosity $verbosity";
|
---|
| 248 |
|
---|
| 249 | $gs_export_opts .= " -gli" if ($gli);
|
---|
| 250 |
|
---|
| 251 | $gs_export_opts .= " -language $language" if ($language);
|
---|
[17913] | 252 | $gs_export_opts .= " -collectdir \"$collectdir\"" if ($collectdir);
|
---|
[14959] | 253 | $gs_export_opts .= " -removeold" if ($removeold);
|
---|
| 254 | $gs_export_opts .= " -maxdocs $maxdocs" if ($maxdocs);
|
---|
| 255 |
|
---|
[17913] | 256 | $gs_export_opts .= " -exportdir \"$export_dir\"";
|
---|
[14959] | 257 |
|
---|
| 258 | my $gs_export_arguments = "$gs_export_opts $gs_col";
|
---|
| 259 |
|
---|
| 260 | &g2futil::run_cmd("export.pl", $gs_export_arguments, $options);
|
---|
| 261 | }
|
---|
| 262 |
|
---|
| 263 | &main(@ARGV);
|
---|
| 264 |
|
---|
| 265 |
|
---|
| 266 |
|
---|