[Spambayes-checkins] spambayes/testtools fpfn.py,1.2,1.3

Tony Meyer anadelonbrin at users.sourceforge.net
Tue Apr 26 08:15:29 CEST 2005


Update of /cvsroot/spambayes/spambayes/testtools
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29414/testtools

Modified Files:
	fpfn.py 
Log Message:
Add [ 618932 ] fpfn.py: add interactivity on unix

Except in a cross-platform way.  This means that less isn't used, just print, ,
 but I couldn't think of a way around that.

Also add the ability to do unsures, including interactivity.

Index: fpfn.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/testtools/fpfn.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** fpfn.py	17 Jan 2003 06:42:54 -0000	1.2
--- fpfn.py	26 Apr 2005 06:15:27 -0000	1.3
***************
*** 1,7 ****
  #! /usr/bin/env python
! """Extract false positive and false negative filenames from timcv.py output."""
  
! import sys
  import re
  
  def cmpf(a, b):
--- 1,30 ----
  #! /usr/bin/env python
! """Extract false positive and false negative filenames from timcv.py output.
  
! Usage: %(program)s [options] cv_output(s)
! 
! Where:
!     -h
!         Show usage and exit.
!     -i
!         Prompt for each message, letting the user correct classification
!         mistakes, or remove email.
!     -u
!         Also print unsures.
!     -o section:option:value
!         set [section, option] in the options database to value
!         Requires spambayes package on the PYTHONPATH.
! """
! 
! try:
!     True, False
! except NameError:
!     # Maintain compatibility with Python 2.2
!     True, False = 1, 0
! 
! import os
  import re
+ import sys
+ import getopt
  
  def cmpf(a, b):
***************
*** 16,21 ****
          return cmp(a, b)
  
  def main():
!     for name in sys.argv[1:]:
          try:
              f = open(name + ".txt")
--- 39,74 ----
          return cmp(a, b)
  
+ program = sys.argv[0]
+ 
+ def usage(code, msg=''):
+     """Print usage message and sys.exit(code)."""
+     if msg:
+         print >> sys.stderr, msg
+         print >> sys.stderr
+     print >> sys.stderr, __doc__ % globals()
+     sys.exit(code)
+ 
  def main():
!     try:
!         opts, args = getopt.getopt(sys.argv[1:], 'hiuo:', [])
!     except getopt.error, msg:
!         usage(1, msg)
! 
!     interactive = False
!     do_unsures = False
!     for opt, arg in opts:
!         if opt == '-h':
!             usage(0)
!         elif opt == '-i':
!             interactive = True
!         elif opt == '-u':
!             do_unsures = True
!         elif opt in ('-o', '--option'):
!             # Do the import here, so that it is only necessary to have
!             # spambayes on the PYTHONPATH if this is used.
!             from spambayes.Options import options
!             options.set_from_cmdline(arg, sys.stderr)
! 
!     for name in args:
          try:
              f = open(name + ".txt")
***************
*** 25,28 ****
--- 78,82 ----
          fp = []
          fn = []
+         unsures = []
          for line in f:
              if line.startswith('    new fp: '):
***************
*** 30,41 ****
              elif line.startswith('    new fn: '):
                  fn.extend(eval(line[12:]))
          fp.sort(cmpf)
          fn.sort(cmpf)
          print "--- fp ---"
          for x in fp:
!             print x
          print "--- fn ---"
          for x in fn:
!             print x
  
  if __name__ == '__main__':
--- 84,147 ----
              elif line.startswith('    new fn: '):
                  fn.extend(eval(line[12:]))
+             elif line.startswith'    new unsure: '):
+                 fn.extend(eval(line[16:]))
          fp.sort(cmpf)
          fn.sort(cmpf)
+         unsures.sort(cmpf)
          print "--- fp ---"
          for x in fp:
!             if interactive and os.path.exists(x):
!                 print open(x).read()
!                 answer = raw_input('(S)pam, (R)emove or (L)eave : ').lower()
!                 if answer == 's':
!                     os.rename(x, os.path.join("Data", "Spam",
!                                               "reservoir", x))
!                 elif answer == 'r':
!                     os.remove(x)
!                 elif answer == 'l':
!                     pass
!                 else:
!                     print "Unknown answer. Left."
!             else:
!                 print x
          print "--- fn ---"
          for x in fn:
!             if interactive and os.path.exists(x):
!                 print open(x).read()
!                 answer = raw_input('(H)am, (R)emove or (L)eave : ').lower()
!                 if answer == 'h':
!                     os.rename(x, os.path.join("Data", "Ham",
!                                               "reservoir", x))
!                 elif answer == 'r':
!                     os.remove(x)
!                 elif answer == 'l':
!                     pass
!                 else:
!                     print "Unknown answer. Left."
!             else:
!                 print x
!         if do_unsures:
!             print "--- unsure ---"
!             for x in unsures:
!                 if interactive and os.path.exists(x):
!                     print open(x).read()
!                     print x
!                     answer = raw_input('(H)am, (S)pam, (R)emove or (L)eave : ').lower()
!                     # One of these will move from a set to the reservoir,
!                     # but not change ham/spam, depending on what it was.
!                     if answer == 'h':
!                         os.rename(x, os.path.join("Data", "Ham",
!                                                   "reservoir", x))
!                     elif answer == 's':
!                         os.rename(x, os.path.join("Data", "Sam",
!                                                   "reservoir", x))
!                     elif answer == 'r':
!                         os.remove(x)
!                     elif answer == 'l':
!                         pass
!                     else:
!                         print "Unknown answer. Left."
!                 else:
!                     print x
  
  if __name__ == '__main__':



More information about the Spambayes-checkins mailing list