Changeset 61

Show
Ignore:
Timestamp:
27.11.2006 19:37:08 (2 years ago)
Author:
decoder
Message:

Created Logging.pm, all logging is now done with this module instead of Config.pm (this solves some dependency problems)
Fixed save_execute error returning of exec() call. Failing exec() call will return 1 now properly.
Added error handling code for force_output_in, and tmpdir is now prepended to this parameter.

Still missing: Correct error handling stuff when parsing fails...

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/devel/FuzzyOcr/Config.pm

    r60 r61  
    22package FuzzyOcr::Config; 
    33 
     4use FuzzyOcr::Logging qw(debuglog logfile); 
     5 
    46use FuzzyOcr::Scanset; 
    57use FuzzyOcr::Preprocessor; 
     8 
    69 
    710use base 'Exporter'; 
     
    2831    logfile); 
    2932 
    30 use Mail::SpamAssassin::Logger; 
    3133use Fcntl ':flock'; 
    3234use POSIX; 
     
    704706} 
    705707 
    706 sub logfile { 
    707     my $conf = get_config(); 
    708     my $logtext = $_[0]; 
    709     my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) = localtime(time); 
    710     my $time = sprintf( 
    711        "%4d-%02d-%02d %02d:%02d:%02d", 
    712         $year + 1900, 
    713         $mon + 1, $mday, $hour, $min, $sec 
    714     ); 
    715     $logtext =~ s/\n/\n                      /g; 
    716  
    717     unless ( open LOGFILE, ">>", $conf->{focr_logfile} ) { 
    718        warn "Can't open $conf->{focr_logfile} for writing, check permissions"; 
    719     } 
    720     flock( LOGFILE, LOCK_EX ); 
    721     seek( LOGFILE, 0, 2 ); 
    722     print LOGFILE "$time [$$] $logtext\n"; 
    723     flock( LOGFILE, LOCK_UN ); 
    724     close LOGFILE; 
    725 } 
    726  
    727 sub debuglog { 
    728     my $conf = get_config(); 
    729     my @lines = split('\n',$_[0]); 
    730     my $limit = defined $_[1] ? $_[1] : 1; 
    731     if ( $conf->{focr_verbose} > $limit ) { 
    732         logfile($_[0]) if defined $conf->{focr_logfile}; 
    733         if ($conf->{focr_log_stderr}) { 
    734             foreach (@lines) { info ("FuzzyOcr: $_"); } 
    735         } 
    736     } else { 
    737         foreach (@lines) { dbg  ("FuzzyOcr: $_"); } 
    738     } 
    739 } 
    740  
    741708sub parse_scansets { 
    742709    my ($file) = @_; 
  • trunk/devel/FuzzyOcr/Deanimate.pm

    r59 r61  
    66 
    77use lib "../"; 
    8 use FuzzyOcr::Config qw(get_config set_config get_tmpdir debuglog logfile); 
     8use FuzzyOcr::Config qw(get_config set_config get_tmpdir); 
    99use FuzzyOcr::Misc qw(save_execute); 
     10use FuzzyOcr::Logging qw(debuglog logfile); 
    1011 
    1112# Provide functions to deanimate gifs 
  • trunk/devel/FuzzyOcr/Hashing.pm

    r59 r61  
    88 
    99use lib "../"; 
    10 use FuzzyOcr::Config qw(get_thresholds get_config set_config get_tmpdir debuglog logfile); 
     10use FuzzyOcr::Config qw(get_thresholds get_config set_config get_tmpdir); 
    1111use FuzzyOcr::Misc qw(save_execute); 
     12use FuzzyOcr::Logging qw(debuglog logfile); 
    1213use Fcntl; 
    1314use Fcntl ':flock'; 
  • trunk/devel/FuzzyOcr/Misc.pm

    r60 r61  
    66 
    77use lib "../"; 
    8 use FuzzyOcr::Config qw(set_pid unset_pid get_timeout get_pms get_config set_config debuglog logfile); 
     8use FuzzyOcr::Config qw(set_pid unset_pid get_timeout get_pms get_config set_config); 
     9use FuzzyOcr::Logging qw(debuglog logfile); 
    910use Time::HiRes qw( time usleep ualarm gettimeofday tv_interval ); 
    1011 
     
    9293                return -1; 
    9394            } elsif (not $pid) { 
    94                 debuglog("Exec: $cmd $stdout $stderr",2); 
     95                debuglog("Exec: $cmd $stdout 2$stderr",2); 
    9596 
    9697                if (defined $stdin) { 
     
    103104                    open(STDERR, $stderr); 
    104105                } 
    105                 exec($cmd); 
    106                 exit($?); 
     106                unless(exec($cmd)) { 
     107                    exit(1); 
     108                } 
    107109            } else { 
    108110                set_pid($pid); 
  • trunk/devel/FuzzyOcr/Preprocessor.pm

    r60 r61  
    11package FuzzyOcr::Preprocessor; 
    22 
    3 use lib "../"; 
    43use FuzzyOcr::Config; 
     4use FuzzyOcr::Logging qw(debuglog logfile); 
    55 
    66sub new { 
  • trunk/devel/FuzzyOcr/Scanset.pm

    r60 r61  
    11package FuzzyOcr::Scanset; 
    22 
    3 use lib "../"; 
    43use FuzzyOcr::Config; 
     4use FuzzyOcr::Logging qw(debuglog logfile); 
    55 
    66sub new { 
     
    7171    if ($out_in) { 
    7272        $retcode = FuzzyOcr::Misc::save_execute($rcmd, $stdin, $stdout, $stderr); 
    73         open(INFILE, "<$out_in"); 
     73        unless ( open(INFILE, "<$tmpdir/$out_in") ) { 
     74            debuglog("Unable to read output from \"$out_in\" for scanset $self->{label}"); 
     75            $stderr =~ tr/>|</   /; 
     76            if (open(INFILE, "<$stderr")) { 
     77                @result = <INFILE>; 
     78                close(INFILE); 
     79                return ($retcode, @result); 
     80            } 
     81        } 
    7482        @result = <INFILE>; 
    7583        close(INFILE); 
  • trunk/devel/FuzzyOcr/Scoring.pm

    r21 r61  
    66 
    77use lib "../"; 
    8 use FuzzyOcr::Config qw(get_pms get_config set_config debuglog logfile); 
     8use FuzzyOcr::Config qw(get_pms get_config set_config); 
     9use FuzzyOcr::Logging qw(debuglog logfile); 
    910 
    1011# Provide custom scoring functions