source: main/trunk/greenstone2/perllib/plugout.pm@ 32594

Last change on this file since 32594 was 32511, checked in by ak19, 6 years ago

Running plugoutinfo.pl with describeall or listall flag would break on FedoraMETSPlugout when either FEDORA_HOME or FEDORA_VERSION aren't set (as is often the case), as there's a die statement in the BEGIN of FedoraMETSPlugout. Needed to run die if either FEDORA env var is not set only if the plugout is NOT in info_only mode in plugout constructor. However, info_only mode was never set in any of the plugouts, so had to add set up the infrastructure for it in plugoutinfo.pl and plugout.pm. Then added the info_only test to all teh plugouts, even though it's redundant in most of them for making sure future changes to any plugout's constructors does not break plugoutinfo.pl.

  • Property svn:keywords set to Author Date Id Revision
File size: 5.2 KB
Line 
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
26package plugout;
27
28use strict; # to pick up typos and undeclared variables...
29no strict 'refs'; # ...but allow filehandles to be variables and vice versa
30no strict 'subs';
31
32require util;
33use FileUtils;
34use gsprintf 'gsprintf';
35
36# global variables
37my $stats = {'num_processed' => 0,
38 'num_blocked' => 0,
39 'num_not_processed' => 0,
40 'num_not_recognised' => 0,
41 'num_archives' => 0
42 };
43
44#globaloptions contains any options that should be passed to all plugouts
45my ($verbosity, $outhandle, $failhandle, $globaloptions);
46
47# - significantly rewritten to support plugouts in extensions [jmt12]
48sub load_plugout{
49 my ($plugout) = shift @_;
50 my ($info_only) = shift @_; # optional. Set to info_only if we're just printing out plugout info
51 my $plugout_name = shift @$plugout;
52
53 my $plugout_suffix = &FileUtils::filenameConcatenate('perllib', 'plugouts', $plugout_name . '.pm');
54 my $plugout_found = 0;
55
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 }
74
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
78 if (defined($ENV{'GSDLCOLLECTION'}))
79 {
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 }
99 }
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 }
141
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";
147 }
148
149 # - create a plugout object
150 my ($plugobj);
151
152 # if just doing plugoutinfo.pl, add in -gsdlinfo to plugout object's options
153 if($info_only) {
154 unshift (@$plugout, "-gsdlinfo");
155 }
156
157 eval ("\$plugobj = new \$plugout_name([],\$plugout)");
158 die "$@" if $@;
159
160 return $plugobj;
161}
162
1631;
Note: See TracBrowser for help on using the repository browser.