[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 | { 'name' => "disable_pharos_imageis",
|
---|
| 42 | 'desc' => "{PharosImageIndexer.disable_pharos_imageis}",
|
---|
| 43 | 'type' => "flag",
|
---|
| 44 | 'reqd' => "no" },
|
---|
| 45 | ];
|
---|
| 46 |
|
---|
| 47 | my $options = { 'name' => "PharosImageIndexer",
|
---|
| 48 | 'desc' => "{PharosImageIndexer.desc}",
|
---|
| 49 | 'abstract' => "yes",
|
---|
| 50 | 'inherits' => "yes",
|
---|
| 51 | 'args' => $arguments };
|
---|
| 52 |
|
---|
| 53 | sub new {
|
---|
| 54 | my ($class) = shift (@_);
|
---|
| 55 | my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
|
---|
| 56 | push(@$pluginlist, $class);
|
---|
| 57 |
|
---|
| 58 | push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
|
---|
| 59 | push(@{$hashArgOptLists->{"OptList"}},$options);
|
---|
| 60 |
|
---|
| 61 | my $self = new PrintInfo($pluginlist, $inputargs, $hashArgOptLists, 1);
|
---|
| 62 |
|
---|
| 63 |
|
---|
| 64 | return bless $self, $class;
|
---|
| 65 |
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | # needs to be called after BasePlugin init, so that outhandle is set up.
|
---|
| 69 | sub init {
|
---|
| 70 | my $self = shift(@_);
|
---|
| 71 |
|
---|
| 72 | return if ($self->{'disable_pharos_imageis'});
|
---|
| 73 |
|
---|
| 74 | # Check that Pharos is installed and available on the path
|
---|
| 75 | my $pharos_available = 1;
|
---|
[21305] | 76 | my $result = `pharos-imageis-identify.pl 2>&1`;
|
---|
| 77 | my $return_value = $?;
|
---|
| 78 | if ( ($ENV{'GSDLOS'} eq "windows" && $return_value == 256) || $return_value == -1) { # Linux and Windows return different values for "program not found"
|
---|
| 79 | $pharos_available = 0;
|
---|
| 80 | }
|
---|
[21294] | 81 |
|
---|
[21305] | 82 | $self->{'pharos_available'} = $pharos_available;
|
---|
[21294] | 83 |
|
---|
| 84 | if ($self->{'pharos_available'} == 0) {
|
---|
| 85 | my $outhandle = $self->{'outhandle'};
|
---|
| 86 | &gsprintf($outhandle, "PharosImageIndexer: Pharos not installed\n");
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | sub begin {
|
---|
| 92 |
|
---|
| 93 | }
|
---|
| 94 |
|
---|
[21305] | 95 | sub remove_one {
|
---|
[21294] | 96 | my $self = shift (@_);
|
---|
[21305] | 97 |
|
---|
| 98 | my ($file, $oids) = @_;
|
---|
| 99 | print STDERR "in pharos remove_one, $file, $oids\n";
|
---|
| 100 | return if ($self->{'disable_pharos_imageis'});
|
---|
| 101 |
|
---|
| 102 | if (!$self->{'pharos_available'}) {
|
---|
| 103 | print STDERR "pharos not available, can't remove\n";
|
---|
| 104 | return;
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | my $doc_id = @$oids[0];
|
---|
| 108 | return unless defined $doc_id;
|
---|
| 109 | my $collection = &util::get_current_collection_name();
|
---|
| 110 | my $cmd = "perl -S pharos-imageis-delete.pl $collection $doc_id.jpg 2>&1";
|
---|
| 111 | print STDERR "Running command $cmd\n";
|
---|
| 112 | my $result = `$cmd`;
|
---|
| 113 | my $return_value = $?;
|
---|
| 114 | my $outhandle = $self->{'outhandle'};
|
---|
| 115 | if ($return_value != 0) {
|
---|
| 116 | print $outhandle "Pharos Indexing failed to delete $doc_id from database for collection $collection\n";
|
---|
| 117 | }
|
---|
| 118 | print $outhandle "$result\n";
|
---|
| 119 |
|
---|
| 120 | }
|
---|
| 121 | sub remove_all {
|
---|
| 122 | my $self = shift (@_);
|
---|
[21294] | 123 | my ($pluginfo, $base_dir, $processor, $maxdocs) = @_;
|
---|
| 124 |
|
---|
| 125 | return if ($self->{'disable_pharos_imageis'});
|
---|
| 126 |
|
---|
| 127 | if (!$self->{'pharos_available'}) {
|
---|
[21305] | 128 | print STDERR "pharos not available, not doing a remove_all\n";
|
---|
[21294] | 129 | return;
|
---|
| 130 | }
|
---|
| 131 | # need to delete everything from the derby database.
|
---|
| 132 | my $collection = &util::get_current_collection_name();
|
---|
[21305] | 133 | my $cmd = "perl -S pharos-imageis-delete.pl $collection '*.jpg' 2>&1";
|
---|
[21294] | 134 | print STDERR "Running command $cmd\n";
|
---|
| 135 | my $result = `$cmd`;
|
---|
| 136 | my $return_value = $?;
|
---|
| 137 | my $outhandle = $self->{'outhandle'};
|
---|
| 138 | if ($return_value != 0) {
|
---|
| 139 | print $outhandle "Pharos Indexing failed to clear database for collection $collection\n";
|
---|
| 140 | }
|
---|
| 141 | print $outhandle "$result\n";
|
---|
| 142 |
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 | sub pharos_index_image {
|
---|
| 146 | my $self = shift(@_);
|
---|
| 147 |
|
---|
| 148 | return if ($self->{'disable_pharos_imageis'} || !$self->{'pharos_available'});
|
---|
| 149 | # pass in the jpg thumbnail, and the doc obj
|
---|
| 150 | my ($filename_full_path, $doc_obj) = @_;
|
---|
| 151 | print STDERR "pharos indexing $filename_full_path\n";
|
---|
| 152 |
|
---|
| 153 | my $collection = &util::get_current_collection_name();
|
---|
| 154 | my $id = $doc_obj->get_OID();
|
---|
| 155 |
|
---|
| 156 | my $cmd = "perl -S pharos-imageis-add.pl $collection $filename_full_path $id 2>&1";
|
---|
| 157 | print STDERR "Running command $cmd\n";
|
---|
| 158 | my $result = `$cmd`;
|
---|
| 159 |
|
---|
| 160 | my $return_value = $?;
|
---|
| 161 | my $outhandle = $self->{'outhandle'};
|
---|
| 162 | if ($return_value != 0) {
|
---|
| 163 | print $outhandle "Pharos Indexing failed for $filename_full_path, $id\n";
|
---|
| 164 | }
|
---|
| 165 | print $outhandle "$result\n";
|
---|
| 166 |
|
---|
| 167 | }
|
---|
| 168 |
|
---|
| 169 |
|
---|
| 170 | 1;
|
---|