source: main/trunk/greenstone2/bin/script/pluginfo.pl@ 20999

Last change on this file since 20999 was 20571, checked in by davidb, 15 years ago

Introduction of variable 'incremental_mode' that is set to 'none', 'onlyadd', or 'all' depending on settings of -removeold -keepold and -incremental. Some minor edits to tidy up the code have also been made in this commit

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