[Spambayes] Outlook addin using bsddb

Moore, Paul Paul.Moore at atosorigin.com
Fri Feb 7 11:13:43 EST 2003


From: Mark Hammond [mailto:mhammond at skippinet.com.au]
> Please let me know if there are any problems, or any suggestions.

Something seems odd. I deregistered and deleted my old setup totally, then
installed the new version. (Windows 2000, Python 2.2.2, Outlook 2000 with
Exchange server). When I ran manager to do a retrain, I got

>manager
Created new configuration file 'C:\Applications\Spambayes\Outlook2000\default_configuration.pck'
Loaded bayes database from 'C:\Applications\Spambayes\Outlook2000\default_bayes_database.db'
Failed to load bayes message database
Traceback (most recent call last):
  File "C:\Applications\Spambayes\Outlook2000\manager.py", line 260, in LoadBayes
    message_db = self.db_manager.open_mdb()
  File "C:\Applications\Spambayes\Outlook2000\manager.py", line 123, in open_mdb
    return bsddb.hashopen(self.mdb_filename)
error: (2, 'No such file or directory')
Either bayes database or message database is missing - creating new
Traceback (most recent call last):
  File "C:\Applications\Spambayes\Outlook2000\manager.py", line 462, in ?
    sys.exit(main(verbose))
  File "C:\Applications\Spambayes\Outlook2000\manager.py", line 437, in main
    mgr = GetManager(verbose=verbose_level)
  File "C:\Applications\Spambayes\Outlook2000\manager.py", line 426, in GetManager
    _mgr = BayesManager(outlook=outlook, verbose=verbose)
  File "C:\Applications\Spambayes\Outlook2000\manager.py", line 162, in __init__
    self.LoadBayes()
  File "C:\Applications\Spambayes\Outlook2000\manager.py", line 272, in LoadBayes
    self.InitNewBayes()
  File "C:\Applications\Spambayes\Outlook2000\manager.py", line 322, in InitNewBayes
    self.message_db = self.db_manager.new_mdb()
  File "C:\Applications\Spambayes\Outlook2000\manager.py", line 126, in new_mdb
    os.unlink(self.mdb_filename)
OSError: [Errno 2] No such file or directory: 'C:\\Applications\\Spambayes\\Outlook2000\\default_message_database.db'

The problem seems to be twofold - On the first hand, I'm getting OSError rather
than IOError from the delete. I fixed this by just suppressing any exception from
the delete (heavy handed, but what the heck?). Secondly, new_mdb() tests for the
bsddb module by doing "import bsddb" and catching an import error, rather than by
looking for the "db" symbol. This gives the wrong module on Python 2.2. I fixed this
by just removing the import - we imported the right module at the top of manager.py,
so that shouldn't be a problem anyway...

A patch is below...

Paul.

--- manager.py.orig	Wed Feb 05 03:09:42 2003
+++ manager.py	Fri Feb 07 10:53:04 2003
@@ -42,7 +42,7 @@
 except ImportError:
     # See if the explicit bsddb3 module exists.
     try:
-        import bsddb3
+        import bsddb3 as bsddb
         use_db = True
     except ImportError:
         use_db = False
@@ -116,16 +116,21 @@
         bayes.db.close()
         bayes.dbm.close()
     def open_mdb(self):
-        try:
-            import bsddb
-        except ImportError:
-            import bsddb3 as bsddb
+        # Why are we doing the import again here? We did it at the top
+        # (and what's more we did it correctly there, checking that bsddb
+        # exports "db" so we don't get the broken Python 2.2 version...
+#        try:
+#            import bsddb
+#        except ImportError:
+#            import bsddb3 as bsddb
         return bsddb.hashopen(self.mdb_filename)
     def new_mdb(self):
         try:
             os.unlink(self.mdb_filename)
-        except IOError, e:
-            if e.errno != errno.ENOENT: raise
+        except: # I get OSError - don't try to be too specific...
+            pass
+#        except IOError, e:
+#            if e.errno != errno.ENOENT: raise
         return self.open_mdb()
     def store_mdb(self, mdb):
         mdb.sync()



More information about the Spambayes mailing list