[12329] | 1 | ###########################################################################
|
---|
| 2 | #
|
---|
| 3 | # plugout.pm -- functions to handle using plugouts
|
---|
| 4 | # A component of the Greenstone digital library software
|
---|
| 5 | # from the New Zealand Digital Library Project at the
|
---|
| 6 | # University of Waikato, New Zealand.
|
---|
| 7 | #
|
---|
| 8 | # Copyright (C) 1999 New Zealand Digital Library Project
|
---|
| 9 | #
|
---|
| 10 | # This program is free software; you can redistribute it and/or modify
|
---|
| 11 | # it under the terms of the GNU General Public License as published by
|
---|
| 12 | # the Free Software Foundation; either version 2 of the License, or
|
---|
| 13 | # (at your option) any later version.
|
---|
| 14 | #
|
---|
| 15 | # This program is distributed in the hope that it will be useful,
|
---|
| 16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 18 | # GNU General Public License for more details.
|
---|
| 19 | #
|
---|
| 20 | # You should have received a copy of the GNU General Public License
|
---|
| 21 | # along with this program; if not, write to the Free Software
|
---|
| 22 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 23 | #
|
---|
| 24 | ###########################################################################
|
---|
| 25 |
|
---|
| 26 | package plugout;
|
---|
| 27 |
|
---|
| 28 | use strict; # to pick up typos and undeclared variables...
|
---|
| 29 | no strict 'refs'; # ...but allow filehandles to be variables and vice versa
|
---|
| 30 | no strict 'subs';
|
---|
| 31 |
|
---|
| 32 | require util;
|
---|
[27306] | 33 | use FileUtils;
|
---|
[12329] | 34 | use gsprintf 'gsprintf';
|
---|
| 35 |
|
---|
| 36 | # global variables
|
---|
| 37 | my $stats = {'num_processed' => 0,
|
---|
| 38 | 'num_blocked' => 0,
|
---|
| 39 | 'num_not_processed' => 0,
|
---|
| 40 | 'num_not_recognised' => 0,
|
---|
| 41 | 'num_archives' => 0
|
---|
| 42 | };
|
---|
| 43 |
|
---|
[14660] | 44 | #globaloptions contains any options that should be passed to all plugouts
|
---|
[12329] | 45 | my ($verbosity, $outhandle, $failhandle, $globaloptions);
|
---|
| 46 |
|
---|
[27306] | 47 | # - significantly rewritten to support plugouts in extensions [jmt12]
|
---|
[12329] | 48 | sub load_plugout{
|
---|
[14660] | 49 | my ($plugout) = shift @_;
|
---|
[32511] | 50 | my ($info_only) = shift @_; # optional. Set to info_only if we're just printing out plugout info
|
---|
[27306] | 51 | my $plugout_name = shift @$plugout;
|
---|
[32511] | 52 |
|
---|
[27306] | 53 | my $plugout_suffix = &FileUtils::filenameConcatenate('perllib', 'plugouts', $plugout_name . '.pm');
|
---|
| 54 | my $plugout_found = 0;
|
---|
[12329] | 55 |
|
---|
[27306] | 56 | # add collection plugout directory to INC unless it is already there
|
---|
| 57 | my $colplugdir = &FileUtils::filenameConcatenate($ENV{'GSDLCOLLECTDIR'},'perllib','plugouts');
|
---|
| 58 | if (-d $colplugdir)
|
---|
| 59 | {
|
---|
| 60 | my $found_colplugdir = 0;
|
---|
| 61 | foreach my $path (@INC)
|
---|
| 62 | {
|
---|
| 63 | if ($path eq $colplugdir)
|
---|
| 64 | {
|
---|
| 65 | $found_colplugdir = 1;
|
---|
| 66 | last;
|
---|
| 67 | }
|
---|
| 68 | }
|
---|
| 69 | if (!$found_colplugdir)
|
---|
| 70 | {
|
---|
| 71 | unshift (@INC, $colplugdir);
|
---|
| 72 | }
|
---|
| 73 | }
|
---|
[14929] | 74 |
|
---|
[27306] | 75 | # To find the plugout we check a number of possible locations
|
---|
| 76 | # - any plugout found in the collection itself is our first choice, with
|
---|
| 77 | # those located in 'custom' having precedence
|
---|
[14735] | 78 | if (defined($ENV{'GSDLCOLLECTION'}))
|
---|
| 79 | {
|
---|
[27306] | 80 | my $collect_dir = $ENV{'GSDLCOLLECTION'};
|
---|
| 81 |
|
---|
| 82 | # (needed for Veridian?)
|
---|
| 83 | my $custom_plugout = &FileUtils::filenameConcatenate($collect_dir, "custom", $collect_dir, $plugout_suffix);
|
---|
| 84 | if (&FileUtils::fileExists($custom_plugout))
|
---|
| 85 | {
|
---|
| 86 | require $custom_plugout;
|
---|
| 87 | $plugout_found = 1;
|
---|
| 88 | }
|
---|
| 89 | else
|
---|
| 90 | {
|
---|
| 91 | # typical collection override
|
---|
| 92 | my $collection_plugout = &FileUtils::filenameConcatenate($collect_dir, $plugout_suffix);
|
---|
| 93 | if (&FileUtils::fileExists($collection_plugout))
|
---|
| 94 | {
|
---|
| 95 | require $custom_plugout;
|
---|
| 96 | $plugout_found = 1;
|
---|
| 97 | }
|
---|
| 98 | }
|
---|
[14735] | 99 | }
|
---|
[27306] | 100 | # - we then search for overridden version provided by any registered GS3
|
---|
| 101 | # extensions (check in order of extension definition)
|
---|
| 102 | if (!$plugout_found && defined $ENV{'GSDL3EXTS'})
|
---|
| 103 | {
|
---|
| 104 | my $ext_prefix = &FileUtils::filenameConcatenate($ENV{'GSDL3SRCHOME'}, "ext");
|
---|
| 105 | my @extensions = split(/:/,$ENV{'GSDL3EXTS'});
|
---|
| 106 | foreach my $e (@extensions)
|
---|
| 107 | {
|
---|
| 108 | my $extension_plugout = &FileUtils::filenameConcatenate($ext_prefix, $e, $plugout_suffix);
|
---|
| 109 | if (&FileUtils::fileExists($extension_plugout))
|
---|
| 110 | {
|
---|
| 111 | require $extension_plugout;
|
---|
| 112 | $plugout_found = 1;
|
---|
| 113 | }
|
---|
| 114 | }
|
---|
| 115 | }
|
---|
| 116 | # - similar for GS2 extensions
|
---|
| 117 | if (!$plugout_found && defined $ENV{'GSDLEXTS'})
|
---|
| 118 | {
|
---|
| 119 | my $ext_prefix = &FileUtils::filenameConcatenate($ENV{'GSDLHOME'}, "ext");
|
---|
| 120 | my @extensions = split(/:/,$ENV{'GSDLEXTS'});
|
---|
| 121 | foreach my $e (@extensions)
|
---|
| 122 | {
|
---|
| 123 | my $extension_plugout = &FileUtils::filenameConcatenate($ext_prefix, $e, $plugout_suffix);
|
---|
| 124 | if (&FileUtils::fileExists($extension_plugout))
|
---|
| 125 | {
|
---|
| 126 | require $extension_plugout;
|
---|
| 127 | $plugout_found = 1;
|
---|
| 128 | }
|
---|
| 129 | }
|
---|
| 130 | }
|
---|
| 131 | # - and the default is the main Greenstone version of the plugout
|
---|
| 132 | if (!$plugout_found)
|
---|
| 133 | {
|
---|
| 134 | my $main_plugout = &FileUtils::filenameConcatenate($ENV{'GSDLHOME'}, $plugout_suffix);
|
---|
| 135 | if (&FileUtils::fileExists($main_plugout))
|
---|
| 136 | {
|
---|
| 137 | require $main_plugout;
|
---|
| 138 | $plugout_found = 1;
|
---|
| 139 | }
|
---|
| 140 | }
|
---|
[14735] | 141 |
|
---|
[27306] | 142 | # - no plugout found with this name
|
---|
| 143 | if (!$plugout_found)
|
---|
| 144 | {
|
---|
| 145 | gsprintf($outhandle, "{plugout.could_not_find_plugout}\n", $plugout_name);
|
---|
| 146 | die "\n";
|
---|
[12329] | 147 | }
|
---|
| 148 |
|
---|
[27306] | 149 | # - create a plugout object
|
---|
[12329] | 150 | my ($plugobj);
|
---|
| 151 |
|
---|
[32511] | 152 | # if just doing plugoutinfo.pl, add in -gsdlinfo to plugout object's options
|
---|
| 153 | if($info_only) {
|
---|
| 154 | unshift (@$plugout, "-gsdlinfo");
|
---|
| 155 | }
|
---|
| 156 |
|
---|
[27306] | 157 | eval ("\$plugobj = new \$plugout_name([],\$plugout)");
|
---|
[12329] | 158 | die "$@" if $@;
|
---|
| 159 |
|
---|
| 160 | return $plugobj;
|
---|
| 161 | }
|
---|
| 162 |
|
---|
| 163 | 1;
|
---|