source: trunk/gsdl/bin/script/plugoutinfo.pl@ 12408

Last change on this file since 12408 was 12334, checked in by shaoqun, 18 years ago

a module that displays plugouts info

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 6.6 KB
Line 
1#!/usr/bin/perl -w
2
3###########################################################################
4#
5# plugoutinfo.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 plugout
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/plugouts");
39}
40
41use plugout;
42use util;
43use gsprintf;
44use printusage;
45use parse2;
46
47my $arguments =
48 [ { 'name' => "collect",
49 'desc' => "{plugoutinfo.collect}",
50 'type' => "string",
51 'reqd' => "no" },
52 { 'name' => "xml",
53 'desc' => "{scripts.xml}",
54 'type' => "flag",
55 'reqd' => "no" },
56 { 'name' => "listall",
57 'desc' => "{scripts.listall}",
58 'type' => "flag",
59 'reqd' => "no" },
60 { 'name' => "describeall",
61 'desc' => "{scripts.describeall}",
62 'type' => "flag",
63 'reqd' => "no" },
64 { 'name' => "language",
65 'desc' => "{scripts.language}",
66 'type' => "string",
67 'reqd' => "no" } ];
68
69my $options = { 'name' => "plugoutinfo.pl",
70 'desc' => "{plugoutinfo.desc}",
71 'args' => $arguments };
72
73sub gsprintf
74{
75 return &gsprintf::gsprintf(@_);
76}
77
78
79sub main {
80 my $collect = "";
81 my $xml = 0;
82 my $listall = 0;
83 my $describeall = 0;
84 my ($language, $encoding);
85
86 my $hashParsingResult = {};
87 my $blnParseFailed = "false";
88 # general options available to all plugins
89 my $unparsed_args = parse2::parse(\@ARGV,$arguments,$hashParsingResult,"allow_extra_options");
90
91 foreach my $strVariable (keys %$hashParsingResult)
92 {
93 my $value = $hashParsingResult->{$strVariable};
94 # test to make sure the variable name is 'safe'
95 if ($strVariable !~ /^\w+$/) {
96 die "variable name '$strVariable' isn't safe!";
97 }
98 eval "\$$strVariable = \$value";
99
100 }
101
102
103 # if language wasn't specified, see if it is set in the environment
104 # (LC_ALL or LANG)
105 if (!$language && ($_=$ENV{'LC_ALL'} or $_=$ENV{'LANG'})) {
106 m/^([^\.]+)\.?(.*)/;
107 $language=$1;
108 $encoding=$2; # might be undef...
109# gsprintf::load_language* thinks "fr" is completely different to "fr_FR"...
110 $language =~ s/_.*$//;
111 }
112
113 # If $language has been set, load the appropriate resource bundle
114 # (Otherwise, the default resource bundle will be loaded automatically)
115 if ($language) {
116 gsprintf::load_language_specific_resource_bundle($language);
117 if ($encoding) {
118 $encoding =~ tr/-/_/;
119 $encoding = lc($encoding);
120 $encoding =~ s/utf_8/utf8/; # special
121 $gsprintf::specialoutputencoding=$encoding;
122 }
123 }
124
125 # If there are more than one argument left after parsing, it mean user input too many arguments.
126 # Error occoured will return 0
127 if( $unparsed_args > 1 or (@ARGV && $ARGV[0] =~ /^\-+h/) )
128 {
129 PrintUsage::print_txt_usage($options, "{plugoutinfo.params}");
130 die "\n";
131 }
132
133 my $plugout = shift (@ARGV);
134 if (defined $plugout) {
135 $plugout =~ s/\.pm$//; # allow xxxPlugout.pm as the argument
136 }
137 if (($listall == 0 && $describeall ==0) && (!defined $plugout || $plugout eq "")) {
138 gsprintf(STDERR, "{plugoutinfo.no_plugout_name}\n\n");
139 PrintUsage::print_txt_usage($options, "{plugoutinfo.params}", 1);
140 die "\n";
141 }
142
143 if ($collect ne "") {
144 $ENV{'GSDLCOLLECTDIR'} = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $collect);
145 } else {
146 $ENV{'GSDLCOLLECTDIR'} = $ENV{'GSDLHOME'};
147 }
148
149 if ($listall) {
150 my $plugout_dir = &util::filename_cat($ENV{'GSDLCOLLECTDIR'},"perllib","plugouts");
151
152 if (!opendir (INDIR, $plugout_dir)) {
153 print STDERR "plugoutinfo.pl: could not open directory $plugout_dir\n";
154 } else {
155 my @plugout_list = grep (/Plugout\.pm$/, readdir (INDIR));
156 closedir (INDIR);
157
158
159 if ($xml) {
160 my $num_plugouts = scalar(@plugout_list);
161
162 print STDERR "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
163 print STDERR "<!DOCTYPE PlugoutList [\n";
164 print STDERR " <!ELEMENT PlugoutList (PlugoutName*)>\n";
165 print STDERR " <!ELEMENT PlugoutName (#PCDATA)>\n";
166 print STDERR " <!ATTLIST PlugoutList\n";
167 print STDERR " length CDATA #REQUIRED>\n";
168 print STDERR "]>\n";
169
170 print STDERR "<PlugoutList length=\"$num_plugouts\">\n";
171 map { print STDERR " <PlugoutName>$_</PlugoutName>\n"; } @plugout_list;
172 print STDERR "</PlugoutList>\n";
173
174 }
175 else {
176 print STDERR join(" ",@plugout_list), "\n";
177 }
178 }
179
180 }
181 elsif ($describeall) {
182 my $plugout_dir = &util::filename_cat($ENV{'GSDLCOLLECTDIR'},"perllib","plugouts");
183 my @plugout_list;
184 if (!opendir (INDIR, $plugout_dir)) {
185 print STDERR "plugoutinfo.pl: could not open directory $plugout_dir\n";
186 } else {
187 @plugout_list = grep (/Plugout\.pm$/, readdir (INDIR));
188 closedir (INDIR);
189 }
190 #sort (@plugout_list);
191 if ($xml) {
192 my $num_plugout = scalar(@plugout_list);
193 &PrintUsage::print_xml_header("plugout", 1);
194 print STDERR "<PlugoutInfoList length=\"$num_plugout\">\n";
195 }
196 foreach my $pl (@plugout_list) {
197 $pl =~ s/\.pm$//;
198 &print_single_plugout($pl, $xml, 0);
199 }
200 if ($xml) {
201 print STDERR "</PlugoutInfoList>\n";
202 }
203 }
204 else {
205 &print_single_plugout($plugout, $xml, 1);
206 }
207}
208
209sub print_single_plugout {
210 my ($plugout, $xml, $header) = @_;
211 my $plugoutobj = &plugout::load_plugout($plugout,[]);
212
213 if ($xml) {
214 $plugoutobj->print_xml_usage($header);
215 }
216 else {
217 gsprintf(STDERR, "\n{plugoutinfo.passing_options}\n\n");
218 gsprintf(STDERR, "{plugoutinfo.option_types}:\n\n");
219 gsprintf(STDERR, "{plugoutinfo.specific_options}\n\n");
220 gsprintf(STDERR, "{plugoutinfo.general_options}\n\n");
221 gsprintf(STDERR, "$plugout {plugoutinfo.info}:\n\n");
222
223 $plugoutobj->print_txt_usage();
224 }
225
226}
227
228&main ();
Note: See TracBrowser for help on using the repository browser.