[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] | 30 | use strict;
|
---|
| 31 | no strict 'subs'; # allow barewords (eg STDERR) as function arguments
|
---|
[3541] | 32 |
|
---|
[1244] | 33 | BEGIN {
|
---|
| 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");
|
---|
[22331] | 38 | # unshift (@INC, "$ENV{'GSDLHOME'}/perllib/cpan/perl-5.8");
|
---|
[1244] | 39 | unshift (@INC, "$ENV{'GSDLHOME'}/perllib/plugins");
|
---|
[14942] | 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");
|
---|
[16787] | 48 | unshift (@INC, "$ext_prefix/perllib/plugins");
|
---|
[14942] | 49 | }
|
---|
| 50 | }
|
---|
[21292] | 51 | if (defined $ENV{'GSDL3EXTS'}) {
|
---|
| 52 | my @extensions = split(/:/,$ENV{'GSDL3EXTS'});
|
---|
| 53 | foreach my $e (@extensions) {
|
---|
| 54 | my $ext_prefix = "$ENV{'GSDL3SRCHOME'}/ext/$e";
|
---|
| 55 |
|
---|
| 56 | unshift (@INC, "$ext_prefix/perllib");
|
---|
| 57 | unshift (@INC, "$ext_prefix/perllib/cpan");
|
---|
| 58 | unshift (@INC, "$ext_prefix/perllib/plugins");
|
---|
| 59 | }
|
---|
| 60 | }
|
---|
| 61 |
|
---|
[1244] | 62 | }
|
---|
| 63 |
|
---|
| 64 | use plugin;
|
---|
| 65 | use util;
|
---|
[5606] | 66 | use gsprintf;
|
---|
| 67 | use printusage;
|
---|
[10230] | 68 | use parse2;
|
---|
[5606] | 69 |
|
---|
| 70 | my $arguments =
|
---|
[24748] | 71 | [ { 'name' => "site",
|
---|
| 72 | 'desc' => "{pluginfo.site}",
|
---|
| 73 | 'type' => "string",
|
---|
| 74 | 'reqd' => "no" },
|
---|
| 75 | { 'name' => "collection",
|
---|
[12639] | 76 | 'desc' => "{pluginfo.collection}",
|
---|
[5606] | 77 | 'type' => "string",
|
---|
| 78 | 'reqd' => "no" },
|
---|
| 79 | { 'name' => "xml",
|
---|
| 80 | 'desc' => "{scripts.xml}",
|
---|
| 81 | 'type' => "flag",
|
---|
| 82 | 'reqd' => "no" },
|
---|
[7952] | 83 | { 'name' => "listall",
|
---|
| 84 | 'desc' => "{scripts.listall}",
|
---|
| 85 | 'type' => "flag",
|
---|
| 86 | 'reqd' => "no" },
|
---|
[11683] | 87 | { 'name' => "describeall",
|
---|
| 88 | 'desc' => "{scripts.describeall}",
|
---|
| 89 | 'type' => "flag",
|
---|
| 90 | 'reqd' => "no" },
|
---|
[5606] | 91 | { 'name' => "language",
|
---|
| 92 | 'desc' => "{scripts.language}",
|
---|
| 93 | 'type' => "string",
|
---|
| 94 | 'reqd' => "no" } ];
|
---|
| 95 |
|
---|
| 96 | my $options = { 'name' => "pluginfo.pl",
|
---|
| 97 | 'desc' => "{pluginfo.desc}",
|
---|
| 98 | 'args' => $arguments };
|
---|
| 99 |
|
---|
[6921] | 100 | sub gsprintf
|
---|
[5606] | 101 | {
|
---|
[6921] | 102 | return &gsprintf::gsprintf(@_);
|
---|
[1244] | 103 | }
|
---|
| 104 |
|
---|
| 105 |
|
---|
| 106 | sub main {
|
---|
[24748] | 107 | my $site = "";
|
---|
[12639] | 108 | my $collection = "";
|
---|
[4749] | 109 | my $xml = 0;
|
---|
[7952] | 110 | my $listall = 0;
|
---|
[11683] | 111 | my $describeall = 0;
|
---|
[6994] | 112 | my ($language, $encoding);
|
---|
[6988] | 113 |
|
---|
[10230] | 114 | my $hashParsingResult = {};
|
---|
| 115 | # general options available to all plugins
|
---|
[10825] | 116 | my $unparsed_args = parse2::parse(\@ARGV,$arguments,$hashParsingResult,"allow_extra_options");
|
---|
[12545] | 117 | # parse returns -1 if an error occurred
|
---|
| 118 | if ($unparsed_args == -1) {
|
---|
| 119 |
|
---|
| 120 | PrintUsage::print_txt_usage($options, "{pluginfo.params}");
|
---|
| 121 | die "\n";
|
---|
| 122 | }
|
---|
| 123 |
|
---|
[10230] | 124 | foreach my $strVariable (keys %$hashParsingResult)
|
---|
| 125 | {
|
---|
[10825] | 126 | my $value = $hashParsingResult->{$strVariable};
|
---|
| 127 | # test to make sure the variable name is 'safe'
|
---|
| 128 | if ($strVariable !~ /^\w+$/) {
|
---|
| 129 | die "variable name '$strVariable' isn't safe!";
|
---|
| 130 | }
|
---|
| 131 | eval "\$$strVariable = \$value";
|
---|
[10230] | 132 | }
|
---|
| 133 |
|
---|
[6988] | 134 | # if language wasn't specified, see if it is set in the environment
|
---|
| 135 | # (LC_ALL or LANG)
|
---|
| 136 | if (!$language && ($_=$ENV{'LC_ALL'} or $_=$ENV{'LANG'})) {
|
---|
| 137 | m/^([^\.]+)\.?(.*)/;
|
---|
| 138 | $language=$1;
|
---|
[6994] | 139 | $encoding=$2; # might be undef...
|
---|
[6988] | 140 | # gsprintf::load_language* thinks "fr" is completely different to "fr_FR"...
|
---|
| 141 | $language =~ s/_.*$//;
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | # If $language has been set, load the appropriate resource bundle
|
---|
[6945] | 145 | # (Otherwise, the default resource bundle will be loaded automatically)
|
---|
| 146 | if ($language) {
|
---|
[6988] | 147 | gsprintf::load_language_specific_resource_bundle($language);
|
---|
[6994] | 148 | if ($encoding) {
|
---|
| 149 | $encoding =~ tr/-/_/;
|
---|
[9375] | 150 | $encoding = lc($encoding);
|
---|
| 151 | $encoding =~ s/utf_8/utf8/; # special
|
---|
[6994] | 152 | $gsprintf::specialoutputencoding=$encoding;
|
---|
| 153 | }
|
---|
[6945] | 154 | }
|
---|
[6926] | 155 |
|
---|
[12545] | 156 | # If there is not exactly 1 argument left (plugin name), then the arguments were wrong
|
---|
[12613] | 157 | # If the user specified -h, then we output the usage also
|
---|
| 158 | if((@ARGV && $ARGV[0] =~ /^\-+h/) )
|
---|
[10825] | 159 | {
|
---|
[12545] | 160 | PrintUsage::print_txt_usage($options, "{pluginfo.params}");
|
---|
| 161 | die "\n";
|
---|
[10825] | 162 | }
|
---|
[12613] | 163 |
|
---|
| 164 | # If there is not exactly 1 argument left (plugin name), then the arguments were wrong (apart from if we had listall or describeall set)
|
---|
| 165 | if ($listall == 0 && $describeall ==0 && $unparsed_args == 0) {
|
---|
[6988] | 166 | gsprintf(STDERR, "{pluginfo.no_plugin_name}\n\n");
|
---|
| 167 | PrintUsage::print_txt_usage($options, "{pluginfo.params}", 1);
|
---|
[4749] | 168 | die "\n";
|
---|
[1244] | 169 | }
|
---|
| 170 |
|
---|
[12613] | 171 | # we had some arguments that we weren't expecting
|
---|
| 172 | if ($unparsed_args > 1) {
|
---|
| 173 | pop(@ARGV); # assume that the last arg is the plugin name
|
---|
| 174 | gsprintf(STDERR, "{common.invalid_options}\n\n", join (',', @ARGV));
|
---|
| 175 | PrintUsage::print_txt_usage($options, "{pluginfo.params}", 1);
|
---|
| 176 | die "\n";
|
---|
| 177 | }
|
---|
| 178 |
|
---|
| 179 | my $plugin = shift (@ARGV);
|
---|
| 180 | if (defined $plugin) {
|
---|
[15876] | 181 | $plugin =~ s/\.pm$//; # allow xxxPlugin.pm as the argument
|
---|
[12613] | 182 | }
|
---|
| 183 |
|
---|
[24748] | 184 | if ($site ne "") {
|
---|
| 185 | # assume Greenstone 3
|
---|
| 186 | if ($collection ne "") {
|
---|
| 187 | $ENV{'GSDLCOLLECTDIR'} = &util::filename_cat ($ENV{'GSDL3HOME'}, "sites", $site, "collect", $collection);
|
---|
| 188 | } else {
|
---|
| 189 | # Probably more useful to default to GS2 area for plugins
|
---|
| 190 | $ENV{'GSDLCOLLECTDIR'} = $ENV{'GSDLHOME'};
|
---|
| 191 | }
|
---|
[1244] | 192 | }
|
---|
[24748] | 193 | else {
|
---|
| 194 | if ($collection ne "") {
|
---|
| 195 | $ENV{'GSDLCOLLECTDIR'} = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $collection);
|
---|
| 196 | } else {
|
---|
| 197 | $ENV{'GSDLCOLLECTDIR'} = $ENV{'GSDLHOME'};
|
---|
| 198 | }
|
---|
| 199 | }
|
---|
[1244] | 200 |
|
---|
[12629] | 201 | if ($listall || $describeall) {
|
---|
[12640] | 202 | my $plugins_dir = &util::filename_cat($ENV{'GSDLCOLLECTDIR'}, "perllib", "plugins");
|
---|
| 203 | my @plugin_list = ();
|
---|
| 204 | if (opendir (INDIR, $plugins_dir)) {
|
---|
[15876] | 205 | @plugin_list = grep (/Plugin\.pm$/, readdir (INDIR));
|
---|
[12640] | 206 | closedir (INDIR);
|
---|
[12625] | 207 | }
|
---|
[1244] | 208 |
|
---|
[14958] | 209 | if ((defined $ENV{'GSDLEXTS'}) && ($collection eq "")) {
|
---|
| 210 | my @extensions = split(/:/,$ENV{'GSDLEXTS'});
|
---|
| 211 | foreach my $e (@extensions) {
|
---|
| 212 | my $ext_prefix = &util::filename_cat($ENV{'GSDLHOME'},"ext",$e);
|
---|
| 213 | my $ext_plugins_dir = &util::filename_cat($ext_prefix, "perllib", "plugins");
|
---|
| 214 |
|
---|
| 215 | if (opendir (INDIR, $ext_plugins_dir)) {
|
---|
[15876] | 216 | my @ext_plugin_list = grep (/Plugin\.pm$/, readdir (INDIR));
|
---|
[14958] | 217 | closedir (INDIR);
|
---|
| 218 |
|
---|
| 219 | push(@plugin_list,@ext_plugin_list);
|
---|
| 220 | }
|
---|
| 221 |
|
---|
| 222 | }
|
---|
| 223 | }
|
---|
[21292] | 224 | if ((defined $ENV{'GSDL3EXTS'}) && ($collection eq "")) {
|
---|
| 225 | my @extensions = split(/:/,$ENV{'GSDL3EXTS'});
|
---|
| 226 | foreach my $e (@extensions) {
|
---|
| 227 | my $ext_prefix = &util::filename_cat($ENV{'GSDL3SRCHOME'},"ext",$e);
|
---|
| 228 | my $ext_plugins_dir = &util::filename_cat($ext_prefix, "perllib", "plugins");
|
---|
[14958] | 229 |
|
---|
[21292] | 230 | if (opendir (INDIR, $ext_plugins_dir)) {
|
---|
| 231 | my @ext_plugin_list = grep (/Plugin\.pm$/, readdir (INDIR));
|
---|
| 232 | closedir (INDIR);
|
---|
| 233 |
|
---|
| 234 | push(@plugin_list,@ext_plugin_list);
|
---|
| 235 | }
|
---|
| 236 |
|
---|
| 237 | }
|
---|
| 238 | }
|
---|
| 239 |
|
---|
[12640] | 240 | print STDERR "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
|
---|
| 241 | print STDERR "<PluginList length=\"" . scalar(@plugin_list) . "\">\n";
|
---|
| 242 | foreach my $plugin (@plugin_list) {
|
---|
| 243 | $plugin =~ s/\.pm$//;
|
---|
| 244 | my $plugobj = &plugin::load_plugin_for_info ($plugin);
|
---|
| 245 | if ($describeall) {
|
---|
| 246 | $plugobj->print_xml_usage(0);
|
---|
[7952] | 247 | }
|
---|
[12640] | 248 | else {
|
---|
| 249 | $plugobj->print_xml_usage(0, 1);
|
---|
| 250 | }
|
---|
[7952] | 251 | }
|
---|
[12640] | 252 | print STDERR "</PluginList>\n";
|
---|
[4749] | 253 | }
|
---|
[11683] | 254 | else {
|
---|
| 255 | &print_single_plugin($plugin, $xml, 1);
|
---|
| 256 | }
|
---|
[5638] | 257 | }
|
---|
[4749] | 258 |
|
---|
[12629] | 259 |
|
---|
[11683] | 260 | sub print_single_plugin {
|
---|
| 261 | my ($plugin, $xml, $header) = @_;
|
---|
| 262 | my $plugobj = &plugin::load_plugin_for_info ($plugin);
|
---|
| 263 | if ($xml) {
|
---|
| 264 | $plugobj->print_xml_usage($header);
|
---|
| 265 | }
|
---|
| 266 | else {
|
---|
[22518] | 267 |
|
---|
| 268 | # this causes us to automatically send output to a pager, if one is
|
---|
| 269 | # set, AND our output is going to a terminal
|
---|
| 270 | # active state perl on windows doesn't do open(handle, "-|");
|
---|
| 271 | if ($ENV{'GSDLOS'} !~ /windows/ && -t STDOUT) {
|
---|
| 272 | my $pager = $ENV{"PAGER"};
|
---|
| 273 | if (! $pager) {$pager="(less || more)"}
|
---|
| 274 | my $pid = open(STDIN, "-|"); # this does a fork... see man perlipc(1)
|
---|
| 275 | if (!defined $pid) {
|
---|
| 276 | gsprintf(STDERR, "pluginfo.pl - can't fork: $!");
|
---|
| 277 | } else {
|
---|
| 278 | if ($pid != 0) { # parent (ie forking) process. child gets 0
|
---|
| 279 | exec ($pager);
|
---|
| 280 | }
|
---|
| 281 | }
|
---|
| 282 | open(STDERR,">&STDOUT"); # so it's easier to pipe output
|
---|
| 283 | }
|
---|
| 284 |
|
---|
[11683] | 285 | gsprintf(STDERR, "\n{pluginfo.passing_options}\n\n");
|
---|
| 286 | gsprintf(STDERR, "{pluginfo.option_types}:\n\n");
|
---|
| 287 | gsprintf(STDERR, "{pluginfo.specific_options}\n\n");
|
---|
| 288 | gsprintf(STDERR, "{pluginfo.general_options}\n\n");
|
---|
| 289 | gsprintf(STDERR, "$plugin {pluginfo.info}:\n\n");
|
---|
| 290 |
|
---|
| 291 | $plugobj->print_txt_usage();
|
---|
| 292 | }
|
---|
| 293 |
|
---|
| 294 | }
|
---|
| 295 |
|
---|
[5606] | 296 | &main ();
|
---|