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