source: gs3-extensions/pharos-imageis/trunk/perllib/plugins/PharosImageIndexer.pm@ 21601

Last change on this file since 21601 was 21601, checked in by davidb, 14 years ago

section level indexing support

File size: 5.0 KB
Line 
1###########################################################################
2#
3# PharosImageIndexer - helper plugin that does image conversion using ImageMagick
4#
5# A component of the Greenstone digital library software
6# from the New Zealand Digital Library Project at the
7# University of Waikato, New Zealand.
8#
9# Copyright (C) 2008 New Zealand Digital Library Project
10#
11# This program is free software; you can redistribute it and/or modify
12# it under the terms of the GNU General Public License as published by
13# the Free Software Foundation; either version 2 of the License, or
14# (at your option) any later version.
15#
16# This program is distributed in the hope that it will be useful,
17# but WITHOUT ANY WARRANTY; without even the implied warranty of
18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19# GNU General Public License for more details.
20#
21# You should have received a copy of the GNU General Public License
22# along with this program; if not, write to the Free Software
23# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24#
25###########################################################################
26package PharosImageIndexer;
27
28use PrintInfo;
29
30
31use strict;
32no strict 'refs'; # allow filehandles to be variables and viceversa
33
34use gsprintf 'gsprintf';
35
36BEGIN {
37 @PharosImageIndexer::ISA = ('PrintInfo');
38}
39
40my $arguments = [
41 ];
42
43my $options = { 'name' => "PharosImageIndexer",
44 'desc' => "{PharosImageIndexer.desc}",
45 'abstract' => "yes",
46 'inherits' => "yes",
47 'args' => $arguments };
48
49sub new {
50 my ($class) = shift (@_);
51 my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
52 push(@$pluginlist, $class);
53
54 push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
55 push(@{$hashArgOptLists->{"OptList"}},$options);
56
57 my $self = new PrintInfo($pluginlist, $inputargs, $hashArgOptLists, 1);
58
59
60 return bless $self, $class;
61
62}
63
64# needs to be called after BasePlugin init, so that outhandle is set up.
65sub init {
66 my $self = shift(@_);
67
68 # Check that Pharos is installed and available on the path
69 my $pharos_available = 1;
70 my $result = `pharos-imageis-identify.pl 2>&1`;
71 my $return_value = $?;
72 if ( ($ENV{'GSDLOS'} eq "windows" && $return_value == 256) || $return_value == -1) { # Linux and Windows return different values for "program not found"
73 $pharos_available = 0;
74 }
75
76 $self->{'pharos_available'} = $pharos_available;
77
78 if ($self->{'pharos_available'} == 0) {
79 my $outhandle = $self->{'outhandle'};
80 &gsprintf($outhandle, "PharosImageIndexer: Pharos not installed\n");
81 }
82
83}
84
85sub begin {
86
87}
88
89sub remove_one {
90 my $self = shift (@_);
91
92 my ($file, $oids, $archivedir) = @_;
93 print STDERR "in pharos remove_one, $file, $oids\n";
94
95 if (!$self->{'pharos_available'}) {
96 print STDERR "pharos not available, can't remove\n";
97 return;
98 }
99
100 my $doc_id = @$oids[0]; # do we need to do all the ids??
101 return unless defined $doc_id;
102 my $collection = &util::get_current_collection_name();
103 my $cmd = "perl -S pharos-imageis-delete.pl $collection $doc_id.jpg 2>&1";
104 print STDERR "Running command $cmd\n";
105 my $result = `$cmd`;
106 my $return_value = $?;
107 my $outhandle = $self->{'outhandle'};
108 if ($return_value != 0) {
109 print $outhandle "Pharos Indexing failed to delete $doc_id from database for collection $collection\n";
110 }
111 print $outhandle "$result\n";
112
113 }
114sub remove_all {
115 my $self = shift (@_);
116 my ($pluginfo, $base_dir, $processor, $maxdocs) = @_;
117
118 if (!$self->{'pharos_available'}) {
119 print STDERR "pharos not available, not doing a remove_all\n";
120 return;
121 }
122 # need to delete everything from the derby database.
123 my $collection = &util::get_current_collection_name();
124 my $cmd = "perl -S pharos-imageis-delete.pl $collection '*.jpg' 2>&1";
125 print STDERR "Running command $cmd\n";
126 my $result = `$cmd`;
127 my $return_value = $?;
128 my $outhandle = $self->{'outhandle'};
129 if ($return_value != 0) {
130 print $outhandle "Pharos Indexing failed to clear database for collection $collection\n";
131 }
132 print $outhandle "$result\n";
133
134}
135
136sub pharos_index_image {
137 my $self = shift(@_);
138
139 if ( !$self->{'pharos_available'}) {
140 print STDERR "pharos not available, can't index the image\n";
141 return;
142 }
143 # pass in the jpg thumbnail, and the doc obj
144 my ($filename_full_path, $doc_obj, $docid) = @_;
145 print STDERR "pharos indexing $filename_full_path\n";
146
147 my $collection = &util::get_current_collection_name();
148
149 if (!defined $docid) {
150 $docid = $doc_obj->get_OID();
151 }
152
153 my $cmd = "perl -S pharos-imageis-add.pl $collection $filename_full_path $docid 2>&1";
154 print STDERR "Running command $cmd\n";
155 my $result = `$cmd`;
156
157 my $return_value = $?;
158 my $outhandle = $self->{'outhandle'};
159 if ($return_value != 0) {
160 print $outhandle "Pharos Indexing failed for $filename_full_path, $docid\n";
161 }
162 print $outhandle "$result\n";
163
164}
165
166
1671;
Note: See TracBrowser for help on using the repository browser.