source: trunk/gsdl/perllib/plugin.pm@ 3177

Last change on this file since 3177 was 2797, checked in by sjboddie, 23 years ago

* empty log message *

  • Property svn:keywords set to Author Date Id Revision
File size: 5.0 KB
RevLine 
[537]1###########################################################################
2#
3# plugin.pm -- functions to handle using plugins
4# A component of the Greenstone digital library software
5# from the New Zealand Digital Library Project at the
6# University of Waikato, New Zealand.
7#
8# Copyright (C) 1999 New Zealand Digital Library Project
9#
10# This program is free software; you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation; either version 2 of the License, or
13# (at your option) any later version.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with this program; if not, write to the Free Software
22# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23#
24###########################################################################
[4]25
26package plugin;
27
[134]28require util;
[4]29
[2785]30my $stats = {'num_processed' => 0,
31 'num_blocked' => 0,
32 'num_not_processed' => 0,
33 'num_archives' => 0
34 };
35
[4]36sub load_plugins {
[1431]37 my ($plugin_list) = shift @_;
[2785]38 ($verbosity, $outhandle, $failhandle) = @_; # globals
[4]39 my @plugin_objects = ();
40
[1243]41 $verbosity = 2 unless defined $verbosity;
[1431]42 $outhandle = STDERR unless defined $outhandle;
[2785]43 $failhandle = STDERR unless defined $failhandle;
[1243]44
[809]45 foreach $pluginoptions (@$plugin_list) {
46 my $pluginname = shift @$pluginoptions;
47 next unless defined $pluginname;
48
[4]49 # find the plugin
[134]50 my $colplugname = &util::filename_cat($ENV{'GSDLCOLLECTDIR'},"perllib/plugins",
[809]51 "${pluginname}.pm");
[134]52 my $mainplugname = &util::filename_cat($ENV{'GSDLHOME'},"perllib/plugins",
[809]53 "${pluginname}.pm");
[134]54 if (-e $colplugname) { require $colplugname; }
55 elsif (-e $mainplugname) { require $mainplugname; }
[809]56 else { die "ERROR - couldn't find plugin \"$pluginname\"\n"; }
[4]57
58 # create a plugin object
59 my ($plugobj);
[809]60 map { $_ = "\"$_\""; } @$pluginoptions;
61 my $options = join (",", @$pluginoptions);
[1244]62 $options =~ s/\$/\\\$/g;
[809]63 eval ("\$plugobj = new \$pluginname($options)");
[4]64 die "$@" if $@;
[809]65
[1243]66 # initialize plugin
[2785]67 $plugobj->init($verbosity, $outhandle, $failhandle);
[1243]68
[4]69 # add this object to the list
70 push (@plugin_objects, $plugobj);
71 }
72
73 return \@plugin_objects;
74}
75
[835]76
77sub begin {
78 my ($pluginfo, $base_dir, $processor, $maxdocs) = @_;
79
80 map { $_->begin($pluginfo, $base_dir, $processor, $maxdocs); } @$pluginfo;
81}
82
[4]83sub read {
[809]84 my ($pluginfo, $base_dir, $file, $metadata, $processor, $maxdocs, $aux) = @_;
[4]85
[809]86 $maxdocs = -1 unless defined $maxdocs && $maxdocs =~ /\d/;
[315]87 my $rv = 0;
88
[1454]89 # the .kill file is a handy (if not very elegant) way of aborting
90 # an import.pl or buildcol.pl process
91 if (-e &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, ".kill")) {
92 print $outhandle "Process killed by .kill file\n";
93 die "\n";
94 }
95
[4]96 # pass this file by each of the plugins in turn until one
97 # is found which will process it
98 foreach $plugobj (@$pluginfo) {
[315]99 $rv = $plugobj->read($pluginfo, $base_dir, $file,
[809]100 $metadata, $processor, $maxdocs, $aux);
[315]101 return $rv if defined $rv;
[4]102 }
[2785]103
[1431]104 if ($verbosity >= 2) {
[2785]105 print $outhandle "WARNING - no plugin could process $file\n";
[170]106 }
[2785]107
[2793]108 $file =~ s/.*?([^\\\/]+)$/$1/;
[2785]109 print $failhandle "$file: no plugin could process this file\n";
110 $stats->{'num_not_processed'} ++;
111
[315]112 return 0;
[4]113}
114
[2785]115# write out some general stats that the plugins have compiled - note that
116# the buildcol.pl process doesn't currently call this process so the stats
117# are only output after import.pl -
118sub write_stats {
119 my ($pluginfo, $statshandle) = @_;
120
121 foreach $plugobj (@$pluginfo) {
122 $plugobj->compile_stats($stats);
123 }
124
125 my $total = $stats->{'num_processed'} + $stats->{'num_blocked'} +
126 $stats->{'num_not_processed'};
127
128 if ($total == 1) {
129 print $statshandle "* 1 document was considered for processing\n";
130 } else {
131 print $statshandle "* $total documents were considered for processing\n";
132 }
133 if ($stats->{'num_archives'}) {
134 print $statshandle " (including the contents of " . $stats->{'num_archives'} .
135 " ZIP/TAR archive";
136 if ($stats->{'num_archives'} == 1) {print $statshandle ")\n";}
137 else {print $statshandle "s)\n";}
138 }
139 if ($stats->{'num_processed'} == 1) {
140 print $statshandle "* 1 was processed and included in the collection\n";
141 } else {
142 print $statshandle "* " . $stats->{'num_processed'} . " were processed and included in the collection\n";
143 }
[2797]144 if ($stats->{'num_not_processed'}) {
145 if ($stats->{'num_not_processed'} == 1) {
146 print $statshandle "* 1 was rejected.";
147 } else {
148 print $statshandle "* " . $stats->{'num_not_processed'} . " were rejected.";
149 }
150 print $statshandle " See the fail log for a list of rejected documents\n";
151 }
[2785]152}
153
[835]154sub end {
[1587]155 my ($pluginfo, $processor) = @_;
156 map { $_->end($processor); } @$pluginfo;
[835]157}
[4]158
1591;
Note: See TracBrowser for help on using the repository browser.