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

Last change on this file since 13948 was 12640, checked in by mdewsnip, 18 years ago

Now returns valid XML instead of an error when -listall and -describeall is specified and the directory doesn't exist (usually collection-specific).

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 6.2 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' => "collection",
49 'desc' => "{plugoutinfo.collection}",
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 $collection = "";
81 my $xml = 0;
82 my $listall = 0;
83 my $describeall = 0;
84 my ($language, $encoding);
85
86 my $hashParsingResult = {};
87 # general options available to all plugouts
88 my $unparsed_args = parse2::parse(\@ARGV,$arguments,$hashParsingResult,"allow_extra_options");
89
90 # parse returns -1 if an error occurred
91 if ($unparsed_args == -1) {
92
93 PrintUsage::print_txt_usage($options, "{plugoutinfo.params}");
94 die "\n";
95 }
96
97 foreach my $strVariable (keys %$hashParsingResult)
98 {
99 my $value = $hashParsingResult->{$strVariable};
100 # test to make sure the variable name is 'safe'
101 if ($strVariable !~ /^\w+$/) {
102 die "variable name '$strVariable' isn't safe!";
103 }
104 eval "\$$strVariable = \$value";
105
106 }
107
108 # if language wasn't specified, see if it is set in the environment
109 # (LC_ALL or LANG)
110 if (!$language && ($_=$ENV{'LC_ALL'} or $_=$ENV{'LANG'})) {
111 m/^([^\.]+)\.?(.*)/;
112 $language=$1;
113 $encoding=$2; # might be undef...
114# gsprintf::load_language* thinks "fr" is completely different to "fr_FR"...
115 $language =~ s/_.*$//;
116 }
117
118 # If $language has been set, load the appropriate resource bundle
119 # (Otherwise, the default resource bundle will be loaded automatically)
120 if ($language) {
121 gsprintf::load_language_specific_resource_bundle($language);
122 if ($encoding) {
123 $encoding =~ tr/-/_/;
124 $encoding = lc($encoding);
125 $encoding =~ s/utf_8/utf8/; # special
126 $gsprintf::specialoutputencoding=$encoding;
127 }
128 }
129
130 # If there is not exactly 1 argument left (plugout name), then the arguments were wrong
131 # Or if the user specified -h, then we output the usage also
132 if(@ARGV && $ARGV[0] =~ /^\-+h/ )
133 {
134 PrintUsage::print_txt_usage($options, "{plugoutinfo.params}");
135 die "\n";
136 }
137
138 # If there is not exactly 1 argument left (plugout name), then the arguments were wrong (apart from if we had listall or describeall set)
139 if ($listall == 0 && $describeall ==0 && $unparsed_args == 0) {
140 gsprintf(STDERR, "{plugoutinfo.no_plugout_name}\n\n");
141 PrintUsage::print_txt_usage($options, "{plugoutinfo.params}", 1);
142 die "\n";
143 }
144
145 # we had some arguments that we weren't expecting
146 if ($unparsed_args > 1) {
147 pop(@ARGV); # assume that the last arg is the plugout name
148 gsprintf(STDERR, "{common.invalid_options}\n\n", join (',', @ARGV));
149 PrintUsage::print_txt_usage($options, "{plugoutinfo.params}", 1);
150 die "\n";
151 }
152
153 my $plugout = shift (@ARGV);
154 if (defined $plugout) {
155 $plugout =~ s/\.pm$//; # allow xxxPlugout.pm as the argument
156 }
157
158 if ($collection ne "") {
159 $ENV{'GSDLCOLLECTDIR'} = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $collection);
160 } else {
161 $ENV{'GSDLCOLLECTDIR'} = $ENV{'GSDLHOME'};
162 }
163
164 if ($listall || $describeall) {
165 my $plugouts_dir = &util::filename_cat($ENV{'GSDLCOLLECTDIR'}, "perllib", "plugouts");
166 my @plugout_list = ();
167 if (opendir (INDIR, $plugouts_dir)) {
168 @plugout_list = grep (/Plugout\.pm$/, readdir (INDIR));
169 closedir (INDIR);
170 }
171
172 print STDERR "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
173 print STDERR "<PlugoutList length=\"" . scalar(@plugout_list) . "\">\n";
174 foreach my $plugout (@plugout_list) {
175 $plugout =~ s/\.pm$//;
176 my $plugoutobj = &plugout::load_plugout ($plugout);
177 if ($describeall) {
178 $plugoutobj->print_xml_usage(0);
179 }
180 else {
181 $plugoutobj->print_xml_usage(0, 1);
182 }
183 }
184 print STDERR "</PlugoutList>\n";
185 }
186 else {
187 &print_single_plugout($plugout, $xml, 1);
188 }
189}
190
191
192sub print_single_plugout {
193 my ($plugout, $xml, $header) = @_;
194 my $plugoutobj = &plugout::load_plugout($plugout,[]);
195
196 if ($xml) {
197 $plugoutobj->print_xml_usage($header);
198 }
199 else {
200 gsprintf(STDERR, "\n{plugoutinfo.passing_options}\n\n");
201 gsprintf(STDERR, "{plugoutinfo.option_types}:\n\n");
202 gsprintf(STDERR, "{plugoutinfo.specific_options}\n\n");
203 gsprintf(STDERR, "{plugoutinfo.general_options}\n\n");
204 gsprintf(STDERR, "$plugout {plugoutinfo.info}:\n\n");
205
206 $plugoutobj->print_txt_usage();
207 }
208
209}
210
211&main ();
Note: See TracBrowser for help on using the repository browser.