root/gsdl/trunk/perllib/baseconvert.pm @ 16841

Revision 16841, 3.3 KB (checked in by davidb, 12 years ago)

Supporting classes for conversion

Line 
1###########################################################################
2#
3# baseconvert.pm -- provides some fundamental methods for converting files
4#                    using external programming
5#
6# Copyright (C) 1999 DigiLib Systems Limited, NZ
7#
8# This program is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation; either version 2 of the License, or
11# (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with this program; if not, write to the Free Software
20# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21#
22###########################################################################
23
24
25package baseconvert;
26
27use strict;
28no strict 'refs'; # allow filehandles to be variables and viceversa
29
30
31use convertutil;
32
33sub new {
34    my ($class) = shift @_;
35
36    my ($base_dir,$filename,$verbosity,$outhandle) = @_;
37
38    my $self = {};
39
40    $self->{'verbosity'}    = $verbosity;
41    $self->{'outhandle'}    = $outhandle;
42
43    # Work out relative filename within 'base_dir'
44    my ($file) = ($filename =~ m/^$base_dir(.*?)$/);
45   
46    $file =~ s/^\/|\\//; # get rid of leading slash from relative filename
47
48    # Setup cached_dir and file_root
49
50    my ($file_root, $dirname, $suffix)
51    = &File::Basename::fileparse($file, "\\.[^\\.]+\$");
52
53    my $collect_dir = $ENV{'GSDLCOLLECTDIR'};
54    my $base_output_dir = &util::filename_cat($collect_dir,"cached",$dirname);
55
56    if (!-e $base_output_dir ) {
57    print $outhandle "Creating directory $base_output_dir\n"
58        if ($verbosity>2);
59
60    &util::mk_all_dir($base_output_dir);
61    }
62
63    my $output_dir = &util::filename_cat($base_output_dir,$file_root);
64
65    if (!-e $output_dir) {
66    print $outhandle "Creating directory $output_dir\n"
67        if ($verbosity>2);
68
69    &util::mk_dir($output_dir);
70    }
71
72    $self->{'cached_dir'} = $output_dir;
73    $self->{'file_root'} = $file_root;
74   
75    return bless $self, $class;
76}
77
78
79
80sub run_general_cmd
81{
82    my $self = shift @_;
83    my ($command,$options) = @_;
84
85    if (!defined $options->{'verbosity'}) {
86    $options->{'verbosity'} = $self->{'verbosity'};
87    }
88
89    if (!defined $options->{'outhandle'}) {
90    $options->{'outhandle'} = $self->{'outhandle'};
91    }
92
93   
94    return &convertutil::run_general_cmd(@_);
95}
96
97
98sub regenerate_general_cmd
99{
100    my $self = shift @_;
101    my ($command,$ofilename,$options) = @_;
102
103    if (!defined $options->{'verbosity'}) {
104    $options->{'verbosity'} = $self->{'verbosity'};
105    }
106
107    if (!defined $options->{'outhandle'}) {
108    $options->{'outhandle'} = $self->{'outhandle'};
109    }
110
111    return &convertutil::regenerate_general_cmd(@_);
112}
113
114
115
116sub run_cached_general_cmd
117{
118    my $self = shift @_;
119
120    my ($command,$ofilename,$options) = @_;
121
122    if (!defined $options->{'verbosity'}) {
123    $options->{'verbosity'} = $self->{'verbosity'};
124    }
125
126    if (!defined $options->{'outhandle'}) {
127    $options->{'outhandle'} = $self->{'outhandle'};
128    }
129
130    return &convertutil::run_cached_general_cmd(@_);
131}
132
133
134
135
136
1371;
Note: See TracBrowser for help on using the browser.