[21294] | 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 | ###########################################################################
|
---|
| 26 | package PharosImageIndexer;
|
---|
| 27 |
|
---|
| 28 | use PrintInfo;
|
---|
| 29 |
|
---|
| 30 |
|
---|
| 31 | use strict;
|
---|
| 32 | no strict 'refs'; # allow filehandles to be variables and viceversa
|
---|
| 33 |
|
---|
| 34 | use gsprintf 'gsprintf';
|
---|
| 35 |
|
---|
| 36 | BEGIN {
|
---|
| 37 | @PharosImageIndexer::ISA = ('PrintInfo');
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | my $arguments = [
|
---|
| 41 | ];
|
---|
| 42 |
|
---|
| 43 | my $options = { 'name' => "PharosImageIndexer",
|
---|
| 44 | 'desc' => "{PharosImageIndexer.desc}",
|
---|
| 45 | 'abstract' => "yes",
|
---|
| 46 | 'inherits' => "yes",
|
---|
| 47 | 'args' => $arguments };
|
---|
| 48 |
|
---|
| 49 | sub 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.
|
---|
| 65 | sub init {
|
---|
| 66 | my $self = shift(@_);
|
---|
| 67 |
|
---|
| 68 | # Check that Pharos is installed and available on the path
|
---|
| 69 | my $pharos_available = 1;
|
---|
[21305] | 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 | }
|
---|
[21294] | 75 |
|
---|
[21305] | 76 | $self->{'pharos_available'} = $pharos_available;
|
---|
[21294] | 77 |
|
---|
| 78 | if ($self->{'pharos_available'} == 0) {
|
---|
| 79 | my $outhandle = $self->{'outhandle'};
|
---|
| 80 | &gsprintf($outhandle, "PharosImageIndexer: Pharos not installed\n");
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | sub begin {
|
---|
| 86 |
|
---|
| 87 | }
|
---|
| 88 |
|
---|
[21305] | 89 | sub remove_one {
|
---|
[21294] | 90 | my $self = shift (@_);
|
---|
[21305] | 91 |
|
---|
[21316] | 92 | my ($file, $oids, $archivedir) = @_;
|
---|
[21305] | 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 |
|
---|
[21316] | 100 | my $doc_id = @$oids[0]; # do we need to do all the ids??
|
---|
[21305] | 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 | }
|
---|
| 114 | sub remove_all {
|
---|
| 115 | my $self = shift (@_);
|
---|
[21294] | 116 | my ($pluginfo, $base_dir, $processor, $maxdocs) = @_;
|
---|
| 117 |
|
---|
| 118 | if (!$self->{'pharos_available'}) {
|
---|
[21305] | 119 | print STDERR "pharos not available, not doing a remove_all\n";
|
---|
[21294] | 120 | return;
|
---|
| 121 | }
|
---|
| 122 | # need to delete everything from the derby database.
|
---|
| 123 | my $collection = &util::get_current_collection_name();
|
---|
[21305] | 124 | my $cmd = "perl -S pharos-imageis-delete.pl $collection '*.jpg' 2>&1";
|
---|
[21294] | 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 |
|
---|
| 136 | sub pharos_index_image {
|
---|
| 137 | my $self = shift(@_);
|
---|
| 138 |
|
---|
[21342] | 139 | if ( !$self->{'pharos_available'}) {
|
---|
| 140 | print STDERR "pharos not available, can't index the image\n";
|
---|
| 141 | return;
|
---|
| 142 | }
|
---|
[21294] | 143 | # pass in the jpg thumbnail, and the doc obj
|
---|
| 144 | my ($filename_full_path, $doc_obj) = @_;
|
---|
| 145 | print STDERR "pharos indexing $filename_full_path\n";
|
---|
| 146 |
|
---|
| 147 | my $collection = &util::get_current_collection_name();
|
---|
| 148 | my $id = $doc_obj->get_OID();
|
---|
| 149 |
|
---|
| 150 | my $cmd = "perl -S pharos-imageis-add.pl $collection $filename_full_path $id 2>&1";
|
---|
| 151 | print STDERR "Running command $cmd\n";
|
---|
| 152 | my $result = `$cmd`;
|
---|
| 153 |
|
---|
| 154 | my $return_value = $?;
|
---|
| 155 | my $outhandle = $self->{'outhandle'};
|
---|
| 156 | if ($return_value != 0) {
|
---|
| 157 | print $outhandle "Pharos Indexing failed for $filename_full_path, $id\n";
|
---|
| 158 | }
|
---|
| 159 | print $outhandle "$result\n";
|
---|
| 160 |
|
---|
| 161 | }
|
---|
| 162 |
|
---|
| 163 |
|
---|
| 164 | 1;
|
---|