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

Last change on this file since 19620 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
RevLine 
[1244]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
[6988]30use strict;
31no strict 'subs'; # allow barewords (eg STDERR) as function arguments
[3541]32
[1244]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");
[5882]37 unshift (@INC, "$ENV{'GSDLHOME'}/perllib/cpan");
[1244]38 unshift (@INC, "$ENV{'GSDLHOME'}/perllib/plugins");
[14942]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");
[16787]47 unshift (@INC, "$ext_prefix/perllib/plugins");
48 unshift (@INC, "$ext_prefix/perllib/plugouts");
49 unshift (@INC, "$ext_prefix/perllib/classify");
[14942]50 }
51 }
[1244]52}
53
54use plugin;
55use util;
[5606]56use gsprintf;
57use printusage;
[10230]58use parse2;
[5606]59
60my $arguments =
[12639]61 [ { 'name' => "collection",
62 'desc' => "{pluginfo.collection}",
[5606]63 'type' => "string",
64 'reqd' => "no" },
65 { 'name' => "xml",
66 'desc' => "{scripts.xml}",
67 'type' => "flag",
68 'reqd' => "no" },
[7952]69 { 'name' => "listall",
70 'desc' => "{scripts.listall}",
71 'type' => "flag",
72 'reqd' => "no" },
[11683]73 { 'name' => "describeall",
74 'desc' => "{scripts.describeall}",
75 'type' => "flag",
76 'reqd' => "no" },
[5606]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
[6921]86sub gsprintf
[5606]87{
[6921]88 return &gsprintf::gsprintf(@_);
[1244]89}
90
91
92sub main {
[12639]93 my $collection = "";
[4749]94 my $xml = 0;
[7952]95 my $listall = 0;
[11683]96 my $describeall = 0;
[6994]97 my ($language, $encoding);
[6988]98
[10230]99 my $hashParsingResult = {};
100 # general options available to all plugins
[10825]101 my $unparsed_args = parse2::parse(\@ARGV,$arguments,$hashParsingResult,"allow_extra_options");
[12545]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
[10230]109 foreach my $strVariable (keys %$hashParsingResult)
110 {
[10825]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";
[10230]117 }
118
[6988]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;
[6994]124 $encoding=$2; # might be undef...
[6988]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
[6945]130 # (Otherwise, the default resource bundle will be loaded automatically)
131 if ($language) {
[6988]132 gsprintf::load_language_specific_resource_bundle($language);
[6994]133 if ($encoding) {
134 $encoding =~ tr/-/_/;
[9375]135 $encoding = lc($encoding);
136 $encoding =~ s/utf_8/utf8/; # special
[6994]137 $gsprintf::specialoutputencoding=$encoding;
138 }
[6945]139 }
[6926]140
[12545]141 # If there is not exactly 1 argument left (plugin name), then the arguments were wrong
[12613]142 # If the user specified -h, then we output the usage also
143 if((@ARGV && $ARGV[0] =~ /^\-+h/) )
[10825]144 {
[12545]145 PrintUsage::print_txt_usage($options, "{pluginfo.params}");
146 die "\n";
[10825]147 }
[12613]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) {
[6988]151 gsprintf(STDERR, "{pluginfo.no_plugin_name}\n\n");
152 PrintUsage::print_txt_usage($options, "{pluginfo.params}", 1);
[4749]153 die "\n";
[1244]154 }
155
[12613]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) {
[15876]166 $plugin =~ s/\.pm$//; # allow xxxPlugin.pm as the argument
[12613]167 }
168
[12639]169 if ($collection ne "") {
170 $ENV{'GSDLCOLLECTDIR'} = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $collection);
[1244]171 } else {
[4749]172 $ENV{'GSDLCOLLECTDIR'} = $ENV{'GSDLHOME'};
[1244]173 }
174
[12629]175 if ($listall || $describeall) {
[12640]176 my $plugins_dir = &util::filename_cat($ENV{'GSDLCOLLECTDIR'}, "perllib", "plugins");
177 my @plugin_list = ();
178 if (opendir (INDIR, $plugins_dir)) {
[15876]179 @plugin_list = grep (/Plugin\.pm$/, readdir (INDIR));
[12640]180 closedir (INDIR);
[12625]181 }
[1244]182
[14958]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)) {
[15876]190 my @ext_plugin_list = grep (/Plugin\.pm$/, readdir (INDIR));
[14958]191 closedir (INDIR);
192
193 push(@plugin_list,@ext_plugin_list);
194 }
195
196 }
197 }
198
[12640]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);
[7952]206 }
[12640]207 else {
208 $plugobj->print_xml_usage(0, 1);
209 }
[7952]210 }
[12640]211 print STDERR "</PluginList>\n";
[4749]212 }
[11683]213 else {
214 &print_single_plugin($plugin, $xml, 1);
215 }
[5638]216}
[4749]217
[12629]218
[11683]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
[5606]237&main ();
Note: See TracBrowser for help on using the repository browser.