source: main/tags/2.60/gsdl/bin/script/classinfo.pl@ 25196

Last change on this file since 25196 was 7952, checked in by davidb, 20 years ago

Script extended to support '-listall' option which prints out all the
plugins/classifiers it knows about.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 5.7 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
29
30BEGIN {
31 die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
32 die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};
33 unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
34 unshift (@INC, "$ENV{'GSDLHOME'}/perllib/cpan");
35 unshift (@INC, "$ENV{'GSDLHOME'}/perllib/classify");
36}
37
38use classify;
39use util;
40use parsargv;
41use gsprintf;
42use printusage;
43
44
45my $arguments =
46 [ { 'name' => "collect",
47 'desc' => "{classinfo.collect}",
48 'type' => "string",
49 'reqd' => "no" },
50 { 'name' => "xml",
51 'desc' => "{scripts.xml}",
52 'type' => "flag",
53 'reqd' => "no" },
54 { 'name' => "listall",
55 'desc' => "{scripts.listall}",
56 'type' => "flag",
57 'reqd' => "no" },
58 { 'name' => "language",
59 'desc' => "{scripts.language}",
60 'type' => "string",
61 'reqd' => "no" } ];
62
63my $options = { 'name' => "classinfo.pl",
64 'desc' => "{classinfo.desc}",
65 'args' => $arguments };
66
67sub gsprintf
68{
69 return &gsprintf::gsprintf(@_);
70}
71
72
73# sub print_usage {
74# print STDERR "\n";
75# print STDERR "classinfo.pl: Prints information about a classifier.\n\n";
76# print STDERR " usage: $0 [options] classifier\n\n";
77# print STDERR " options:\n";
78# print STDERR " -collect collection-name Giving a collection name will make classinfo.pl\n";
79# print STDERR " look in collect/collection-name/perllib/classify\n";
80# print STDERR " first. If the classifier is not found there it will\n";
81# print STDERR " look in the general perllib/classify directory.\n\n";
82# print STDERR " -xml Produces the information in an xml form, without\n";
83# print STDERR " 'pretty' comments but with much more detail.\n\n";
84# print STDERR " -language language-code Language to display classifer options in (eg. 'en_US'\n";
85# print STDERR " specifies American English). Requires translations\n";
86# print STDERR " of the option descriptions to exist in the\n";
87# print STDERR " perllib/strings_language-code.rb file.\n";
88# }
89
90
91sub main {
92 my $collect = "";
93 my $xml = 0;
94 my $listall = 0;
95
96 # Parse command line
97 if (!parsargv::parse(\@ARGV,
98 q^collect/.*/^, \$collect,
99 q^xml^, \$xml,
100 q^listall^, \$listall,
101 q^language/.*/^, \$language))
102 {
103 &PrintUsage::print_txt_usage($options, "{classinfo.params}", 1);
104 die "\n";
105 }
106
107 # If $language has been specified, load the appropriate resource bundle
108 # (Otherwise, the default resource bundle will be loaded automatically)
109 if ($language) {
110 &gsprintf::load_language_specific_resource_bundle($language);
111 }
112
113 # Get classifier
114 my $classifier = shift (@ARGV);
115 if (($listall == 0) && (!defined $classifier || $classifier eq "")) {
116 &gsprintf(STDERR, "{classinfo.no_classifier_name}\n\n");
117 &PrintUsage::print_txt_usage($options, "{classinfo.params}", 1);
118 die "\n";
119 }
120
121 # make sure the classifier is loaded from the correct location - a hack.
122 if ($collect ne "") {
123 $ENV{'GSDLCOLLECTDIR'} = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $collect);
124 } else {
125 $ENV{'GSDLCOLLECTDIR'} = $ENV{'GSDLHOME'};
126 }
127
128 if ($listall) {
129 my $class_dir = &util::filename_cat($ENV{'GSDLCOLLECTDIR'},"perllib","classify");
130
131 if (!opendir (INDIR, $class_dir)) {
132 print STDERR "classinfo.pl: could not open directory $class_dir\n";
133 } else {
134 my @class_list = grep (/\.pm$/, readdir (INDIR));
135 closedir (INDIR);
136
137 if ($xml) {
138 my $num_class = scalar(@class_list);
139
140 print STDERR "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
141 print STDERR "<!DOCTYPE ClassifyList [\n";
142 print STDERR " <!ELEMENT ClassifyList (ClassifyName*)>\n";
143 print STDERR " <!ELEMENT ClassifyName (#PCDATA)>\n";
144 print STDERR " <!ATTLIST ClassifyList\n";
145 print STDERR " length CDATA #REQUIRED>\n";
146 print STDERR "]>\n";
147
148 print STDERR "<ClassifyList length=\"$num_class\">\n";
149 map { print STDERR " <ClassifyName>$_</ClassifyName>\n"; } @class_list;
150 print STDERR "</ClassifyList>\n";
151
152 }
153 else {
154 print STDERR join(" ",@class_list), "\n";
155 }
156 }
157
158 }
159 else {
160 my $classobj = &classify::load_classifier_for_info ($classifier);
161 if ($xml) {
162 $classobj->print_xml_usage();
163 }
164 else {
165 &gsprintf(STDERR, "\n{classinfo.passing_options}\n\n");
166 &gsprintf(STDERR, "{classinfo.option_types}:\n\n");
167 &gsprintf(STDERR, "{classinfo.specific_options}\n\n");
168 &gsprintf(STDERR, "{classinfo.general_options}\n\n");
169 &gsprintf(STDERR, "$classifier {classinfo.info}:\n\n");
170
171 $classobj->print_txt_usage();
172 }
173 }
174}
175
176
177&main ();
Note: See TracBrowser for help on using the repository browser.