[16025] | 1 | ###########################################################################
|
---|
| 2 | #
|
---|
| 3 | # PrintInfo - most base plugin
|
---|
| 4 | #
|
---|
| 5 | # A component of the Greenstone digital library software
|
---|
| 6 | # from the New Zealand Digital Library Project at the
|
---|
| 7 | # University of Waikato, New Zealand.
|
---|
| 8 | #
|
---|
| 9 | # Copyright (C) 2008 New Zealand Digital Library Project
|
---|
| 10 | #
|
---|
| 11 | # This program is free software; you can redistribute it and/or modify
|
---|
| 12 | # it under the terms of the GNU General Public License as published by
|
---|
| 13 | # the Free Software Foundation; either version 2 of the License, or
|
---|
| 14 | # (at your option) any later version.
|
---|
| 15 | #
|
---|
| 16 | # This program is distributed in the hope that it will be useful,
|
---|
| 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 19 | # GNU General Public License for more details.
|
---|
| 20 | #
|
---|
| 21 | # You should have received a copy of the GNU General Public License
|
---|
| 22 | # along with this program; if not, write to the Free Software
|
---|
| 23 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 24 | #
|
---|
| 25 | ###########################################################################
|
---|
| 26 |
|
---|
[15868] | 27 | ## Most basic plugin, just handles parsing the arguments and printing out descriptions. Used for plugins and Extractor plugins
|
---|
| 28 |
|
---|
| 29 | package PrintInfo;
|
---|
| 30 |
|
---|
| 31 | BEGIN {
|
---|
| 32 | die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | eval {require bytes};
|
---|
[16639] | 36 | eval "require diagnostics"; # some perl distros (eg mac) don't have this
|
---|
[15868] | 37 |
|
---|
| 38 | # suppress the annoying "subroutine redefined" warning that various
|
---|
| 39 | # plugins cause under perl 5.6
|
---|
| 40 | $SIG{__WARN__} = sub {warn($_[0]) unless ($_[0] =~ /Subroutine\s+\S+\sredefined/)};
|
---|
| 41 |
|
---|
| 42 | use strict;
|
---|
| 43 | no strict 'subs';
|
---|
| 44 |
|
---|
| 45 | use gsprintf 'gsprintf';
|
---|
| 46 | use parse2;
|
---|
| 47 | use printusage;
|
---|
| 48 |
|
---|
[25957] | 49 | my $arguments = [
|
---|
| 50 | { 'name' => "gs_version",
|
---|
| 51 | 'desc' => "{PrintInfo.gs_version}",
|
---|
| 52 | 'type' => "string",
|
---|
| 53 | 'reqd' => "no",
|
---|
| 54 | 'hiddengli' => "yes" }
|
---|
[15868] | 55 |
|
---|
[25957] | 56 | ];
|
---|
| 57 |
|
---|
[15868] | 58 | my $options = { 'name' => "PrintInfo",
|
---|
| 59 | 'desc' => "{PrintInfo.desc}",
|
---|
| 60 | 'abstract' => "yes",
|
---|
| 61 | 'inherits' => "no",
|
---|
| 62 | 'args' => $arguments };
|
---|
| 63 |
|
---|
[15881] | 64 | # $auxiliary_plugin argument passed in by "on-the-side" plugin helpers such as Extractors and ImageConverter. We don't want parsing of args done by them.
|
---|
[15868] | 65 | sub new
|
---|
| 66 | {
|
---|
| 67 | my $class = shift (@_);
|
---|
[15881] | 68 | my ($pluginlist,$args,$hashArgOptLists, $auxiliary) = @_;
|
---|
[15868] | 69 | my $plugin_name = (defined $pluginlist->[0]) ? $pluginlist->[0] : $class;
|
---|
| 70 |
|
---|
[25957] | 71 | if ($plugin_name eq $class) {
|
---|
[15868] | 72 | push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
|
---|
| 73 | push(@{$hashArgOptLists->{"OptList"}},$options);
|
---|
[25957] | 74 | }
|
---|
[15868] | 75 | my $self = {};
|
---|
| 76 | $self->{'outhandle'} = STDERR;
|
---|
| 77 | $self->{'option_list'} = $hashArgOptLists->{"OptList"};
|
---|
| 78 | $self->{"info_only"} = 0;
|
---|
[25957] | 79 | $self->{'gs_version'} = "2";
|
---|
[15868] | 80 | # Check if gsdlinfo is in the argument list or not - if it is, don't parse
|
---|
[25957] | 81 | # the args, just return the object.
|
---|
| 82 | # gsdlinfo must come before gs_version. both are set by plugin.pm
|
---|
| 83 | my $v=0;
|
---|
[15868] | 84 | foreach my $strArg (@{$args})
|
---|
| 85 | {
|
---|
[25957] | 86 | if ($v) {
|
---|
| 87 | $self->{'gs_version'} = $strArg;
|
---|
| 88 | last;
|
---|
| 89 | }
|
---|
| 90 | elsif($strArg eq "-gsdlinfo")
|
---|
[15868] | 91 | {
|
---|
| 92 | $self->{"info_only"} = 1;
|
---|
[25957] | 93 | #return bless $self, $class;
|
---|
[15868] | 94 | }
|
---|
[25957] | 95 | elsif ($strArg eq "-gs_version") {
|
---|
| 96 | $v = 1;
|
---|
| 97 | }
|
---|
[15868] | 98 | }
|
---|
[25957] | 99 |
|
---|
| 100 | if ($self->{"info_only"}) {
|
---|
| 101 | return bless $self, $class;
|
---|
| 102 | }
|
---|
[15881] | 103 | if (defined $auxiliary) { # don't parse the args here
|
---|
| 104 | return bless $self, $class;
|
---|
| 105 | }
|
---|
| 106 |
|
---|
[25957] | 107 | # now that we are passed printing out info, we do need to add in this class's options so that they are available for parsing.
|
---|
| 108 | if ($plugin_name ne $class) {
|
---|
| 109 | push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
|
---|
| 110 | push(@{$hashArgOptLists->{"OptList"}},$options);
|
---|
| 111 | }
|
---|
| 112 |
|
---|
[15868] | 113 | if(parse2::parse($args,$hashArgOptLists->{"ArgList"},$self) == -1)
|
---|
| 114 | {
|
---|
| 115 | my $classTempClass = bless $self, $class;
|
---|
| 116 | print STDERR "<BadPlugin p=$plugin_name>\n";
|
---|
[15881] | 117 | &gsprintf(STDERR, "\n{PrintInfo.bad_general_option}\n", $plugin_name);
|
---|
[15868] | 118 | $classTempClass->print_txt_usage(""); # Use default resource bundle
|
---|
| 119 | die "\n";
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 | delete $self->{"info_only"};
|
---|
| 123 | # else parsing was successful.
|
---|
| 124 |
|
---|
| 125 | $self->{'plugin_type'} = $plugin_name;
|
---|
| 126 |
|
---|
| 127 | return bless $self, $class;
|
---|
| 128 |
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | #sub init {
|
---|
| 132 | #}
|
---|
| 133 |
|
---|
[20577] | 134 | sub set_incremental {
|
---|
| 135 | my $self = shift(@_);
|
---|
| 136 | my ($incremental_mode) = @_;
|
---|
| 137 |
|
---|
| 138 | if (!defined $incremental_mode) {
|
---|
| 139 | $self->{'incremental'} = 0;
|
---|
| 140 | $self->{'incremental_mode'} = "none";
|
---|
| 141 | }
|
---|
[20682] | 142 | elsif ($incremental_mode eq "all") {
|
---|
| 143 | $self->{'incremental'} = 1;
|
---|
| 144 | $self->{'incremental_mode'} = "all";
|
---|
[20577] | 145 | }
|
---|
| 146 | else {
|
---|
[20682] | 147 | # none, onlyadd
|
---|
| 148 | $self->{'incremental'} = 0;
|
---|
[20577] | 149 | $self->{'incremental_mode'} = $incremental_mode;
|
---|
| 150 | }
|
---|
| 151 | }
|
---|
| 152 |
|
---|
[15868] | 153 | sub get_arguments
|
---|
| 154 | {
|
---|
| 155 | my $self = shift(@_);
|
---|
| 156 | my $optionlistref = $self->{'option_list'};
|
---|
| 157 | my @optionlist = @$optionlistref;
|
---|
| 158 | my $pluginoptions = pop(@$optionlistref);
|
---|
| 159 | my $pluginarguments = $pluginoptions->{'args'};
|
---|
| 160 | return $pluginarguments;
|
---|
| 161 | }
|
---|
| 162 |
|
---|
| 163 |
|
---|
| 164 | sub print_xml_usage
|
---|
| 165 | {
|
---|
| 166 | my $self = shift(@_);
|
---|
| 167 | my $header = shift(@_);
|
---|
| 168 | my $high_level_information_only = shift(@_);
|
---|
| 169 |
|
---|
| 170 | # XML output is always in UTF-8
|
---|
| 171 | gsprintf::output_strings_in_UTF8;
|
---|
| 172 |
|
---|
| 173 | if ($header) {
|
---|
| 174 | &PrintUsage::print_xml_header("plugin");
|
---|
| 175 | }
|
---|
| 176 | $self->print_xml($high_level_information_only);
|
---|
| 177 | }
|
---|
| 178 |
|
---|
| 179 |
|
---|
| 180 | sub print_xml
|
---|
| 181 | {
|
---|
| 182 | my $self = shift(@_);
|
---|
| 183 | my $high_level_information_only = shift(@_);
|
---|
| 184 |
|
---|
| 185 | my $optionlistref = $self->{'option_list'};
|
---|
| 186 | my @optionlist = @$optionlistref;
|
---|
| 187 | my $pluginoptions = shift(@$optionlistref);
|
---|
| 188 | return if (!defined($pluginoptions));
|
---|
| 189 |
|
---|
| 190 | # Find the process and block default expressions in the plugin arguments
|
---|
| 191 | my $process_exp = "";
|
---|
| 192 | my $block_exp = "";
|
---|
| 193 | if (defined($pluginoptions->{'args'})) {
|
---|
| 194 | foreach my $option (@{$pluginoptions->{'args'}}) {
|
---|
| 195 | if ($option->{'name'} eq "process_exp") {
|
---|
| 196 | $process_exp = $option->{'deft'};
|
---|
| 197 | }
|
---|
| 198 | if ($option->{'name'} eq "block_exp") {
|
---|
| 199 | $block_exp = $option->{'deft'};
|
---|
| 200 | }
|
---|
| 201 | }
|
---|
| 202 | }
|
---|
| 203 |
|
---|
| 204 | gsprintf(STDERR, "<PlugInfo>\n");
|
---|
| 205 | gsprintf(STDERR, " <Name>$pluginoptions->{'name'}</Name>\n");
|
---|
| 206 | my $desc = gsprintf::lookup_string($pluginoptions->{'desc'});
|
---|
| 207 | $desc =~ s/</&lt;/g; # doubly escaped
|
---|
| 208 | $desc =~ s/>/&gt;/g;
|
---|
| 209 | gsprintf(STDERR, " <Desc>$desc</Desc>\n");
|
---|
| 210 | gsprintf(STDERR, " <Abstract>$pluginoptions->{'abstract'}</Abstract>\n");
|
---|
| 211 | gsprintf(STDERR, " <Inherits>$pluginoptions->{'inherits'}</Inherits>\n");
|
---|
| 212 | gsprintf(STDERR, " <Processes>$process_exp</Processes>\n");
|
---|
| 213 | gsprintf(STDERR, " <Blocks>$block_exp</Blocks>\n");
|
---|
| 214 | gsprintf(STDERR, " <Explodes>" . ($pluginoptions->{'explodes'} || "no") . "</Explodes>\n");
|
---|
| 215 | # adding new option that works with replace_srcdoc_with_html.pl
|
---|
| 216 | gsprintf(STDERR, " <SourceReplaceable>" . ($pluginoptions->{'srcreplaceable'} || "no") . "</SourceReplaceable>\n");
|
---|
| 217 | unless (defined($high_level_information_only)) {
|
---|
| 218 | gsprintf(STDERR, " <Arguments>\n");
|
---|
| 219 | if (defined($pluginoptions->{'args'})) {
|
---|
| 220 | &PrintUsage::print_options_xml($pluginoptions->{'args'});
|
---|
| 221 | }
|
---|
| 222 | gsprintf(STDERR, " </Arguments>\n");
|
---|
| 223 |
|
---|
| 224 | # Recurse up the plugin hierarchy
|
---|
| 225 | $self->print_xml();
|
---|
| 226 | }
|
---|
| 227 | gsprintf(STDERR, "</PlugInfo>\n");
|
---|
| 228 | }
|
---|
| 229 |
|
---|
| 230 |
|
---|
| 231 | sub print_txt_usage
|
---|
| 232 | {
|
---|
| 233 | my $self = shift(@_);
|
---|
| 234 | # Print the usage message for a plugin (recursively)
|
---|
| 235 | my $descoffset = $self->determine_description_offset(0);
|
---|
| 236 | $self->print_plugin_usage($descoffset, 1);
|
---|
| 237 | }
|
---|
| 238 |
|
---|
| 239 |
|
---|
| 240 | sub determine_description_offset
|
---|
| 241 | {
|
---|
| 242 | my $self = shift(@_);
|
---|
| 243 | my $maxoffset = shift(@_);
|
---|
| 244 |
|
---|
| 245 | my $optionlistref = $self->{'option_list'};
|
---|
| 246 | my @optionlist = @$optionlistref;
|
---|
| 247 | my $pluginoptions = shift(@$optionlistref);
|
---|
| 248 | return $maxoffset if (!defined($pluginoptions));
|
---|
| 249 |
|
---|
| 250 | # Find the length of the longest option string of this plugin
|
---|
| 251 | my $pluginargs = $pluginoptions->{'args'};
|
---|
| 252 | if (defined($pluginargs)) {
|
---|
| 253 | my $longest = &PrintUsage::find_longest_option_string($pluginargs);
|
---|
| 254 | if ($longest > $maxoffset) {
|
---|
| 255 | $maxoffset = $longest;
|
---|
| 256 | }
|
---|
| 257 | }
|
---|
| 258 |
|
---|
| 259 | # Recurse up the plugin hierarchy
|
---|
| 260 | $maxoffset = $self->determine_description_offset($maxoffset);
|
---|
| 261 | $self->{'option_list'} = \@optionlist;
|
---|
| 262 | return $maxoffset;
|
---|
| 263 | }
|
---|
| 264 |
|
---|
| 265 |
|
---|
| 266 | sub print_plugin_usage
|
---|
| 267 | {
|
---|
| 268 | my $self = shift(@_);
|
---|
| 269 | my $descoffset = shift(@_);
|
---|
| 270 | my $isleafclass = shift(@_);
|
---|
| 271 |
|
---|
| 272 | my $optionlistref = $self->{'option_list'};
|
---|
| 273 | my @optionlist = @$optionlistref;
|
---|
| 274 | my $pluginoptions = shift(@$optionlistref);
|
---|
| 275 | return if (!defined($pluginoptions));
|
---|
| 276 |
|
---|
| 277 | my $pluginname = $pluginoptions->{'name'};
|
---|
| 278 | my $pluginargs = $pluginoptions->{'args'};
|
---|
| 279 | my $plugindesc = $pluginoptions->{'desc'};
|
---|
| 280 |
|
---|
| 281 | # Produce the usage information using the data structure above
|
---|
| 282 | if ($isleafclass) {
|
---|
| 283 | if (defined($plugindesc)) {
|
---|
| 284 | gsprintf(STDERR, "$plugindesc\n\n");
|
---|
| 285 | }
|
---|
| 286 | gsprintf(STDERR, " {common.usage}: plugin $pluginname [{common.options}]\n\n");
|
---|
| 287 | }
|
---|
| 288 |
|
---|
| 289 | # Display the plugin options, if there are some
|
---|
| 290 | if (defined($pluginargs)) {
|
---|
| 291 | # Calculate the column offset of the option descriptions
|
---|
| 292 | my $optiondescoffset = $descoffset + 2; # 2 spaces between options & descriptions
|
---|
| 293 |
|
---|
| 294 | if ($isleafclass) {
|
---|
| 295 | gsprintf(STDERR, " {common.specific_options}:\n");
|
---|
| 296 | }
|
---|
| 297 | else {
|
---|
| 298 | gsprintf(STDERR, " {common.general_options}:\n", $pluginname);
|
---|
| 299 | }
|
---|
| 300 |
|
---|
| 301 | # Display the plugin options
|
---|
| 302 | &PrintUsage::print_options_txt($pluginargs, $optiondescoffset);
|
---|
| 303 | }
|
---|
| 304 |
|
---|
| 305 | # Recurse up the plugin hierarchy
|
---|
| 306 | $self->print_plugin_usage($descoffset, 0);
|
---|
| 307 | $self->{'option_list'} = \@optionlist;
|
---|
| 308 | }
|
---|
| 309 |
|
---|
[16025] | 310 |
|
---|
[15868] | 311 | 1;
|
---|
| 312 |
|
---|
| 313 |
|
---|