[Zodb-checkins] CVS: ZODB4/BDBStorage - BerkeleyBase.py:2.4

Barry Warsaw barry@wooz.org
Mon, 16 Dec 2002 16:01:27 -0500


Update of /cvs-repository/ZODB4/BDBStorage
In directory cvs.zope.org:/tmp/cvs-serv6218

Modified Files:
	BerkeleyBase.py 
Log Message:
Forward port some changes from zodb3, specifically:

- the read_only flag to BerkeleyConfig
- more logging
- added the cleanup() method and module level function


=== ZODB4/BDBStorage/BerkeleyBase.py 2.3 => 2.4 ===
--- ZODB4/BDBStorage/BerkeleyBase.py:2.3	Fri Dec  6 18:12:03 2002
+++ ZODB4/BDBStorage/BerkeleyBase.py	Mon Dec 16 16:01:27 2002
@@ -19,6 +19,7 @@
 import os
 import time
 import errno
+import shutil
 import threading
 from types import StringType
 
@@ -109,6 +110,11 @@
       3600, a classic pack will be performed once per day.  Set to zero to
       never automatically do classic packs.  For Minimal storage, this value
       is ignored -- all packs are classic packs.
+
+    Here are some other miscellaneous configuration variables:
+
+    - read_only causes ReadOnlyError's to be raised whenever any operation
+      (except pack!) might modify the underlying database.
     """
     interval = 120
     kbyte = 0
@@ -118,11 +124,12 @@
     frequency = 0
     packtime = 4 * 60 * 60
     classicpack = 0
+    read_only = 0
 
     def __repr__(self):
         d = self.__class__.__dict__.copy()
         d.update(self.__dict__)
-        return """<BerkeleyConfig:
+        return """<BerkeleyConfig (read_only=%(read_only)s):
 \tcheckpoint interval: %(interval)s seconds
 \tcheckpoint kbytes: %(kbyte)s
 \tcheckpoint minutes: %(min)s
@@ -181,6 +188,7 @@
         if env is None:
             env = name
 
+        self.log('Creating Berkeley environment')
         if env == '':
             raise TypeError, 'environment name is empty'
         elif isinstance(env, StringType):
@@ -192,7 +200,9 @@
         # This should be enough of a guarantee that sortKey() -- which via
         # BaseStorage uses the name -- is globally unique.
         envdir = os.path.abspath(self._env.db_home)
+        self.log('Berkeley environment dir: %s', envdir)
         BaseStorage.__init__(self, envdir)
+        self._is_read_only = config.read_only
 
         # Instantiate a pack lock
         self._packlock = threading.Lock()
@@ -206,6 +216,7 @@
         # Initialize the object id counter.
         self._init_oid()
         # Set up the checkpointing thread
+        self.log('setting up threads')
         if config.interval > 0:
             self._checkpointstop = event = threading.Event()
             self._checkpointer = _Checkpoint(self, event, config.interval)
@@ -219,6 +230,7 @@
             self._autopacker.start()
         else:
             self._autopacker = None
+        self.log('ready')
 
     def _make_autopacker(self, event):
         raise NotImplementedError
@@ -361,6 +373,7 @@
                 self._closed = True
         finally:
             self._lock_release()
+        self.log('finished closing the database')
 
     def _doclose(self):
         # Close all the tables
@@ -422,6 +435,10 @@
         finally:
             self._lock_release()
 
+    def cleanup(self):
+        """Remove the entire environment directory for this storage."""
+        cleanup(self.getName())
+
 
 
 def env_from_string(envname, config):
@@ -463,6 +480,16 @@
         lockfile.close()
         raise
     return env, lockfile
+
+
+
+def cleanup(envdir):
+    """Remove the entire environment directory for a Berkeley storage."""
+    try:
+        shutil.rmtree(envdir)
+    except OSError, e:
+        if e.errno <> errno.ENOENT:
+            raise