Changeset 75
- Timestamp:
- 01.12.2006 03:32:23 (2 years ago)
- Files:
-
- trunk/devel/FuzzyOcr.pm (modified) (11 diffs)
- trunk/devel/FuzzyOcr/Config.pm (modified) (20 diffs)
- trunk/devel/FuzzyOcr/Deanimate.pm (modified) (4 diffs)
- trunk/devel/FuzzyOcr/Hashing.pm (modified) (11 diffs)
- trunk/devel/FuzzyOcr/Logging.pm (modified) (2 diffs)
- trunk/devel/FuzzyOcr/Misc.pm (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/devel/FuzzyOcr.pm
r74 r75 70 70 if ($conf->{focr_global_timeout}) { 71 71 my $t = get_timeout(); 72 debuglog("Global Timeout set at ".$conf->{focr_timeout}." sec." ,2);72 debuglog("Global Timeout set at ".$conf->{focr_timeout}." sec."); 73 73 $t->run(sub { 74 74 $end = fuzzyocr_do( $self, $conf, $pms ); … … 121 121 my $main = $self->{main}; 122 122 123 debuglog("Starting FuzzyOcr..." ,2);123 debuglog("Starting FuzzyOcr..."); 124 124 foreach my $p ( 125 125 $pms->{msg}->find_parts(qr(^image\b)i), … … 181 181 $imgfiles{$imgfilename}{ftype} = 1; 182 182 ($w,$h) = unpack("vv",substr($pdata,6,4)); 183 debuglog("GIF: [${h}x${w}] $imgfilename");183 infolog("GIF: [${h}x${w}] $imgfilename"); 184 184 $imgfiles{$imgfilename}{width} = $w; 185 185 $imgfiles{$imgfilename}{height} = $h; … … 208 208 } else { 209 209 ($h,$w) = unpack("nn",substr($pdata,$pos+3,4)); 210 debuglog("JPEG: [${h}x${w}] $imgfilename");210 infolog("JPEG: [${h}x${w}] $imgfilename"); 211 211 $imgfiles{$imgfilename}{ftype} = 2; 212 212 $imgfiles{$imgfilename}{height} = $h; … … 219 219 $imgfiles{$imgfilename}{width} = $w; 220 220 $imgfiles{$imgfilename}{height} = $h; 221 debuglog("PNG: [${h}x${w}] $imgfilename");221 infolog("PNG: [${h}x${w}] $imgfilename"); 222 222 } elsif ( substr($pdata,0,2) eq "BM" ) { 223 223 ## BMP File … … 226 226 $imgfiles{$imgfilename}{width} = $w; 227 227 $imgfiles{$imgfilename}{height} = $h; 228 debuglog("BMP: [${h}x${w}] $imgfilename");228 infolog("BMP: [${h}x${w}] $imgfilename"); 229 229 } elsif ( 230 230 (substr($pdata,0,4) eq "\x4d\x4d\x00\x2a") or … … 241 241 last if ($h != 0 and $w != 0); 242 242 } 243 debuglog("TIFF: [${h}x${w}] $imgfilename ($worder)");244 debuglog("Cannot determite size of TIFF image, setting to '1x1'") if ($h == 0 and $w == 0);243 infolog("TIFF: [${h}x${w}] $imgfilename ($worder)"); 244 infolog("Cannot determite size of TIFF image, setting to '1x1'") if ($h == 0 and $w == 0); 245 245 $imgfiles{$imgfilename}{ftype} = 5; 246 246 $imgfiles{$imgfilename}{width} = $w ? $w : 1; … … 259 259 print PICT $pdata; 260 260 close PICT; 261 debuglog("Saved: $imgfilename");261 infolog("Saved: $imgfilename"); 262 262 $cnt++; 263 263 } … … 278 278 # Try to load personal wordlist 279 279 if ($conf->{focr_personal_wordlist} =~ m/^\//) { 280 infolog("Attempting to load personal wordlist...");281 280 read_words( $conf->{focr_personal_wordlist} ); 282 281 } else { … … 285 284 read_words( $peruserlist ); 286 285 } else { 287 errorlog("Cannot read personal_wordlist: $peruserlist, skipping..."); 286 # Only complain if the file exists 287 if ( -e $peruserlist ) { 288 errorlog("Cannot read personal_wordlist: $peruserlist, skipping..."); 289 } 288 290 } 289 291 } … … 658 660 } 659 661 660 debuglog("ocrdata=>>".join("",@result)."<<=end") if ($conf->{focr_verbose}>2);662 debuglog("ocrdata=>>".join("",@result)."<<=end"); 661 663 662 664 foreach my $ww (keys %words) { trunk/devel/FuzzyOcr/Config.pm
r74 r75 3 3 4 4 use lib qw(..); 5 use FuzzyOcr::Logging qw(debuglog errorlog infolog);5 use FuzzyOcr::Logging qw(debuglog infolog warnlog errorlog); 6 6 use FuzzyOcr::Scanset; 7 7 use FuzzyOcr::Preprocessor; … … 83 83 sub set_pid { 84 84 $pid = shift; 85 debuglog("Saved pid: $pid" ,2);85 debuglog("Saved pid: $pid"); 86 86 } 87 87 … … 439 439 } 440 440 441 infolog("Adding <".scalar(@cmds)."> new options");442 441 $conf->{parser}->register_commands(\@cmds); 443 442 } … … 449 448 my $main = $self->{main}; 450 449 my $retcode; 451 info("FuzzyOcr: focr_end_config");452 450 453 451 # Parse preprocessor file … … 481 479 }); 482 480 } else { 483 errorlog("$bin is already defined, skipping...");481 warnlog("$bin is already defined, skipping..."); 484 482 } 485 483 } … … 504 502 my $b = "focr_bin_$a"; 505 503 if (defined $conf->{$b} and ! -x $conf->{$b}) { 506 errorlog("cannot exec $a, removing...");504 infolog("cannot exec $a, removing..."); 507 505 delete $conf->{$b}; 508 506 } … … 512 510 foreach my $p (@paths) { 513 511 my $f = "$p/$a"; 514 debuglog("Testing $f...",2);515 512 next unless -x $f; 516 513 $conf->{$b} = $f; … … 520 517 infolog("Using $a => $conf->{$b}"); 521 518 } else { 522 errorlog("Cannot find executable for $a");519 warnlog("Cannot find executable for $a"); 523 520 } 524 521 } … … 529 526 next unless $k =~ m/^focr_/; 530 527 next if $k =~ m/^focr_bin_/; 531 debuglog(" $k => ".$conf->{$k} ,2);528 debuglog(" $k => ".$conf->{$k}); 532 529 } 533 530 … … 561 558 unless (HAS_DBI and HAS_DBD_MYSQL) { 562 559 $conf->{focr_enable_image_hashing} = 0; 563 infolog("Disable Image Hashing");560 errorlog("Disable Image Hashing"); 564 561 errorlog("Missing DBI") unless HAS_DBI; 565 562 errorlog("Missing DBD::mysql") unless HAS_DBD_MYSQL; … … 569 566 unless (HAS_MLDBM and HAS_DB_FILE and HAS_STORABLE) { 570 567 $conf->{focr_enable_image_hashing} = 0; 571 infolog("Disable Image Hashing");568 errorlog("Disable Image Hashing"); 572 569 errorlog("Missing MLDBM") unless HAS_MLDBM; 573 570 errorlog("Missing DB_File") unless HAS_DB_FILE; … … 590 587 my $db = $DB{$k}; 591 588 if ($db->{check} < $now) { 592 debuglog("Expire: <$k> Reason: $db->{check} < $now");589 infolog("Expire: <$k> Reason: $db->{check} < $now"); 593 590 delete $DB{$k}; $hash++; 594 591 } … … 669 666 } 670 667 $sql .= ")"; 671 debuglog($sql ,2);668 debuglog($sql); 672 669 $ddb->do($sql); $err++; 673 670 } … … 704 701 } 705 702 $sql .= ")"; 706 debuglog($sql ,2);703 debuglog($sql); 707 704 $ddb->do($sql); $err++; 708 705 } … … 724 721 my $tfile = $_[1] || 'Personal'; 725 722 unless ( -r $wfile ) { 726 errorlog("Cannot read $tfile wordlist: \"$wfile\"\n Please check file path and permissions are correct.");723 warnlog("Cannot read $tfile wordlist: \"$wfile\"\n Please check file path and permissions are correct."); 727 724 return; 728 725 } … … 752 749 my ($file) = @_; 753 750 unless (open(SFILE, "<$file")) { 754 errorlog("Failed to open scanset file \"$file\", aborting...");751 warnlog("Failed to open scanset file \"$file\", aborting..."); 755 752 return 1; 756 753 } … … 769 766 next; 770 767 } 771 debuglog("line $_" ,2);768 debuglog("line $_"); 772 769 if ($_ =~ /^(\s)*preprocessors(\s)*=(\s)*(.*)$/i) { 773 770 my $prep = $4; … … 808 805 # Start a new scanset 809 806 } elsif ($_ =~ /^(\s)*scanset(\s)+(.+?)(\s)+\{$/i) { 810 debuglog("line $_" ,2);807 debuglog("line $_"); 811 808 if (grep $_ eq $3, @slabels) { 812 809 errorlog("Label already used earlier in line $., aborting..."); … … 840 837 # We are in the middle of a preprocessor 841 838 if(defined $preprocessor) { 842 debuglog("line: $_" ,2);839 debuglog("line: $_"); 843 840 if ($_ =~ /^(\s)*(command|args)(\s)*=(\s)*(.*)$/i) { 844 841 my $tag = $2; … … 866 863 # Start a new preprocessor 867 864 } elsif ($_ =~ /^(\s)*preprocessor(\s)+(.+?)(\s)+\{$/i) { 868 debuglog("line: $_" ,2);865 debuglog("line: $_"); 869 866 if (grep $_ eq $3, @plabels) { 870 867 errorlog("Error, label already used earlier in line $., aborting..."); trunk/devel/FuzzyOcr/Deanimate.pm
r70 r75 8 8 use FuzzyOcr::Config qw(get_config set_config get_tmpdir); 9 9 use FuzzyOcr::Misc qw(save_execute); 10 use FuzzyOcr::Logging qw(errorlog infolog);10 use FuzzyOcr::Logging qw(errorlog warnlog infolog); 11 11 12 12 # Provide functions to deanimate gifs … … 42 42 $tfile = $tfile3; 43 43 } else { 44 errorlog("$conf->{'focr_bin_gifsicle'}: ".44 warnlog("$conf->{'focr_bin_gifsicle'}: ". 45 45 ($retcode<0) ? 'Timed out' : 'Error' 46 46 ." [$retcode], image not reduced!"); … … 53 53 ">>$efile"); 54 54 return $tfile2 if ($retcode == 0); 55 infolog("$conf->{focr_bin_gifsicle}: cannot extract image#${index}");55 warnlog("$conf->{focr_bin_gifsicle}: cannot extract image#${index}"); 56 56 return $tfile; 57 57 } … … 106 106 }sx; 107 107 if ($n != $frameno) { 108 errorlog ( "Trouble parsing 'gifsicle --info' output.\n"108 warnlog ( "Trouble parsing 'gifsicle --info' output.\n" 109 109 . " Expected 'image \#$frameno', found 'image \#$n', skipping..." ); 110 110 $info{'error'}++; trunk/devel/FuzzyOcr/Hashing.pm
r74 r75 10 10 use FuzzyOcr::Config qw(get_thresholds get_config set_config get_tmpdir get_mysql_ddb); 11 11 use FuzzyOcr::Misc qw(save_execute); 12 use FuzzyOcr::Logging qw(debuglog errorlog infolog);12 use FuzzyOcr::Logging qw(debuglog errorlog warnlog infolog); 13 13 use Fcntl; 14 14 use Fcntl ':flock'; … … 59 59 my $conf = get_config(); 60 60 if ($conf->{focr_enable_image_hashing} == 0) { 61 infolog("Image Hashing is disabled");61 warnlog("Image Hashing is disabled"); 62 62 return (0,''); 63 63 } … … 76 76 if ($conf->{focr_enable_image_hashing} == 3) { 77 77 unless (defined $conf->{focr_mysql_ddb}) { 78 infolog("Connection to MySQL server unavailable");78 warnlog("Connection to MySQL server unavailable"); 79 79 return (0,''); 80 80 } … … 145 145 tie %DB, 'MLDBM', $dbfile, O_RDWR or $ret++; 146 146 if ($ret>0) { 147 errorlog("No Image Hash database found at \"$dbfile\", or permissions wrong.");147 warnlog("No Image Hash database found at \"$dbfile\", or permissions wrong."); 148 148 return (0,''); 149 149 } … … 194 194 $ret = open HASH, $conf->{focr_digest_db}; 195 195 unless($ret) { 196 errorlog("No Image Hash database found at \"$conf->{focr_digest_db}\", or permissions wrong.");196 warnlog("No Image Hash database found at \"$conf->{focr_digest_db}\", or permissions wrong."); 197 197 return (0,''); 198 198 } … … 219 219 if ($conf->{focr_enable_image_hashing} == 3) { 220 220 unless (defined $conf->{focr_mysql_ddb}) { 221 infolog("Connection to MySQL server unavailable");221 warnlog("Connection to MySQL server unavailable"); 222 222 return; 223 223 } … … 276 276 tie %DB, 'MLDBM', $dbfile or $ret++; 277 277 if ($ret>0) { 278 errorlog("Unable to open/create Image Hash database at \"$dbfile\", check permissions.");278 warnlog("Unable to open/create Image Hash database at \"$dbfile\", check permissions."); 279 279 return; 280 280 } … … 303 303 } 304 304 unless ($ret) { 305 errorlog("Unable to open/create Image Hash database at \"$conf->{focr_digest_db}\", check permissions.");305 warnlog("Unable to open/create Image Hash database at \"$conf->{focr_digest_db}\", check permissions."); 306 306 return; 307 307 } … … 313 313 close(DB); 314 314 } 315 #debuglog("Digest: $digest");315 debuglog("Digest: $digest"); 316 316 } 317 317 … … 334 334 unless (-r $pfile) { 335 335 errorlog("Cannot read $pfile"); 336 return(1, '');336 return(1, ''); 337 337 } 338 338 339 339 my ($r, @stdout_data) = save_execute( 340 "$conf->{focr_bin_ppmhist} -noheader $pfile", 341 undef, 340 "$conf->{focr_bin_ppmhist} -noheader $pfile", undef, 342 341 ">$imgdir/ppmhist.info", 343 342 ">/dev/null", 1); … … 368 367 } 369 368 } 370 infolog("Got: <$hash>");369 debuglog("Got: <$hash>"); 371 370 return(0, $hash); 372 371 } trunk/devel/FuzzyOcr/Logging.pm
r70 r75 2 2 3 3 use base 'Exporter'; 4 our @EXPORT_OK = qw(debuglog errorlog infolog logfile);4 our @EXPORT_OK = qw(debuglog errorlog infolog warnlog logfile); 5 5 6 6 use Mail::SpamAssassin::Logger qw(log_message would_log); … … 34 34 35 35 sub errorlog { 36 _log("error",$_[0]) if $conf->{focr_log_stderr}; 36 37 my $conf = FuzzyOcr::Config::get_config(); 37 _log("error",$_[0]); 38 logfile($_[0]) if defined $conf->{focr_logfile}; 38 if (defined $conf->{focr_logfile}) { 39 logfile($_[0]); 40 } 41 } 42 43 sub warnlog { 44 my $conf = FuzzyOcr::Config::get_config(); 45 return if ($conf->{focr_verbose} < 1); 46 _log("warn",$_[0]) if $conf->{focr_log_stderr}; 47 if (defined $conf->{focr_logfile}) { 48 logfile($_[0]); 49 } 39 50 } 40 51 41 52 sub infolog { 42 53 my $conf = FuzzyOcr::Config::get_config(); 43 _log("info",$_[0]); 44 logfile($_[0]) if defined $conf->{focr_logfile}; 54 return if ($conf->{focr_verbose} < 2); 55 _log("info",$_[0]) if $conf->{focr_log_stderr}; 56 if (defined $conf->{focr_logfile}) { 57 logfile($_[0]); 58 } 45 59 } 46 60 47 61 sub debuglog { 48 62 my $conf = FuzzyOcr::Config::get_config(); 49 my $limit = defined $_[1] ? $_[1] : 1; 50 my $test = defined $conf->{focr_verbose} ? $conf->{focr_verbose} : 10; 51 if ( $test > $limit ) { 52 _log("info",$_[0]) if $conf->{focr_log_stderr}; 53 logfile($_[0]) if defined $conf->{focr_logfile}; 54 } else { 55 _log("dbg",$_[0]) if (would_log('dbg')); 63 return if ($conf->{focr_verbose} < 3); 64 _log("dbg",$_[0]) if $conf->{focr_log_stderr}; 65 if (defined $conf->{focr_logfile}) { 66 logfile($_[0]); 56 67 } 57 68 } trunk/devel/FuzzyOcr/Misc.pm
r70 r75 7 7 use lib qw(..); 8 8 use FuzzyOcr::Config qw(set_pid unset_pid get_config get_timeout); 9 use FuzzyOcr::Logging qw(debuglog errorlog infolog);9 use FuzzyOcr::Logging qw(debuglog errorlog warnlog infolog); 10 10 use Time::HiRes qw( gettimeofday tv_interval ); 11 11 … … 34 34 } 35 35 } 36 infolog("Remove DIR: $dir");36 debuglog("Remove DIR: $dir"); 37 37 unless(rmdir $dir) { 38 38 errorlog("Cannot remove DIR: $dir"); … … 55 55 return -1; 56 56 } elsif (not $pid) { 57 debuglog("Exec : $cmd" ,2);58 debuglog("Stdin : $stdin" ,2) if (defined $stdin);59 debuglog("Stdout: $stdout" ,2) if (defined $stdout);60 debuglog("Stderr: $stderr" ,2) if (defined $stderr);57 debuglog("Exec : $cmd"); 58 debuglog("Stdin : $stdin") if (defined $stdin); 59 debuglog("Stdout: $stdout") if (defined $stdout); 60 debuglog("Stderr: $stderr") if (defined $stderr); 61 61 if (defined $stdin) { 62 62 open(STDIN, $stdin); … … 94 94 return -1; 95 95 } elsif (not $pid) { 96 debuglog("Exec : $cmd" ,2);97 debuglog("Stdin : $stdin" ,2) if (defined $stdin);98 debuglog("Stdout: $stdout" ,2) if (defouted $stdout);99 debuglog("Stderr: $stderr" ,2) if (deferred $stderr);96 debuglog("Exec : $cmd"); 97 debuglog("Stdin : $stdin") if (defined $stdin); 98 debuglog("Stdout: $stdout") if (defouted $stdout); 99 debuglog("Stderr: $stderr") if (deferred $stderr); 100 100 if (defined $stdin) { 101 101 open(STDIN, $stdin);
