source: gsdl/trunk/bin/script/pluginfo.pl@ 18470

Last change on this file since 18470 was 16787, checked in by davidb, 16 years ago

Now checks for extended plugins and classifiers as well as in standard place

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 7.0 KB
Line 
1#!/usr/bin/perl -w
2
3###########################################################################
4#
5# pluginfo.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) 1999 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# This program will print info about a plugin
29
30use strict;
31no strict 'subs'; # allow barewords (eg STDERR) as function arguments
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/plugins");
39
40 if (defined $ENV{'GSDLEXTS'}) {
41 my @extensions = split(/:/,$ENV{'GSDLEXTS'});
42 foreach my $e (@extensions) {
43 my $ext_prefix = "$ENV{'GSDLHOME'}/ext/$e";
44
45 unshift (@INC, "$ext_prefix/perllib");
46 unshift (@INC, "$ext_prefix/perllib/cpan");
47 unshift (@INC, "$ext_prefix/perllib/plugins");
48 unshift (@INC, "$ext_prefix/perllib/plugouts");
49 unshift (@INC, "$ext_prefix/perllib/classify");
50 }
51 }
52}
53
54use plugin;
55use util;
56use gsprintf;
57use printusage;
58use parse2;
59
60my $arguments =
61 [ { 'name' => "collection",
62 'desc' => "{pluginfo.collection}",
63 'type' => "string",
64 'reqd' => "no" },
65 { 'name' => "xml",
66 'desc' => "{scripts.xml}",
67 'type' => "flag",
68 'reqd' => "no" },
69 { 'name' => "listall",
70 'desc' => "{scripts.listall}",
71 'type' => "flag",
72 'reqd' => "no" },
73 { 'name' => "describeall",
74 'desc' => "{scripts.describeall}",
75 'type' => "flag",
76 'reqd' => "no" },
77 { 'name' => "language",
78 'desc' => "{scripts.language}",
79 'type' => "string",
80 'reqd' => "no" } ];
81
82my $options = { 'name' => "pluginfo.pl",
83 'desc' => "{pluginfo.desc}",
84 'args' => $arguments };
85
86sub gsprintf
87{
88 return &gsprintf::gsprintf(@_);
89}
90
91
92sub main {
93 my $collection = "";
94 my $xml = 0;
95 my $listall = 0;
96 my $describeall = 0;
97 my ($language, $encoding);
98
99 my $hashParsingResult = {};
100 # general options available to all plugins
101 my $unparsed_args = parse2::parse(\@ARGV,$arguments,$hashParsingResult,"allow_extra_options");
102 # parse returns -1 if an error occurred
103 if ($unparsed_args == -1) {
104
105 PrintUsage::print_txt_usage($options, "{pluginfo.params}");
106 die "\n";
107 }
108
109 foreach my $strVariable (keys %$hashParsingResult)
110 {
111 my $value = $hashParsingResult->{$strVariable};
112 # test to make sure the variable name is 'safe'
113 if ($strVariable !~ /^\w+$/) {
114 die "variable name '$strVariable' isn't safe!";
115 }
116 eval "\$$strVariable = \$value";
117 }
118
119 # if language wasn't specified, see if it is set in the environment
120 # (LC_ALL or LANG)
121 if (!$language && ($_=$ENV{'LC_ALL'} or $_=$ENV{'LANG'})) {
122 m/^([^\.]+)\.?(.*)/;
123 $language=$1;
124 $encoding=$2; # might be undef...
125# gsprintf::load_language* thinks "fr" is completely different to "fr_FR"...
126 $language =~ s/_.*$//;
127 }
128
129 # If $language has been set, load the appropriate resource bundle
130 # (Otherwise, the default resource bundle will be loaded automatically)
131 if ($language) {
132 gsprintf::load_language_specific_resource_bundle($language);
133 if ($encoding) {
134 $encoding =~ tr/-/_/;
135 $encoding = lc($encoding);
136 $encoding =~ s/utf_8/utf8/; # special
137 $gsprintf::specialoutputencoding=$encoding;
138 }
139 }
140
141 # If there is not exactly 1 argument left (plugin name), then the arguments were wrong
142 # If the user specified -h, then we output the usage also
143 if((@ARGV && $ARGV[0] =~ /^\-+h/) )
144 {
145 PrintUsage::print_txt_usage($options, "{pluginfo.params}");
146 die "\n";
147 }
148
149 # If there is not exactly 1 argument left (plugin name), then the arguments were wrong (apart from if we had listall or describeall set)
150 if ($listall == 0 && $describeall ==0 && $unparsed_args == 0) {
151 gsprintf(STDERR, "{pluginfo.no_plugin_name}\n\n");
152 PrintUsage::print_txt_usage($options, "{pluginfo.params}", 1);
153 die "\n";
154 }
155
156 # we had some arguments that we weren't expecting
157 if ($unparsed_args > 1) {
158 pop(@ARGV); # assume that the last arg is the plugin name
159 gsprintf(STDERR, "{common.invalid_options}\n\n", join (',', @ARGV));
160 PrintUsage::print_txt_usage($options, "{pluginfo.params}", 1);
161 die "\n";
162 }
163
164 my $plugin = shift (@ARGV);
165 if (defined $plugin) {
166 $plugin =~ s/\.pm$//; # allow xxxPlugin.pm as the argument
167 }
168
169 if ($collection ne "") {
170 $ENV{'GSDLCOLLECTDIR'} = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $collection);
171 } else {
172 $ENV{'GSDLCOLLECTDIR'} = $ENV{'GSDLHOME'};
173 }
174
175 if ($listall || $describeall) {
176 my $plugins_dir = &util::filename_cat($ENV{'GSDLCOLLECTDIR'}, "perllib", "plugins");
177 my @plugin_list = ();
178 if (opendir (INDIR, $plugins_dir)) {
179 @plugin_list = grep (/Plugin\.pm$/, readdir (INDIR));
180 closedir (INDIR);
181 }
182
183 if ((defined $ENV{'GSDLEXTS'}) && ($collection eq "")) {
184 my @extensions = split(/:/,$ENV{'GSDLEXTS'});
185 foreach my $e (@extensions) {
186 my $ext_prefix = &util::filename_cat($ENV{'GSDLHOME'},"ext",$e);
187 my $ext_plugins_dir = &util::filename_cat($ext_prefix, "perllib", "plugins");
188
189 if (opendir (INDIR, $ext_plugins_dir)) {
190 my @ext_plugin_list = grep (/Plugin\.pm$/, readdir (INDIR));
191 closedir (INDIR);
192
193 push(@plugin_list,@ext_plugin_list);
194 }
195
196 }
197 }
198
199 print STDERR "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
200 print STDERR "<PluginList length=\"" . scalar(@plugin_list) . "\">\n";
201 foreach my $plugin (@plugin_list) {
202 $plugin =~ s/\.pm$//;
203 my $plugobj = &plugin::load_plugin_for_info ($plugin);
204 if ($describeall) {
205 $plugobj->print_xml_usage(0);
206 }
207 else {
208 $plugobj->print_xml_usage(0, 1);
209 }
210 }
211 print STDERR "</PluginList>\n";
212 }
213 else {
214 &print_single_plugin($plugin, $xml, 1);
215 }
216}
217
218
219sub print_single_plugin {
220 my ($plugin, $xml, $header) = @_;
221 my $plugobj = &plugin::load_plugin_for_info ($plugin);
222 if ($xml) {
223 $plugobj->print_xml_usage($header);
224 }
225 else {
226 gsprintf(STDERR, "\n{pluginfo.passing_options}\n\n");
227 gsprintf(STDERR, "{pluginfo.option_types}:\n\n");
228 gsprintf(STDERR, "{pluginfo.specific_options}\n\n");
229 gsprintf(STDERR, "{pluginfo.general_options}\n\n");
230 gsprintf(STDERR, "$plugin {pluginfo.info}:\n\n");
231
232 $plugobj->print_txt_usage();
233 }
234
235}
236
237&main ();
Note: See TracBrowser for help on using the repository browser.