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

Last change on this file since 12338 was 11683, checked in by kjdon, 18 years ago

added a -describeall option, so we can generate the descriptive output for all plugins/classifiers at once

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 6.0 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
40use classify;
41use util;
42use gsprintf;
43use printusage;
44
45use parse2;
46
47my $arguments =
48 [ { 'name' => "collect",
49 'desc' => "{classinfo.collect}",
50 'type' => "string",
51 'deft' => "",
52 'reqd' => "no" },
53 { 'name' => "xml",
54 'desc' => "{scripts.xml}",
55 'type' => "flag",
56 'reqd' => "no" },
57 { 'name' => "listall",
58 'desc' => "{scripts.listall}",
59 'type' => "flag",
60 'reqd' => "no" },
61 { 'name' => "describeall",
62 'desc' => "{scripts.describeall}",
63 'type' => "flag",
64 'reqd' => "no" },
65 { 'name' => "language",
66 'desc' => "{scripts.language}",
67 'type' => "string",
68 'reqd' => "no" } ];
69
70my $options = { 'name' => "classinfo.pl",
71 'desc' => "{classinfo.desc}",
72 'args' => $arguments };
73
74sub gsprintf
75{
76 return &gsprintf::gsprintf(@_);
77}
78
79sub main {
80 my $collect = "";
81 my $xml = 0;
82 my $listall = 0;
83 my $describeall = 0;
84 my $language;
85
86 my $hashParsingResult = {};
87 my $blnParseFailed = "false";
88 # general options available to all plugins
89 my $intArgLeftinAfterParsing = parse2::parse(\@ARGV,$arguments,$hashParsingResult,"allow_extra_options");
90 # If there are more than one argument left after parsing, it mean user input too many arguments.
91 # Error occoured will return 0
92 if($intArgLeftinAfterParsing > 1)
93 {
94 &PrintUsage::print_txt_usage($options, "{classinfo.params}");
95 die "\n";
96 }
97
98 foreach my $strVariable (keys %$hashParsingResult)
99 {
100 eval "\$$strVariable = \$hashParsingResult->{\"\$strVariable\"}";
101 }
102 # If $language has been specified, load the appropriate resource bundle
103 # (Otherwise, the default resource bundle will be loaded automatically)
104 if ($language) {
105 &gsprintf::load_language_specific_resource_bundle($language);
106 }
107
108 # Get classifier
109 my $classifier = shift (@ARGV);
110 if (defined $classifier) {
111 $classifier =~ s/\.pm$//; # allow xxx.pm as the argument
112 }
113 if (($listall == 0 && $describeall == 0) && (!defined $classifier || $classifier eq "")) {
114 &gsprintf(STDERR, "{classinfo.no_classifier_name}\n\n");
115 &PrintUsage::print_txt_usage($options, "{classinfo.params}", 1);
116 die "\n";
117 }
118
119 # make sure the classifier is loaded from the correct location - a hack.
120 if ($collect ne "") {
121 $ENV{'GSDLCOLLECTDIR'} = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $collect);
122 } else {
123 $ENV{'GSDLCOLLECTDIR'} = $ENV{'GSDLHOME'};
124 }
125
126 if ($listall) {
127 my $class_dir = &util::filename_cat($ENV{'GSDLCOLLECTDIR'},"perllib","classify");
128
129 if (!opendir (INDIR, $class_dir)) {
130 print STDERR "classinfo.pl: could not open directory $class_dir\n";
131 } else {
132 my @class_list = grep (/\.pm$/, readdir (INDIR));
133 closedir (INDIR);
134
135 if ($xml) {
136 my $num_class = scalar(@class_list);
137
138 print STDERR "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
139 print STDERR "<!DOCTYPE ClassifyList [\n";
140 print STDERR " <!ELEMENT ClassifyList (ClassifyName*)>\n";
141 print STDERR " <!ELEMENT ClassifyName (#PCDATA)>\n";
142 print STDERR " <!ATTLIST ClassifyList\n";
143 print STDERR " length CDATA #REQUIRED>\n";
144 print STDERR "]>\n";
145
146 print STDERR "<ClassifyList length=\"$num_class\">\n";
147 map { print STDERR " <ClassifyName>$_</ClassifyName>\n"; } @class_list;
148 print STDERR "</ClassifyList>\n";
149
150 }
151 else {
152 print STDERR join(" ",@class_list), "\n";
153 }
154 }
155
156 }
157 elsif ($describeall) {
158 my $class_dir = &util::filename_cat($ENV{'GSDLCOLLECTDIR'},"perllib","classify");
159 my @class_list;
160 if (!opendir (INDIR, $class_dir)) {
161 print STDERR "classinfo.pl: could not open directory $class_dir\n";
162 } else {
163 @class_list = grep (/\.pm$/, readdir (INDIR));
164 closedir (INDIR);
165 }
166 if ($xml) {
167 my $num_class = scalar(@class_list);
168 &PrintUsage::print_xml_header("classify", 1);
169 print STDERR "<ClassInfoList length=\"$num_class\">\n";
170 }
171 foreach my $cl (@class_list) {
172 $cl =~ s/\.pm$//;
173 &print_single_classifier($cl, $xml, 0);
174 }
175 if ($xml) {
176 print STDERR "</ClassInfoList>\n";
177 }
178 }
179 else {
180 &print_single_classifier($classifier, $xml, 1);
181 }
182}
183
184sub print_single_classifier {
185 my ($classifier, $xml, $header) = @_;
186 my $classobj = &classify::load_classifier_for_info ($classifier);
187 if ($xml) {
188 $classobj->print_xml_usage($header);
189 }
190 else {
191 &gsprintf(STDERR, "\n{classinfo.passing_options}\n\n");
192 &gsprintf(STDERR, "{classinfo.option_types}:\n\n");
193 &gsprintf(STDERR, "{classinfo.specific_options}\n\n");
194 &gsprintf(STDERR, "{classinfo.general_options}\n\n");
195 &gsprintf(STDERR, "$classifier {classinfo.info}:\n\n");
196
197 $classobj->print_txt_usage();
198 }
199
200}
201
202
203&main ();
Note: See TracBrowser for help on using the repository browser.