Changeset 58

Show
Ignore:
Timestamp:
25.11.2006 00:37:28 (2 years ago)
Author:
jorge
Message:

+ small bug fixes,
+ added statistical information regarding sub-program execution times to help evaluate bottlenecks. (requires Time::HiRes? generally available);
+ connect to mysql db only if images are found.
+ when focr_verbose is greater than 1 you can send logging to stderr if focr_log_stderr is set to 1
+ reduced debug logging by requiring focr_verbose = 3 for to log most sql statements as well as other informational messages

Files:

Legend:

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

    r55 r58  
    1616# Verbosity level (see manual) Attention: Don't set to 0, but to 0.0 for quiet operation. (Default value: 1) 
    1717#focr_verbose 2 
     18# 
     19# When focr_verbose>1 you can log to stderr by setting this variable to 1 (Default value: 0) 
     20#focr_log_stderr 1 
    1821# 
    1922# Logfile (make sure it is writable by the plugin) (Default value: /etc/mail/spamassassin/FuzzyOcr.log) 
  • trunk/devel/FuzzyOcr.pm

    r57 r58  
    1919use Fcntl ':flock'; 
    2020 
    21 use lib qw(.); # Allow placing of FuzzyOcr in siteconfigdir 
     21use lib qw(. /etc/mail/spamassassin); # Allow placing of FuzzyOcr in siteconfigdir 
     22 
    2223use FuzzyOcr::Config qw(kill_pid get_tmpdir set_tmpdir get_pms save_pms get_timeout get_ddb get_thresholds get_scansets get_config get_wordlist set_config finish_parsing_end load_global_words load_personal_words debuglog logfile); 
    2324use FuzzyOcr::Hashing qw(check_image_hash_db check_image_hash_db add_image_hash_db calc_image_hash); 
     
    9394    } 
    9495 
     96    my $ddb; 
    9597    my $imgdir; 
    9698    my %imgfiles = (); 
     
    113115            debuglog("Variable \$ENV{HOME} not defined and getpwuid failed, personal wordlist function not available..."); 
    114116        } 
    115     } 
    116     if ($conf->{focr_enable_image_hashing} == 3) { 
    117         $conf->{focr_ddb} = get_ddb(); 
    118117    } 
    119118 
     
    266265    } 
    267266    debuglog("Found: $cnt images"); $cnt = 0; 
     267    if ($conf->{focr_enable_image_hashing} == 3) { 
     268        $ddb = $conf->{focr_ddb} = get_ddb(); 
     269    } 
    268270 
    269271    my $haserr = open RAWERR, ">$imgdir/raw.err"; 
     
    602604            $scan =~ s/\$efile/$efile/g; 
    603605            #unlink $efile if (-e $efile); 
    604             debuglog("Trying: $scanset"); 
     606            #debuglog("Trying: $scanset"); 
    605607            printf RAWERR qq(## $scan 2>>$efile\n) if ($haserr>0); 
    606608 
     
    707709        } 
    708710        if ( $conf->{focr_verbose} > 0 and $conf->{focr_verbose} < 3 ) { 
    709             debuglog($debuginfo)
     711            debuglog($debuginfo) unless ($conf->{focr_enable_image_hashing} == 3)
    710712        } 
    711713        for my $set ( 0 .. 3 ) { 
     
    719721    } 
    720722    if ($conf->{focr_enable_image_hashing} == 3) { 
    721         $conf->{focr_ddb}->disconnect; 
     723        $ddb->disconnect; 
    722724    } 
    723725    debuglog("FuzzyOcr ending successfully..."); 
  • trunk/devel/FuzzyOcr/Config.pm

    r55 r58  
    134134sub get_ddb { 
    135135    return undef unless (HAS_DBI and HAS_DBD_MYSQL); 
     136    use DBI; 
    136137    my $conf = get_config(); 
    137138    my %dopts = ( AutoCommit => 1 ); 
     
    197198        setting => 'focr_logfile', 
    198199        type => $Mail::SpamAssassin::Conf::CONF_TYPE_STRING 
     200       }); 
     201 
     202    push (@cmds, { 
     203        setting => 'focr_log_stderr', 
     204        default => 0, 
     205        type => $Mail::SpamAssassin::Conf::CONF_TYPE_BOOL 
    199206       }); 
    200207 
     
    406413    $conf = $opts->{conf}; 
    407414 
     415    #add_facilities('FuzzyOcr'); 
    408416    # find external binaries 
    409417    @paths = split(/:/, $conf->{'focr_path_bin'}); 
     
    521529    } 
    522530    if ($conf->{focr_enable_image_hashing} == 3) { 
    523         my $ddb = $conf->{focr_ddb} = get_ddb(); 
     531        my $ddb = get_ddb(); 
    524532        if (defined $ddb) { 
    525533            my $db   = $conf->{focr_mysql_db}; 
     
    594602                debuglog("Stored [$err] Hashes in $db.$tab") if $err>0; 
    595603            } 
    596             $conf->{focr_ddb}->disconnect; 
    597             delete $conf->{focr_ddb}; 
     604            $ddb->disconnect; 
    598605            debuglog("done updating MySQL database"); 
    599606        } 
     
    685692    my @lines = split('\n',$_[0]); 
    686693    my $limit = defined $_[1] ? $_[1] : 1; 
    687     foreach (@lines) { dbg ("FuzzyOcr: $_"); } 
    688694    if ( $conf->{focr_verbose} > $limit ) { 
    689695        logfile($_[0]) if defined $conf->{focr_logfile}; 
     696        if ($conf->{focr_log_stderr}) { 
     697            foreach (@lines) { info ("FuzzyOcr: $_"); } 
     698        } 
     699    } else { 
     700        foreach (@lines) { dbg  ("FuzzyOcr: $_"); } 
    690701    } 
    691702} 
  • trunk/devel/FuzzyOcr/Hashing.pm

    r57 r58  
    121121            # Expire old records... 
    122122            $sql = qq(delete from $db.$dbfile where $dbfile.check < $then); 
    123             debuglog($sql); 
     123            debuglog($sql,2); 
    124124            $ddb->do($sql); 
    125125        } 
     
    130130            debuglog("Matched [$next] time(s). Prev match: ".fmt_time($now - $when)); 
    131131            $sql = qq(update $db.$dbfile set $dbfile.match='$next',$dbfile.check='$now' where $dbfile.key='$key'); 
    132             debuglog($sql); 
     132            debuglog($sql,2); 
    133133            $ddb->do($sql); 
    134134        } 
  • trunk/devel/FuzzyOcr/Misc.pm

    r57 r58  
    4343    my $t = get_timeout(); 
    4444    my ($cmd, $stdout, $stderr, $return_stdout) = @_; 
     45    my ($pgm,undef) = split(' ',$cmd,2); 
    4546    $stdout = '>/dev/null' unless $stdout; 
    4647    $stderr = '>/dev/null' unless $stderr; 
    4748    my $retcode; 
    4849    if ($conf->{'focr_global_timeout'}) { 
     50        my $begin = [gettimeofday]; 
    4951        my $pid = fork(); 
    5052        if (not defined $pid) { 
     
    5254            return -1; 
    5355        } elsif (not $pid) { 
     56            debuglog("Exec: $cmd $stdout $stderr",2); 
    5457            open(STDOUT, $stdout); 
    5558            open(STDERR, $stderr); 
     
    5861        } else { 
    5962            set_pid($pid); 
    60             wait(); 
    61             $retcode = $?; 
     63            wait(); $retcode = $?; 
     64            debuglog("Elapsed: ". 
     65                sprintf ("%.6f",tv_interval($begin, [gettimeofday])) 
     66                ." sec. ($pgm)"); 
    6267            unset_pid(); 
    6368            if ($return_stdout and $stdout !~ m,/dev/null,i) { 
     
    8085                return -1; 
    8186            } elsif (not $pid) { 
    82                 debuglog("Exec: $cmd $stdout $stderr"); 
     87                debuglog("Exec: $cmd $stdout $stderr",2); 
    8388                open(STDOUT, $stdout); 
    8489                open(STDERR, $stderr); 
     
    9095                debuglog("Elapsed: ". 
    9196                    sprintf ("%.6f",tv_interval($begin, [gettimeofday])) 
    92                     ." sec. ($cmd)"); 
     97                    ." sec. ($pgm)"); 
    9398                unset_pid(); 
    9499                if ($return_stdout and $stdout !~ m,/dev/null,i) { 
  • trunk/devel/INSTALL

    r49 r58  
    5757focr_max_size_<img_type> <max-size> 
    5858 
    59 where <img_type> is one of the following: 
     59where <max-size> is expressed in bytes (compared to the pnm 
     60filesize), and <img_type> is one of the following: 
    6061 
    6162- gif