source: gsdl/trunk/perllib/plugins/BaseMediaConverter.pm@ 18327

Last change on this file since 18327 was 18105, checked in by ak19, 15 years ago

Bugfix submitted by Vladimir Risojevic: backslash file separators on Windows cause a pattern-match to fail when ImagePlugin uses the cache_generated_images option

  • Property svn:executable set to *
File size: 4.9 KB
Line 
1###########################################################################
2#
3# BaseMediaConverter - helper plugin that provide base functionality for
4# image/video conversion using ImageMagick/ffmpeg
5#
6# A component of the Greenstone digital library software
7# from the New Zealand Digital Library Project at the
8# University of Waikato, New Zealand.
9#
10# Copyright (C) 2008 New Zealand Digital Library Project
11#
12# This program is free software; you can redistribute it and/or modify
13# it under the terms of the GNU General Public License as published by
14# the Free Software Foundation; either version 2 of the License, or
15# (at your option) any later version.
16#
17# This program is distributed in the hope that it will be useful,
18# but WITHOUT ANY WARRANTY; without even the implied warranty of
19# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20# GNU General Public License for more details.
21#
22# You should have received a copy of the GNU General Public License
23# along with this program; if not, write to the Free Software
24# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25#
26###########################################################################
27package BaseMediaConverter;
28
29use PrintInfo;
30
31use convertutil;
32
33use strict;
34use gsprintf 'gsprintf';
35
36BEGIN {
37 @BaseMediaConverter::ISA = ('PrintInfo');
38}
39
40my $arguments = [
41 ];
42
43my $options = { 'name' => "BaseMediaConverter",
44 'desc' => "{BaseMediaConverter.desc}",
45 'abstract' => "yes",
46 'inherits' => "yes",
47 'args' => $arguments };
48
49sub new {
50 my ($class) = shift (@_);
51 my ($pluginlist,$inputargs,$hashArgOptLists,$auxiliary) = @_;
52 push(@$pluginlist, $class);
53
54 push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
55 push(@{$hashArgOptLists->{"OptList"}},$options);
56
57 my $self = new PrintInfo($pluginlist, $inputargs, $hashArgOptLists, $auxiliary);
58
59 return bless $self, $class;
60}
61
62sub begin {
63 my $self = shift (@_);
64 my ($pluginfo, $base_dir, $processor, $maxdocs) = @_;
65
66 # Save base_dir for use in file cache
67 $self->{'base_dir'} = $base_dir;
68
69}
70
71
72sub init_cache_for_file
73{
74 my $self = shift @_;
75 my ($filename) = @_;
76
77 my $verbosity = $self->{'verbosity'};
78 my $outhandle = $self->{'outhandle'};
79 my $base_dir = $self->{'base_dir'};
80
81 # Work out relative filename within 'base_dir'
82 $filename =~ s/\\/\//g;
83 my ($file) = ($filename =~ m/^$base_dir(.*?)$/);
84
85 $file =~ s/^\/|\\//; # get rid of leading slash from relative filename
86
87 # Setup cached_dir and file_root
88
89 my ($file_root, $dirname, $suffix)
90 = &File::Basename::fileparse($file, "\\.[^\\.]+\$");
91
92 my $collect_dir = $ENV{'GSDLCOLLECTDIR'};
93 my $base_output_dir = &util::filename_cat($collect_dir,"cached",$dirname);
94
95 if (!-e $base_output_dir ) {
96 print $outhandle "Creating directory $base_output_dir\n"
97 if ($verbosity>2);
98
99 &util::mk_all_dir($base_output_dir);
100 }
101
102 my $output_dir = &util::filename_cat($base_output_dir,$file_root);
103
104 if (!-e $output_dir) {
105 print $outhandle "Creating directory $output_dir\n"
106 if ($verbosity>2);
107
108 &util::mk_dir($output_dir);
109 }
110
111 $self->{'cached_dir'} = $output_dir;
112 $self->{'cached_file_root'} = $file_root;
113
114}
115
116
117
118sub run_general_cmd
119{
120 my $self = shift @_;
121 my ($command,$print_info) = @_;
122
123
124 if (!defined $print_info->{'verbosity'}) {
125 $print_info->{'verbosity'} = $self->{'verbosity'};
126 }
127
128 if (!defined $print_info->{'outhandle'}) {
129 $print_info->{'outhandle'} = $self->{'outhandle'};
130 }
131
132
133 return &convertutil::run_general_cmd(@_);
134}
135
136
137sub regenerate_general_cmd
138{
139 my $self = shift @_;
140 my ($command,$ofilename,$print_info) = @_;
141
142 if (!defined $print_info->{'verbosity'}) {
143 $print_info->{'verbosity'} = $self->{'verbosity'};
144 }
145
146 if (!defined $print_info->{'outhandle'}) {
147 $print_info->{'outhandle'} = $self->{'outhandle'};
148 }
149
150 return &convertutil::regenerate_general_cmd(@_);
151}
152
153
154
155sub run_cached_general_cmd
156{
157 my $self = shift @_;
158
159 my ($command,$ofilename,$print_info) = @_;
160
161 if (!defined $print_info->{'verbosity'}) {
162 $print_info->{'verbosity'} = $self->{'verbosity'};
163 }
164
165 if (!defined $print_info->{'outhandle'}) {
166 $print_info->{'outhandle'} = $self->{'outhandle'};
167 }
168
169 return &convertutil::run_cached_general_cmd(@_);
170}
171
172
173
174sub autorun_general_cmd
175{
176 my $self = shift @_;
177
178 my ($command,$ofilename,$print_info) = @_;
179
180 my $result;
181 my $regenerated;
182 my $had_error;
183
184 if ($self->{'cache_generated_images'}) {
185 ($regenerated,$result,$had_error)
186 = $self->run_cached_general_cmd($command,$ofilename,$print_info);
187 }
188 else {
189 $regenerated = 1; # always true for a command that is always run
190 ($result,$had_error)
191 = $self->run_general_cmd($command,$print_info);
192 }
193
194 return ($regenerated,$result,$had_error);
195}
196
197
198#
1991;
Note: See TracBrowser for help on using the repository browser.