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

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

Functionality added so -listall option looks in Greenstone extension folders as well for plugins/classifiers.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 6.5 KB
RevLine 
[1885]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
[10230]29use strict;
30no strict 'subs'; # allow barewords (eg STDERR) as function arguments
[1885]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");
[5882]36 unshift (@INC, "$ENV{'GSDLHOME'}/perllib/cpan");
[1885]37 unshift (@INC, "$ENV{'GSDLHOME'}/perllib/classify");
[14942]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 }
47 }
[1885]48}
49
50use classify;
51use util;
[5606]52use gsprintf;
53use printusage;
[1885]54
[10230]55use parse2;
[5606]56
57my $arguments =
[12639]58 [ { 'name' => "collection",
59 'desc' => "{classinfo.collection}",
[5606]60 'type' => "string",
[10230]61 'deft' => "",
[5606]62 'reqd' => "no" },
63 { 'name' => "xml",
64 'desc' => "{scripts.xml}",
65 'type' => "flag",
66 'reqd' => "no" },
[7952]67 { 'name' => "listall",
68 'desc' => "{scripts.listall}",
69 'type' => "flag",
70 'reqd' => "no" },
[11683]71 { 'name' => "describeall",
72 'desc' => "{scripts.describeall}",
73 'type' => "flag",
74 'reqd' => "no" },
[5606]75 { 'name' => "language",
76 'desc' => "{scripts.language}",
77 'type' => "string",
78 'reqd' => "no" } ];
79
80my $options = { 'name' => "classinfo.pl",
81 'desc' => "{classinfo.desc}",
82 'args' => $arguments };
83
[6921]84sub gsprintf
[5606]85{
[6921]86 return &gsprintf::gsprintf(@_);
[1885]87}
88
89sub main {
[12639]90 my $collection = "";
[4762]91 my $xml = 0;
[7952]92 my $listall = 0;
[11683]93 my $describeall = 0;
[10230]94 my $language;
[1885]95
[10230]96 my $hashParsingResult = {};
[12545]97 # general options available to all classifiers
[10230]98 my $intArgLeftinAfterParsing = parse2::parse(\@ARGV,$arguments,$hashParsingResult,"allow_extra_options");
[12545]99 # parse returns -1 if an error occurred
100 if($intArgLeftinAfterParsing == -1)
[4762]101 {
[10230]102 &PrintUsage::print_txt_usage($options, "{classinfo.params}");
[4762]103 die "\n";
[1885]104 }
105
[10230]106 foreach my $strVariable (keys %$hashParsingResult)
107 {
108 eval "\$$strVariable = \$hashParsingResult->{\"\$strVariable\"}";
109 }
[6945]110 # If $language has been specified, load the appropriate resource bundle
111 # (Otherwise, the default resource bundle will be loaded automatically)
112 if ($language) {
113 &gsprintf::load_language_specific_resource_bundle($language);
114 }
[12545]115
116 # If there is not exactly 1 argument left (classifier name), then the arguments were wrong
[12613]117 # If the user specified -h, then we output the usage also
118 if((@ARGV && $ARGV[0] =~ /^\-+h/) )
[12545]119 {
120 PrintUsage::print_txt_usage($options, "{classinfo.params}");
121 die "\n";
122 }
[6926]123
[12614]124 # If there is not exactly 1 argument left (classifier name), then the arguments were wrong (apart from if we had listall or describeall set)
[12613]125 if ($listall == 0 && $describeall ==0 && $intArgLeftinAfterParsing == 0) {
[12614]126 gsprintf(STDERR, "{classinfo.no_classifier_name}\n\n");
127 PrintUsage::print_txt_usage($options, "{classinfo.params}", 1);
[12613]128 die "\n";
129 }
130
131 # we had some arguments that we weren't expecting
132 if ($intArgLeftinAfterParsing > 1) {
[12614]133 pop(@ARGV); # assume that the last arg is the classifier name
[12613]134 gsprintf(STDERR, "{common.invalid_options}\n\n", join (',', @ARGV));
[12614]135 PrintUsage::print_txt_usage($options, "{classinfo.params}", 1);
[12613]136 die "\n";
137 }
138
[1885]139 # Get classifier
140 my $classifier = shift (@ARGV);
[10350]141 if (defined $classifier) {
142 $classifier =~ s/\.pm$//; # allow xxx.pm as the argument
143 }
[1885]144
145 # make sure the classifier is loaded from the correct location - a hack.
[12639]146 if ($collection ne "") {
147 $ENV{'GSDLCOLLECTDIR'} = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $collection);
[1885]148 } else {
[4762]149 $ENV{'GSDLCOLLECTDIR'} = $ENV{'GSDLHOME'};
[1885]150 }
[4762]151
[12629]152 if ($listall || $describeall) {
[12640]153 my $classify_dir = &util::filename_cat($ENV{'GSDLCOLLECTDIR'}, "perllib", "classify");
154 my @classifier_list = ();
155 if (opendir (INDIR, $classify_dir)) {
156 @classifier_list = grep (/\.pm$/, readdir (INDIR));
157 closedir (INDIR);
[12625]158 }
[7952]159
[14958]160 if ((defined $ENV{'GSDLEXTS'}) && ($collection eq "")) {
161 my @extensions = split(/:/,$ENV{'GSDLEXTS'});
162 foreach my $e (@extensions) {
163 my $ext_prefix = &util::filename_cat($ENV{'GSDLHOME'},"ext",$e);
164 my $ext_classify_dir = &util::filename_cat($ext_prefix, "perllib", "classify");
165
166 if (opendir (INDIR, $ext_classify_dir)) {
167 my @ext_classifier_list = grep (/\.pm$/, readdir (INDIR));
168 closedir (INDIR);
169
170 push(@classifier_list,@ext_classifier_list);
171 }
172
173 }
174 }
175
[12640]176 print STDERR "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
177 print STDERR "<ClassifyList length=\"" . scalar(@classifier_list) . "\">\n";
178 foreach my $classifier (@classifier_list) {
179 $classifier =~ s/\.pm$//;
180 my $classifierobj = &classify::load_classifier_for_info ($classifier);
181 if ($describeall) {
182 $classifierobj->print_xml_usage(0);
[7952]183 }
[12640]184 else {
185 $classifierobj->print_xml_usage(0, 1);
186 }
[7952]187 }
[12640]188 print STDERR "</ClassifyList>\n";
[4762]189 }
[11683]190 else {
191 &print_single_classifier($classifier, $xml, 1);
192 }
[1885]193}
194
[12629]195
[11683]196sub print_single_classifier {
197 my ($classifier, $xml, $header) = @_;
198 my $classobj = &classify::load_classifier_for_info ($classifier);
199 if ($xml) {
200 $classobj->print_xml_usage($header);
201 }
202 else {
203 &gsprintf(STDERR, "\n{classinfo.passing_options}\n\n");
204 &gsprintf(STDERR, "{classinfo.option_types}:\n\n");
205 &gsprintf(STDERR, "{classinfo.specific_options}\n\n");
206 &gsprintf(STDERR, "{classinfo.general_options}\n\n");
207 &gsprintf(STDERR, "$classifier {classinfo.info}:\n\n");
208
209 $classobj->print_txt_usage();
210 }
211
212}
[1885]213
[11683]214
[5606]215&main ();
Note: See TracBrowser for help on using the repository browser.