[Spambayes-checkins] spambayes dbmstorage.py,NONE,1.1 Options.py,1.78,1.79 storage.py,1.5,1.6 anydbm.py,1.4,NONE

Neale Pickett npickett at users.sourceforge.net
Tue Dec 3 20:11:23 2002


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

Modified Files:
	Options.py storage.py 
Added Files:
	dbmstorage.py 
Removed Files:
	anydbm.py 
Log Message:
* New option "dbm_type" which can be"best ", "db3hash", "dbhash",
  "gdbm", or "dumbdbm".  If it's "best", then the best available dbm
  implementation will be used.  Note that "best" on Windows excludes
  "dbhash".


--- NEW FILE: dbmstorage.py ---
"""Wrapper to open an appropriate dbm storage type."""

from Options import options
import sys

class error(Exception):
    pass

def open_db3hash(*args):
    """Open a bsddb3 hash."""
    import bsddb3
    return bsddb3.hashopen(*args)

def open_dbhash(*args):
    """Open a bsddb hash.  Don't use this on Windows."""
    import bsddb
    return bsddb.hashopen(*args)

def open_gdbm(*args):
    """Open a gdbm database."""
    import gdbm
    return gdbm.open(*args)

def open_dumbdbm(*args):
    """Open a dumbdbm database."""
    import dumbdbm
    return dumbdbm.open(*args)

def open_best(*args):
    if sys.platform == "win32":
        funcs = [open_db3hash, open_gdbm, open_dumbdbm]
    else:
        funcs = [open_db3hash, open_dbhash, open_gdbm, open_dumbdbm]
    for f in funcs:
        try:
            return f(*args)
        except ImportError:
            pass
    raise error("No dbm modules available!")

open_funcs = {
    "best": open_best,
    "db3hash": open_db3hash,
    "dbhash": open_dbhash,
    "gdbm": open_gdbm,
    "dumbdbm": open_dumbdbm,
    }

def open(*args):
    dbm_type = options.dbm_type.lower()
    f = open_funcs.get(dbm_type)
    if not f:
        raise error("Unknown dbm type in options file")
    return f(*args)

Index: Options.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/Options.py,v
retrieving revision 1.78
retrieving revision 1.79
diff -C2 -d -r1.78 -r1.79
*** Options.py	26 Nov 2002 00:43:51 -0000	1.78
--- Options.py	3 Dec 2002 20:11:13 -0000	1.79
***************
*** 373,376 ****
--- 373,380 ----
  [globals]
  verbose: False
+ # What DBM storage type should we use?  Must be best, db3hash, dbhash,
+ # gdbm, dumbdbm.  Windows folk should steer clear of dbhash.  Default is
+ # "best", which will pick the best DBM type available on your platform.
+ dbm_type: best
  """
  
***************
*** 461,464 ****
--- 465,469 ----
                  },
      'globals': {'verbose': boolean_cracker,
+                 'dbm_type': string_cracker,
                  },
  }

Index: storage.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/storage.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** storage.py	2 Dec 2002 06:02:03 -0000	1.5
--- storage.py	3 Dec 2002 20:11:18 -0000	1.6
***************
*** 52,55 ****
--- 52,56 ----
  import errno
  import shelve
+ import dbmstorage
  
  PICKLE_TYPE = 1
***************
*** 131,135 ****
              print 'Loading state from',self.db_name,'database'
  
!         self.db = shelve.DbfilenameShelf(self.db_name, self.mode)
  
          if self.db.has_key(self.statekey):
--- 132,137 ----
              print 'Loading state from',self.db_name,'database'
  
!         self.dbm = dbmstorage.open(self.db_name, self.mode)
!         self.db = shelve.Shelf(self.dbm)
  
          if self.db.has_key(self.statekey):

--- anydbm.py DELETED ---





More information about the Spambayes-checkins mailing list