[Spambayes-checkins] spambayes/scripts sb_upload.py,1.3,1.4

Tony Meyer anadelonbrin at users.sourceforge.net
Thu Oct 7 08:10:00 CEST 2004


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

Modified Files:
	sb_upload.py 
Log Message:
Add patch from Graham Ashton to allow users of sb_upload.py to not just upload, but
also train.

Index: sb_upload.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/scripts/sb_upload.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** sb_upload.py	15 Sep 2004 06:53:58 -0000	1.3
--- sb_upload.py	7 Oct 2004 06:09:57 -0000	1.4
***************
*** 12,15 ****
--- 12,16 ----
  usage:  %(progname)s [-h] [-n] [-s server] [-p port] [-r N]
                       [-o section:option:value]
+                      [-t (ham|spam)] [-o section:option:value]
  
  Options:
***************
*** 19,22 ****
--- 20,24 ----
      -p, --port=   - provide alternate server port (default %(port)s)
      -r, --prob=   - feed the message to the trainer w/ prob N [0.0...1.0]
+     -t, --train=  - train the message (pass either 'ham' or 'spam')
      -o, --option= - set [section, option] in the options database to value
  """
***************
*** 101,109 ****
      port = options["html_ui", "port"]
      prob = 1.0
  
      try:
!         opts, args = getopt.getopt(argv, "hns:p:r:o:",
                                     ["help", "null", "server=", "port=",
!                                     "prob=", "option="])
      except getopt.error:
          usage(globals(), locals())
--- 103,112 ----
      port = options["html_ui", "port"]
      prob = 1.0
+     train_as = None
  
      try:
!         opts, args = getopt.getopt(argv, "hns:p:r:t:o:",
                                     ["help", "null", "server=", "port=",
!                                     "prob=", "train=", "option="])
      except getopt.error:
          usage(globals(), locals())
***************
*** 126,129 ****
--- 129,138 ----
                  sys.exit(1)
              prob = n
+         elif opt in ("-t", "--train"):
+             arg = arg.capitalize()
+             if arg not in ("Ham", "Spam"):
+                 usage(globals(), locals())
+                 sys.exit(1)
+             train_as = arg
          elif opt in ('-o', '--option'):
              options.set_from_cmdline(arg, sys.stderr)
***************
*** 138,143 ****
      if random.random() < prob:
          try:
!             post_multipart("%s:%d"%(server,port), "/upload", [],
!                            [('file', 'message.dat', data)])
          except:
              # not an error if the server isn't responding
--- 147,159 ----
      if random.random() < prob:
          try:
!             if train_as is not None:
!                 which_text = "Train as %s" % (train_as,)
!                 post_multipart("%s:%d" % (server, port), "/train",
!                                [("which", which_text),
!                                 ("text", "")],
!                                [("file", "message.dat", data)])
!             else:
!                 post_multipart("%s:%d" % (server,port), "/upload", [],
!                                [('file', 'message.dat', data)])
          except:
              # not an error if the server isn't responding



More information about the Spambayes-checkins mailing list