|
From: <jgr...@us...> - 2003-10-20 13:06:31
|
Update of /cvsroot/popfile/engine
In directory sc8-pr-cvs1:/tmp/cvs-serv22773
Modified Files:
bayes.pl insert.pl pipe.pl
Log Message:
Create test suites for the utility scripts:
insert.pl
bayes.pl
pipe.pl
insert.pl:
Added code to detect errors (file does not exist,
bucket does not exist), output error messages and
return an error code.
Make sure that all POPFile modules are cleaned up
when done.
bayes.pl:
Added code to detect errors (file does not exist),
output error messages and return an error code.
Make sure that all POPFile modules are cleaned up
when done.
pipe.pl:
Make sure that all POPFile modules are cleaned up
when done.
Pass in \n as the end of line character so that the
STDOUT output will have the right end of line character
for the platform pipe.pl is being used on. If this
is not done then POPFile will use the standard network
line ending: \r\n.
Classifer/Bayes.pm:
Add reference to IO::Handle since we need it for
flush.
Add an optional $crlf option to classify_and_modify so
that it can be used with non-network streams that require
an EOL different from \r\n.
If classify_and_modify is told not to save the file in
the history then there's no need to save the file even
temporarily because the streaming parsing added in v0.20.0
doesn't need a copy of the message on disk.
write_line__ might now be passed an undef file handle so
don't try to write to it.
If we are not saving the classification to the history
then don't add the XPL header (or the equivalent link
in a quarantined message) since it wont work.
POPFile/Configuration.pm:
Add code to determine whether there has been a
configuration change. This is done to prevent the
configuration being saved when nothing has changed.
This is particularly needed by the scripts which wont
change the configuration and shouldn't have the code
of a save.
tests/TestInsertScript.tst:
Test suite for insert.pl.
tests/TestBayesScript.tst:
Test suite for bayes.pl.
tests/TestPipeScript.tst:
Test suite for pipe.pl.
Index: bayes.pl
===================================================================
RCS file: /cvsroot/popfile/engine/bayes.pl,v
retrieving revision 1.24
retrieving revision 1.25
diff -C2 -d -r1.24 -r1.25
*** bayes.pl 13 Oct 2003 20:23:40 -0000 1.24
--- bayes.pl 20 Oct 2003 12:53:50 -0000 1.25
***************
*** 32,36 ****
# main
! if ( $#ARGV == 0 ) {
my $c = new POPFile::Configuration;
my $mq = new POPFile::MQ;
--- 32,38 ----
# main
! my $code = 0;
!
! if ( $#ARGV >= 0 ) {
my $c = new POPFile::Configuration;
my $mq = new POPFile::MQ;
***************
*** 62,78 ****
$b->start();
! my @files = glob $ARGV[0];
foreach my $file (@files) {
! print "$file is '" . $b->classify($file) . "'\n";
}
! foreach my $word (sort keys %{$b->{parser__}->{words__}}) {
! print "$word $b->{parser__}->{words__}{$word}\n";
}
}
else
{
! print "bayes.pl - output the score that a message is in each bucket\n\n";
print "Usage: bayes.pl <messages>\n";
print " <messages> Filename of message(s) to classify\n";
}
--- 64,105 ----
$b->start();
! my @files;
!
! if ($^O =~ /linux/) {
! @files = @ARGV[0 .. $#ARGV];
! } else {
! @files = map { glob } @ARGV[0 .. $#ARGV];
! }
!
foreach my $file (@files) {
! if ( !(-e $file) ) {
! print STDERR "Error: File `$file' does not exist, classification aborted.\n";
! $code = 1;
! last;
! }
}
! if ( $code == 0 ) {
! foreach my $file (@files) {
! print "`$file' is `" . $b->classify( $file ) . "'\n";
! }
!
! foreach my $word (sort keys %{$b->{parser__}->{words__}}) {
! print "$word $b->{parser__}->{words__}{$word}\n";
! }
}
+
+ $b->stop();
+ $l->stop();
+ $mq->stop();
+ $c->stop();
}
else
{
! print "bayes.pl - output the classification of a message\n\n";
print "Usage: bayes.pl <messages>\n";
print " <messages> Filename of message(s) to classify\n";
+ $code = 1;
}
+
+ exit $code;
Index: insert.pl
===================================================================
RCS file: /cvsroot/popfile/engine/insert.pl,v
retrieving revision 1.24
retrieving revision 1.25
diff -C2 -d -r1.24 -r1.25
*** insert.pl 9 Oct 2003 18:22:11 -0000 1.24
--- insert.pl 20 Oct 2003 12:53:50 -0000 1.25
***************
*** 30,33 ****
--- 30,35 ----
use POPFile::Logger;
+ my $code = 0;
+
if ( $#ARGV > 0 ) {
my $c = new POPFile::Configuration;
***************
*** 65,76 ****
@files = @ARGV[1 .. $#ARGV];
} else {
! @files = map { glob } @ARGV[1 .. $#ARGV];
}
! if ( !$b->add_messages_to_bucket( $ARGV[0], @files ) ) {
! print "Bucket $ARGV[0] does not exist\n";
! } else {
! print "Added ", $#files+1, " files to $ARGV[0]\n";
}
} else {
print "insert.pl - insert mail messages into a specific bucket\n\n";
--- 67,97 ----
@files = @ARGV[1 .. $#ARGV];
} else {
! @files = map { glob } @ARGV[1 .. $#ARGV];
}
! # Check for the existence of each file first because the API
! # call we use does not care if a file is missing
!
! foreach my $file (@files) {
! if ( !(-e $file) ) {
! print STDERR "Error: File `$file' does not exist, insert aborted.\n";
! $code = 1;
! last;
! }
}
+
+ if ( $code == 0 ) {
+ if ( !$b->add_messages_to_bucket( $ARGV[0], @files ) ) {
+ print STDERR "Error: Bucket `$ARGV[0]' does not exist, insert aborted.\n";
+ $code = 1;
+ } else {
+ print "Added ", $#files+1, " files to `$ARGV[0]'\n";
+ }
+ }
+
+ $b->stop();
+ $l->stop();
+ $mq->stop();
+ $c->stop();
} else {
print "insert.pl - insert mail messages into a specific bucket\n\n";
***************
*** 78,81 ****
--- 99,105 ----
print " <bucket> The name of the bucket\n";
print " <messages> Filename of message(s) to insert\n";
+ $code = 1;
}
+
+ exit $code;
Index: pipe.pl
===================================================================
RCS file: /cvsroot/popfile/engine/pipe.pl,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** pipe.pl 6 Jul 2003 01:11:47 -0000 1.2
--- pipe.pl 20 Oct 2003 12:53:50 -0000 1.3
***************
*** 17,22 ****
# main
! if ( $#ARGV == -1 )
! {
my $c = new POPFile::Configuration;
my $mq = new POPFile::MQ;
--- 17,21 ----
# main
! if ( $#ARGV == -1 ) {
my $c = new POPFile::Configuration;
my $mq = new POPFile::MQ;
***************
*** 54,62 ****
$b->start();
! $b->classify_and_modify(\*STDIN, \*STDOUT, 0, 0, 1, '', 1) . "'\n";
! }
! else
! {
print "pipe.pl - reads a message on STDIN, classifies it, outputs the modified version on STDOUT\n\n";
print "Usage: pipe.pl\n";
}
--- 53,69 ----
$b->start();
! $b->classify_and_modify(\*STDIN, \*STDOUT, 0, 0, 1, '', 1, "\n") . "'\n";
!
! $b->stop();
! $l->stop();
! $mq->stop();
! $c->stop();
! $u->stop();
!
! exit 0;
! } else {
print "pipe.pl - reads a message on STDIN, classifies it, outputs the modified version on STDOUT\n\n";
print "Usage: pipe.pl\n";
+
+ exit 1;
}
|