source: gsdl/trunk/bin/script/classinfo.pl@ 16787

Last change on this file since 16787 was 16787, checked in by davidb, 16 years ago

Now checks for extended plugins and classifiers as well as in standard place

  • 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# classinfo.pl -- provide information about classifiers
6#
7# A component of the Greenstone digital library software
8# from the New Zealand Digital Library Project at the
9# University of Waikato, New Zealand.
10#
11# Copyright (C) 1999 New Zealand Digital Library Project
12#
13# This program is free software; you can redistribute it and/or modify
14# it under the terms of the GNU General Public License as published by
15# the Free Software Foundation; either version 2 of the License, or
16# (at your option) any later version.
17#
18# This program is distributed in the hope that it will be useful,
19# but WITHOUT ANY WARRANTY; without even the implied warranty of
20# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21# GNU General Public License for more details.
22#
23# You should have received a copy of the GNU General Public License
24# along with this program; if not, write to the Free Software
25# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26#
27###########################################################################
28
29use strict;
30no strict 'subs'; # allow barewords (eg STDERR) as function arguments
31
32BEGIN {
33 die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
34 die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};
35 unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
36 unshift (@INC, "$ENV{'GSDLHOME'}/perllib/cpan");
37 unshift (@INC, "$ENV{'GSDLHOME'}/perllib/classify");
38
39 if (defined $ENV{'GSDLEXTS'}) {
40 my @extensions = split(/:/,$ENV{'GSDLEXTS'});
41 foreach my $e (@extensions) {
42 my $ext_prefix = "$ENV{'GSDLHOME'}/ext/$e";
43
44 unshift (@INC, "$ext_prefix/perllib");
45 unshift (@INC, "$ext_prefix/perllib/cpan");
46 unshift (@INC, "$ext_prefix/perllib/plugins");
47 unshift (@INC, "$ext_prefix/perllib/plugouts");
48 unshift (@INC, "$ext_prefix/perllib/classify");
49 }
50 }
51}
52
53use classify;
54use util;
55use gsprintf;
56use printusage;
57
58use parse2;
59
60my $arguments =
61 [ { 'name' => "collection",
62 'desc' => "{classinfo.collection}",
63 'type' => "string",
64 'deft' => "",
65 'reqd' => "no" },
66 { 'name' => "xml",
67 'desc' => "{scripts.xml}",
68 'type' => "flag",
69 'reqd' => "no" },
70 { 'name' => "listall",
71 'desc' => "{scripts.listall}",
72 'type' => "flag",
73 'reqd' => "no" },
74 { 'name' => "describeall",
75 'desc' => "{scripts.describeall}",
76 'type' => "flag",
77 'reqd' => "no" },
78 { 'name' => "language",
79 'desc' => "{scripts.language}",
80 'type' => "string",
81 'reqd' => "no" } ];
82
83my $options = { 'name' => "classinfo.pl",
84 'desc' => "{classinfo.desc}",
85 'args' => $arguments };
86
87sub gsprintf
88{
89 return &gsprintf::gsprintf(@_);
90}
91
92sub main {
93 my $collection = "";
94 my $xml = 0;
95 my $listall = 0;
96 my $describeall = 0;
97 my $language;
98
99 my $hashParsingResult = {};
100 # general options available to all classifiers
101 my $intArgLeftinAfterParsing = parse2::parse(\@ARGV,$arguments,$hashParsingResult,"allow_extra_options");
102 # parse returns -1 if an error occurred
103 if($intArgLeftinAfterParsing == -1)
104 {
105 &PrintUsage::print_txt_usage($options, "{classinfo.params}");
106 die "\n";
107 }
108
109 foreach my $strVariable (keys %$hashParsingResult)
110 {
111 eval "\$$strVariable = \$hashParsingResult->{\"\$strVariable\"}";
112 }
113 # If $language has been specified, 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 }
118
119 # If there is not exactly 1 argument left (classifier name), then the arguments were wrong
120 # If the user specified -h, then we output the usage also
121 if((@ARGV && $ARGV[0] =~ /^\-+h/) )
122 {
123 PrintUsage::print_txt_usage($options, "{classinfo.params}");
124 die "\n";
125 }
126
127 # If there is not exactly 1 argument left (classifier name), then the arguments were wrong (apart from if we had listall or describeall set)
128 if ($listall == 0 && $describeall ==0 && $intArgLeftinAfterParsing == 0) {
129 gsprintf(STDERR, "{classinfo.no_classifier_name}\n\n");
130 PrintUsage::print_txt_usage($options, "{classinfo.params}", 1);
131 die "\n";
132 }
133
134 # we had some arguments that we weren't expecting
135 if ($intArgLeftinAfterParsing > 1) {
136 pop(@ARGV); # assume that the last arg is the classifier name
137 gsprintf(STDERR, "{common.invalid_options}\n\n", join (',', @ARGV));
138 PrintUsage::print_txt_usage($options, "{classinfo.params}", 1);
139 die "\n";
140 }
141
142 # Get classifier
143 my $classifier = shift (@ARGV);
144 if (defined $classifier) {
145 $classifier =~ s/\.pm$//; # allow xxx.pm as the argument
146 }
147
148 # make sure the classifier is loaded from the correct location - a hack.
149 if ($collection ne "") {
150 $ENV{'GSDLCOLLECTDIR'} = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $collection);
151 } else {
152 $ENV{'GSDLCOLLECTDIR'} = $ENV{'GSDLHOME'};
153 }
154
155 if ($listall || $describeall) {
156 my $classify_dir = &util::filename_cat($ENV{'GSDLCOLLECTDIR'}, "perllib", "classify");
157 my @classifier_list = ();
158 if (opendir (INDIR, $classify_dir)) {
159 @classifier_list = grep (/\.pm$/, readdir (INDIR));
160 closedir (INDIR);
161 }
162
163 if ((defined $ENV{'GSDLEXTS'}) && ($collection eq "")) {
164 my @extensions = split(/:/,$ENV{'GSDLEXTS'});
165 foreach my $e (@extensions) {
166 my $ext_prefix = &util::filename_cat($ENV{'GSDLHOME'},"ext",$e);
167 my $ext_classify_dir = &util::filename_cat($ext_prefix, "perllib", "classify");
168
169 if (opendir (INDIR, $ext_classify_dir)) {
170 my @ext_classifier_list = grep (/\.pm$/, readdir (INDIR));
171 closedir (INDIR);
172
173 push(@classifier_list,@ext_classifier_list);
174 }
175
176 }
177 }
178
179 print STDERR "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
180 print STDERR "<ClassifyList length=\"" . scalar(@classifier_list) . "\">\n";
181 foreach my $classifier (@classifier_list) {
182 $classifier =~ s/\.pm$//;
183 my $classifierobj = &classify::load_classifier_for_info ($classifier);
184 if ($describeall) {
185 $classifierobj->print_xml_usage(0);
186 }
187 else {
188 $classifierobj->print_xml_usage(0, 1);
189 }
190 }
191 print STDERR "</ClassifyList>\n";
192 }
193 else {
194 &print_single_classifier($classifier, $xml, 1);
195 }
196}
197
198
199sub print_single_classifier {
200 my ($classifier, $xml, $header) = @_;
201 my $classobj = &classify::load_classifier_for_info ($classifier);
202 if ($xml) {
203 $classobj->print_xml_usage($header);
204 }
205 else {
206 &gsprintf(STDERR, "\n{classinfo.passing_options}\n\n");
207 &gsprintf(STDERR, "{classinfo.option_types}:\n\n");
208 &gsprintf(STDERR, "{classinfo.specific_options}\n\n");
209 &gsprintf(STDERR, "{classinfo.general_options}\n\n");
210 &gsprintf(STDERR, "$classifier {classinfo.info}:\n\n");
211
212 $classobj->print_txt_usage();
213 }
214
215}
216
217
218&main ();
Note: See TracBrowser for help on using the repository browser.