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