Commit faf72340 authored by Barry Warsaw's avatar Barry Warsaw

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.
parent 4ac9aff7
......@@ -15,28 +15,20 @@
"""Berkeley storage with full undo and versioning support.
"""
__version__ = '$Revision: 1.62 $'.split()[-2:][0]
__version__ = '$Revision: 1.63 $'.split()[-2:][0]
import time
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'
......
......@@ -15,21 +15,14 @@
"""Berkeley storage without undo or versioning.
"""
__version__ = '$Revision: 1.23 $'[-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
__version__ = '$Revision: 1.24 $'[-2:][0]
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'
......
......@@ -14,7 +14,7 @@
"""Base class for BerkeleyStorage implementations.
"""
__version__ = '$Revision: 1.37 $'.split()[-2:][0]
__version__ = '$Revision: 1.38 $'.split()[-2:][0]
import os
import time
......@@ -25,7 +25,7 @@ from types import StringType
# 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 @@ class BerkeleyBase(BaseStorage):
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)
......
......@@ -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)
......@@ -21,9 +21,16 @@ from ZODB.referencesf import referencesf
from ZODB.tests.MinPO import MinPO
from Persistence import Persistent
from BDBStorage.BDBFullStorage import BDBFullStorage
from BDBStorage.BDBMinimalStorage import BDBMinimalStorage
from BDBStorage.BerkeleyBase import BerkeleyConfig
import BDBStorage
if BDBStorage.is_available:
from BDBStorage.BDBFullStorage import BDBFullStorage
from BDBStorage.BDBMinimalStorage import BDBMinimalStorage
from BDBStorage.BerkeleyBase import BerkeleyConfig
else:
# Sigh
class FakeBaseClass: pass
BDBFullStorage = BDBMinimalStorage = FakeBaseClass
from BDBStorage.tests.BerkeleyTestBase import BerkeleyTestBase
ZERO = '\0'*8
......@@ -254,9 +261,10 @@ class TestMinimalPack(TestAutopackBase):
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestAutopack, 'check'))
suite.addTest(unittest.makeSuite(TestAutomaticClassicPack, 'check'))
suite.addTest(unittest.makeSuite(TestMinimalPack, 'check'))
if BDBStorage.is_available:
suite.addTest(unittest.makeSuite(TestAutopack, 'check'))
suite.addTest(unittest.makeSuite(TestAutomaticClassicPack, 'check'))
suite.addTest(unittest.makeSuite(TestMinimalPack, 'check'))
return suite
......
......@@ -18,9 +18,12 @@ import os
import time
import unittest
from BDBStorage.BerkeleyBase import BerkeleyConfig
import BDBStorage
if BDBStorage.is_available:
from BDBStorage.BerkeleyBase import BerkeleyConfig
from BDBStorage.BDBFullStorage import BDBFullStorage
from BDBStorage.tests import BerkeleyTestBase
from BDBStorage.BDBFullStorage import BDBFullStorage
......@@ -106,11 +109,12 @@ class OpenRecoveryTest(BerkeleyTestBase.FullTestBase):
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(MinimalCreateTest, 'check'))
suite.addTest(unittest.makeSuite(FullCreateTest, 'check'))
suite.addTest(unittest.makeSuite(FullOpenExistingTest, 'check'))
suite.addTest(unittest.makeSuite(FullOpenCloseTest, 'check'))
suite.addTest(unittest.makeSuite(OpenRecoveryTest, 'check'))
if BDBStorage.is_available:
suite.addTest(unittest.makeSuite(MinimalCreateTest, 'check'))
suite.addTest(unittest.makeSuite(FullCreateTest, 'check'))
suite.addTest(unittest.makeSuite(FullOpenExistingTest, 'check'))
suite.addTest(unittest.makeSuite(FullOpenCloseTest, 'check'))
suite.addTest(unittest.makeSuite(OpenRecoveryTest, 'check'))
return suite
......
......@@ -15,13 +15,11 @@
# Unit tests for basic storage functionality
import unittest
# Import this here and now so that import failures properly cause the test
# suite to ignore these tests.
import bsddb3
from ZODB import POSException
import BerkeleyTestBase
import BDBStorage
from BDBStorage.tests import BerkeleyTestBase
from ZODB.tests.BasicStorage import BasicStorage
from ZODB.tests.RevisionStorage import RevisionStorage
from ZODB.tests.VersionStorage import VersionStorage
......@@ -79,9 +77,10 @@ class FullRecoveryTest(BerkeleyTestBase.FullTestBase,
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(FullTest, 'check'))
suite.addTest(unittest.makeSuite(FullRecoveryTest, 'check'))
suite.addTest(unittest.makeSuite(MinimalTest, 'check'))
if BDBStorage.is_available:
suite.addTest(unittest.makeSuite(FullTest, 'check'))
suite.addTest(unittest.makeSuite(FullRecoveryTest, 'check'))
suite.addTest(unittest.makeSuite(MinimalTest, 'check'))
return suite
......
......@@ -16,7 +16,8 @@
import unittest
from ZODBTestBase import ZODBTestBase
import BDBStorage
from BDBStorage.tests.ZODBTestBase import ZODBTestBase
from Persistence import PersistentMapping
......@@ -46,8 +47,9 @@ class MinimalNewInsertsTest(ZODBTestBase, InsertMixin):
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(MinimalNewInsertsTest, 'check'))
suite.addTest(unittest.makeSuite(FullNewInsertsTest, 'check'))
if BDBStorage.is_available:
suite.addTest(unittest.makeSuite(MinimalNewInsertsTest, 'check'))
suite.addTest(unittest.makeSuite(FullNewInsertsTest, 'check'))
return suite
......
......@@ -19,10 +19,18 @@ import unittest
from ZODB.utils import U64
from ZODB.tests.MinPO import MinPO
from ZODB.tests.StorageTestBase import zodb_unpickle
from BDBStorage.BDBMinimalStorage import BDBMinimalStorage
from BDBStorage.BDBFullStorage import BDBFullStorage
from BDBStorage.tests.BerkeleyTestBase import BerkeleyTestBase
import BDBStorage
if BDBStorage.is_available:
from BDBStorage.BDBMinimalStorage import BDBMinimalStorage
from BDBStorage.BDBFullStorage import BDBFullStorage
else:
# Sigh
class FakeBaseClass: pass
BDBFullStorage = BDBMinimalStorage = FakeBaseClass
from BDBStorage.tests.ZODBTestBase import ZODBTestBase
from BDBStorage.tests.BerkeleyTestBase import BerkeleyTestBase
from Persistence import Persistent
......@@ -218,9 +226,10 @@ class WhiteboxHighLevelFull(ZODBTestBase):
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(WhiteboxLowLevelMinimal, 'check'))
suite.addTest(unittest.makeSuite(WhiteboxHighLevelMinimal, 'check'))
suite.addTest(unittest.makeSuite(WhiteboxHighLevelFull, 'check'))
if BDBStorage.is_available:
suite.addTest(unittest.makeSuite(WhiteboxLowLevelMinimal, 'check'))
suite.addTest(unittest.makeSuite(WhiteboxHighLevelMinimal, 'check'))
suite.addTest(unittest.makeSuite(WhiteboxHighLevelFull, 'check'))
return suite
......
......@@ -18,11 +18,9 @@
import time
import unittest
# Import this here and now so that import failures properly cause the test
# suite to ignore these tests.
import bsddb3
from ZODBTestBase import ZODBTestBase
import BDBStorage
from BDBStorage.tests.ZODBTestBase import ZODBTestBase
from Persistence import PersistentMapping
......@@ -81,8 +79,9 @@ class FullCommitAndRead(ZODBTestBase, CommitAndRead):
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(MinimalCommitAndRead, 'check'))
suite.addTest(unittest.makeSuite(FullCommitAndRead, 'check'))
if BDBStorage.is_available:
suite.addTest(unittest.makeSuite(MinimalCommitAndRead, 'check'))
suite.addTest(unittest.makeSuite(FullCommitAndRead, 'check'))
return suite
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment