[Spambayes-checkins] spambayes/Outlook2000 manager.py,1.60,1.61

Mark Hammond mhammond at users.sourceforge.net
Mon Jun 16 22:07:45 EDT 2003


Update of /cvsroot/spambayes/spambayes/Outlook2000
In directory sc8-pr-cvs1:/tmp/cvs-serv25076

Modified Files:
	manager.py 
Log Message:
Catch the assertion error in the classifier, and warn the user their
database is corrupt.  Not great, but better than nothing and 1 million
more emails to the mailing list.

Also introduces ReportErrorOnce, useful for errors on event handlers
that you don't want to bombard the user with.


Index: manager.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/Outlook2000/manager.py,v
retrieving revision 1.60
retrieving revision 1.61
diff -C2 -d -r1.60 -r1.61
*** manager.py	16 Jun 2003 05:00:23 -0000	1.60
--- manager.py	17 Jun 2003 04:07:43 -0000	1.61
***************
*** 6,9 ****
--- 6,10 ----
  import errno
  import shutil
+ import traceback
  import win32api, win32con, win32ui
  
***************
*** 178,181 ****
--- 179,183 ----
  class BayesManager:
      def __init__(self, config_base="default", outlook=None, verbose=1):
+         self.reported_error_map = {}
          self.reported_startup_error = False
          self.config = self.options = None
***************
*** 259,266 ****
              # We have reported the error, but for the sake of the log, we
              # still want it logged there.
-             import traceback
              print "ERROR:", message
              traceback.print_exc()
  
      # Outlook used to give us thread grief - now we avoid Outlook
      # from threads, but this remains a worthwhile abstraction.
--- 261,278 ----
              # We have reported the error, but for the sake of the log, we
              # still want it logged there.
              print "ERROR:", message
              traceback.print_exc()
  
+     def ReportErrorOnce(self, msg, title = None, key = None):
+         if key is None: key = msg
+         # Always print the message and traceback.
+         print "ERROR:", msg
+         traceback.print_exc()
+         if key in self.reported_error_map:
+             print "(this error has already been reported - not displaying it again)"
+         else:
+             self.reported_error_map[key] = True
+             ReportError(msg, title)
+ 
      # Outlook used to give us thread grief - now we avoid Outlook
      # from threads, but this remains a worthwhile abstraction.
***************
*** 620,624 ****
          """
          email = msg.GetEmailPackageObject()
!         return self.bayes.spamprob(bayes_tokenize(email), evidence)
  
      def ShowManager(self):
--- 632,645 ----
          """
          email = msg.GetEmailPackageObject()
!         try:
!             return self.bayes.spamprob(bayes_tokenize(email), evidence)
!         except AssertionError:
!             # See bug 706520 assert fails in classifier
!             # For now, just tell the user.
!             msg = "It appears your SpamBayes training database is corrupt.\r\n\r\n" \
!                   "We are working on solving this, but unfortunately you\r\n" \
!                   "must re-train the system via the SpamBayes manager."
!             self.ReportErrorOnce(msg)
!             raise
  
      def ShowManager(self):





More information about the Spambayes-checkins mailing list