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

Last change on this file since 12408 was 11683, checked in by kjdon, 18 years ago

added a -describeall option, so we can generate the descriptive output for all plugins/classifiers at once

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 6.5 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
41use plugin;
42use util;
43use gsprintf;
44use printusage;
45use parse2;
46
47my $arguments =
48 [ { 'name' => "collect",
49 'desc' => "{pluginfo.collect}",
50 'type' => "string",
51 'reqd' => "no" },
52 { 'name' => "xml",
53 'desc' => "{scripts.xml}",
54 'type' => "flag",
55 'reqd' => "no" },
56 { 'name' => "listall",
57 'desc' => "{scripts.listall}",
58 'type' => "flag",
59 'reqd' => "no" },
60 { 'name' => "describeall",
61 'desc' => "{scripts.describeall}",
62 'type' => "flag",
63 'reqd' => "no" },
64 { 'name' => "language",
65 'desc' => "{scripts.language}",
66 'type' => "string",
67 'reqd' => "no" } ];
68
69my $options = { 'name' => "pluginfo.pl",
70 'desc' => "{pluginfo.desc}",
71 'args' => $arguments };
72
73sub gsprintf
74{
75 return &gsprintf::gsprintf(@_);
76}
77
78
79sub main {
80 my $collect = "";
81 my $xml = 0;
82 my $listall = 0;
83 my $describeall = 0;
84 my ($language, $encoding);
85
86 my $hashParsingResult = {};
87 my $blnParseFailed = "false";
88 # general options available to all plugins
89 my $unparsed_args = parse2::parse(\@ARGV,$arguments,$hashParsingResult,"allow_extra_options");
90
91 foreach my $strVariable (keys %$hashParsingResult)
92 {
93 my $value = $hashParsingResult->{$strVariable};
94 # test to make sure the variable name is 'safe'
95 if ($strVariable !~ /^\w+$/) {
96 die "variable name '$strVariable' isn't safe!";
97 }
98 eval "\$$strVariable = \$value";
99 }
100
101 # if language wasn't specified, see if it is set in the environment
102 # (LC_ALL or LANG)
103 if (!$language && ($_=$ENV{'LC_ALL'} or $_=$ENV{'LANG'})) {
104 m/^([^\.]+)\.?(.*)/;
105 $language=$1;
106 $encoding=$2; # might be undef...
107# gsprintf::load_language* thinks "fr" is completely different to "fr_FR"...
108 $language =~ s/_.*$//;
109 }
110
111 # If $language has been set, load the appropriate resource bundle
112 # (Otherwise, the default resource bundle will be loaded automatically)
113 if ($language) {
114 gsprintf::load_language_specific_resource_bundle($language);
115 if ($encoding) {
116 $encoding =~ tr/-/_/;
117 $encoding = lc($encoding);
118 $encoding =~ s/utf_8/utf8/; # special
119 $gsprintf::specialoutputencoding=$encoding;
120 }
121 }
122
123 # If there are more than one argument left after parsing, it mean user input too many arguments.
124 # Error occoured will return 0
125 if( $unparsed_args > 1 or (@ARGV && $ARGV[0] =~ /^\-+h/) )
126 {
127 PrintUsage::print_txt_usage($options, "{pluginfo.params}");
128 die "\n";
129 }
130
131 my $plugin = shift (@ARGV);
132 if (defined $plugin) {
133 $plugin =~ s/\.pm$//; # allow xxxPlug.pm as the argument
134 }
135 if (($listall == 0 && $describeall ==0) && (!defined $plugin || $plugin eq "")) {
136 gsprintf(STDERR, "{pluginfo.no_plugin_name}\n\n");
137 PrintUsage::print_txt_usage($options, "{pluginfo.params}", 1);
138 die "\n";
139 }
140
141 if ($collect ne "") {
142 $ENV{'GSDLCOLLECTDIR'} = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $collect);
143 } else {
144 $ENV{'GSDLCOLLECTDIR'} = $ENV{'GSDLHOME'};
145 }
146
147 if ($listall) {
148 my $plugin_dir = &util::filename_cat($ENV{'GSDLCOLLECTDIR'},"perllib","plugins");
149
150 if (!opendir (INDIR, $plugin_dir)) {
151 print STDERR "pluginfo.pl: could not open directory $plugin_dir\n";
152 } else {
153 my @plugin_list = grep (/Plug\.pm$/, readdir (INDIR));
154 closedir (INDIR);
155
156
157 if ($xml) {
158 my $num_plugins = scalar(@plugin_list);
159
160 print STDERR "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
161 print STDERR "<!DOCTYPE PluginList [\n";
162 print STDERR " <!ELEMENT PluginList (PluginName*)>\n";
163 print STDERR " <!ELEMENT PluginName (#PCDATA)>\n";
164 print STDERR " <!ATTLIST PluginList\n";
165 print STDERR " length CDATA #REQUIRED>\n";
166 print STDERR "]>\n";
167
168 print STDERR "<PluginList length=\"$num_plugins\">\n";
169 map { print STDERR " <PluginName>$_</PluginName>\n"; } @plugin_list;
170 print STDERR "</PluginList>\n";
171
172 }
173 else {
174 print STDERR join(" ",@plugin_list), "\n";
175 }
176 }
177
178 }
179 elsif ($describeall) {
180 my $plugin_dir = &util::filename_cat($ENV{'GSDLCOLLECTDIR'},"perllib","plugins");
181 my @plugin_list;
182 if (!opendir (INDIR, $plugin_dir)) {
183 print STDERR "pluginfo.pl: could not open directory $plugin_dir\n";
184 } else {
185 @plugin_list = grep (/Plug\.pm$/, readdir (INDIR));
186 closedir (INDIR);
187 }
188 #sort (@plugin_list);
189 if ($xml) {
190 my $num_plugin = scalar(@plugin_list);
191 &PrintUsage::print_xml_header("plugin", 1);
192 print STDERR "<PlugInfoList length=\"$num_plugin\">\n";
193 }
194 foreach my $pl (@plugin_list) {
195 $pl =~ s/\.pm$//;
196 &print_single_plugin($pl, $xml, 0);
197 }
198 if ($xml) {
199 print STDERR "</PlugInfoList>\n";
200 }
201 }
202 else {
203 &print_single_plugin($plugin, $xml, 1);
204 }
205}
206
207sub print_single_plugin {
208 my ($plugin, $xml, $header) = @_;
209 my $plugobj = &plugin::load_plugin_for_info ($plugin);
210 if ($xml) {
211 $plugobj->print_xml_usage($header);
212 }
213 else {
214 gsprintf(STDERR, "\n{pluginfo.passing_options}\n\n");
215 gsprintf(STDERR, "{pluginfo.option_types}:\n\n");
216 gsprintf(STDERR, "{pluginfo.specific_options}\n\n");
217 gsprintf(STDERR, "{pluginfo.general_options}\n\n");
218 gsprintf(STDERR, "$plugin {pluginfo.info}:\n\n");
219
220 $plugobj->print_txt_usage();
221 }
222
223}
224
225&main ();
Note: See TracBrowser for help on using the repository browser.