[Spambayes-checkins] spambayes hammie.py,1.7,1.8

Guido van Rossum gvanrossum@users.sourceforge.net
Fri, 06 Sep 2002 21:31:10 -0700


Update of /cvsroot/spambayes/spambayes
In directory usw-pr-cvs1:/tmp/cvs-serv6491

Modified Files:
	hammie.py 
Log Message:
Minor cleanup; standardize exit codes; add some docs/comments.


Index: hammie.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/hammie.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** hammie.py	7 Sep 2002 04:23:15 -0000	1.7
--- hammie.py	7 Sep 2002 04:31:08 -0000	1.8
***************
*** 1,3 ****
--- 1,4 ----
  #! /usr/bin/env python
+ # At the moment, this requires Python 2.3 from CVS
  
  # A driver for the classifier module.  Currently mostly a wrapper around
***************
*** 27,32 ****
  """
  
- from __future__ import generators
- 
  import sys
  import os
--- 28,31 ----
***************
*** 40,44 ****
  import cPickle as pickle
  
! program = sys.argv[0]
  
  # Tim's tokenizer kicks far more booty than anything I would have
--- 39,43 ----
  import cPickle as pickle
  
! program = sys.argv[0] # For usage(); referenced by docstring above
  
  # Tim's tokenizer kicks far more booty than anything I would have
***************
*** 258,261 ****
--- 257,261 ----
  
  def usage(code, msg=''):
+     """Print usage message and sys.exit(code)."""
      if msg:
          print >> sys.stderr, msg
***************
*** 265,275 ****
  
  def main():
      try:
          opts, args = getopt.getopt(sys.argv[1:], 'hdfg:s:p:u:')
      except getopt.error, msg:
!         usage(1, msg)
  
      if not opts:
!         usage(0, "No options given")
  
      pck = "hammie.db"
--- 265,276 ----
  
  def main():
+     """Main program; parse options and go."""
      try:
          opts, args = getopt.getopt(sys.argv[1:], 'hdfg:s:p:u:')
      except getopt.error, msg:
!         usage(2, msg)
  
      if not opts:
!         usage(2, "No options given")
  
      pck = "hammie.db"
***************
*** 292,296 ****
              unknown = arg
      if args:
!         usage(1)
  
      save = False
--- 293,297 ----
              unknown = arg
      if args:
!         usage(2, "Positional arguments not allowed")
  
      save = False