[Zodb-checkins] CVS: ZODB3/BDBStorage - BDBFullStorage.py:1.63 BDBMinimalStorage.py:1.24 BerkeleyBase.py:1.38 __init__.py:1.15

Barry Warsaw barry@wooz.org
Fri, 3 Jan 2003 17:47:42 -0500


Update of /cvs-repository/ZODB3/BDBStorage
In directory cvs.zope.org:/tmp/cvs-serv29521/BDBStorage

Modified Files:
	BDBFullStorage.py BDBMinimalStorage.py BerkeleyBase.py 
	__init__.py 
Log Message:
Here's a principled way to determine whether the BDBStorages are
available or not, and also fixes to all the tests so they won't crap
out or complain if not.

To test whether these storages are avialable (including all package
dependencies), do:

import BDBStorage
if BDBStorage.is_available:
    # okay to use

Also, in BDBStorage/__init__.py do some cross-platform compatibility
for the bsddb module; in Python 2.3 we can just use the built-in
module, but in earlier Pythons we have to use bsddb3.  Now you can
just use "from BDBStorage import db" to get the proper db object.


=== ZODB3/BDBStorage/BDBFullStorage.py 1.62 => 1.63 ===
--- ZODB3/BDBStorage/BDBFullStorage.py:1.62	Wed Dec 18 17:14:15 2002
+++ ZODB3/BDBStorage/BDBFullStorage.py	Fri Jan  3 17:47:08 2003
@@ -21,22 +21,14 @@
 import cPickle as pickle
 from struct import pack, unpack
 
-# This uses the Dunn/Kuchling PyBSDDB v3 extension module available from
-# http://pybsddb.sourceforge.net.  It is compatible with release 3.4 of
-# PyBSDDB3.  The only recommended version of BerkeleyDB is 4.0.14.
-from bsddb3 import db
-
 from ZODB import POSException
 from ZODB.utils import p64, U64
 from ZODB.referencesf import referencesf
 from ZODB.TimeStamp import TimeStamp
 from ZODB.ConflictResolution import ConflictResolvingStorage, ResolvedSerial
 
-# BerkeleyBase.BerkeleyBase class provides some common functionality for both
-# the Full and Minimal implementations.  It in turn inherits from
-# ZODB.BaseStorage.BaseStorage which itself provides some common storage
-# functionality.
-from BerkeleyBase import BerkeleyBase, PackStop, _WorkThread
+from BDBStorage import db
+from BDBStorage.BerkeleyBase import BerkeleyBase, PackStop, _WorkThread
 
 ABORT = 'A'
 COMMIT = 'C'


=== ZODB3/BDBStorage/BDBMinimalStorage.py 1.23 => 1.24 ===
--- ZODB3/BDBStorage/BDBMinimalStorage.py:1.23	Wed Dec 18 17:14:15 2002
+++ ZODB3/BDBStorage/BDBMinimalStorage.py	Fri Jan  3 17:47:09 2003
@@ -17,19 +17,12 @@
 
 __version__ = '$Revision$'[-2:][0]
 
-# This uses the Dunn/Kuchling PyBSDDB v3 extension module available from
-# http://pybsddb.sourceforge.net.  It is compatible with release 3.4 of
-# PyBSDDB3.
-from bsddb3 import db
-
 from ZODB import POSException
 from ZODB.utils import p64, U64
 from ZODB.referencesf import referencesf
 from ZODB.ConflictResolution import ConflictResolvingStorage, ResolvedSerial
 
-# BerkeleyBase class provides some common functionality for BerkeleyDB-based
-# storages.  It in turn inherits from BaseStorage which itself provides some
-# common storage functionality.
+from BDBStorage import db
 from BerkeleyBase import BerkeleyBase, PackStop, _WorkThread
 
 ABORT = 'A'


=== ZODB3/BDBStorage/BerkeleyBase.py 1.37 => 1.38 ===
--- ZODB3/BDBStorage/BerkeleyBase.py:1.37	Mon Dec 16 10:15:38 2002
+++ ZODB3/BDBStorage/BerkeleyBase.py	Fri Jan  3 17:47:09 2003
@@ -25,7 +25,7 @@
 
 # This uses the Dunn/Kuchling PyBSDDB v3 extension module available from
 # http://pybsddb.sourceforge.net
-from bsddb3 import db
+from BDBStorage import db
 
 # BaseStorage provides primitives for lock acquisition and release, and a host
 # of other methods, some of which are overridden here, some of which are not.
@@ -242,13 +242,15 @@
     def _make_autopacker(self, event):
         raise NotImplementedError
 
-    def _setupDB(self, name, flags=0, dbtype=db.DB_BTREE, reclen=None):
+    def _setupDB(self, name, flags=0, dbtype=None, reclen=None):
         """Open an individual database with the given flags.
 
         flags are passed directly to the underlying DB.set_flags() call.
         Optional dbtype specifies the type of BerkeleyDB access method to
         use.  Optional reclen if not None gives the record length.
         """
+        if dbtype is None:
+            dbtype = db.DB_BTREE
         d = db.DB(self._env)
         if flags:
             d.set_flags(flags)


=== ZODB3/BDBStorage/__init__.py 1.14 => 1.15 ===
--- ZODB3/BDBStorage/__init__.py:1.14	Fri Dec  6 14:07:03 2002
+++ ZODB3/BDBStorage/__init__.py	Fri Jan  3 17:47:09 2003
@@ -12,4 +12,26 @@
 #
 ##############################################################################
 
-__version__ = '2.0beta3'
+# Python 2.2 and earlier requires the pybsddb distutils package, but for
+# Python 2.3, we really want to use the standard bsddb package.  Also, we want
+# to set a flag that other modules can easily tests to see if this stuff is
+# available or not.  Python 2.2 and 2.3 has bool() but not Python 2.1.
+#
+# Get the pybsddb extension module from pybsddb.sourceforge.net and the
+# BerkeleyDB libraries from www.sleepycat.com.
+
+try:
+    bool
+except NameError:
+    def bool(x):
+        return not not x
+
+try:
+    from bsddb import _db as db
+except ImportError:
+    try:
+        from bsddb3 import db
+    except ImportError:
+        db = None
+
+is_available = bool(db)