[Zodb-checkins] SVN: ZODB/branches/blob-merge-branch/src/ZODB/ Allow users to specify the temporary directory for uncommitted blob data via

Chris McDonough chrism at plope.com
Mon Feb 27 18:45:58 EST 2006


Log message for revision 65548:
  Allow users to specify the temporary directory for uncommitted blob data via
  the ZODB_BLOB_TEMPDIR environment variable.  We don't use a value from ZConfig
  because ZConfig use isn't mandated for standalone ZODB usage.
  

Changed:
  U   ZODB/branches/blob-merge-branch/src/ZODB/Blobs/Blob.py
  U   ZODB/branches/blob-merge-branch/src/ZODB/Blobs/tests/basic.txt
  U   ZODB/branches/blob-merge-branch/src/ZODB/utils.py

-=-
Modified: ZODB/branches/blob-merge-branch/src/ZODB/Blobs/Blob.py
===================================================================
--- ZODB/branches/blob-merge-branch/src/ZODB/Blobs/Blob.py	2006-02-27 23:31:40 UTC (rev 65547)
+++ ZODB/branches/blob-merge-branch/src/ZODB/Blobs/Blob.py	2006-02-27 23:45:57 UTC (rev 65548)
@@ -46,6 +46,8 @@
         results from this method call is unconditionally closed at
         transaction boundaries and so may not be used across
         transactions.  """
+
+        tempdir = os.environ.get('ZODB_BLOB_TEMPDIR', tempfile.gettempdir())
         
         result = None
 
@@ -64,7 +66,7 @@
                 raise BlobError, "Already opened for reading."
 
             if self._p_blob_uncommitted is None:
-                self._p_blob_uncommitted = utils.mktemp()
+                self._p_blob_uncommitted = utils.mktemp(dir=tempdir)
 
             self._p_blob_writers += 1
             result = BlobFile(self._p_blob_uncommitted, mode, self)
@@ -75,7 +77,7 @@
 
             if self._p_blob_uncommitted is None:
                 # Create a new working copy
-                self._p_blob_uncommitted = utils.mktemp()
+                self._p_blob_uncommitted = utils.mktemp(dir=tempdir)
                 uncommitted = BlobFile(self._p_blob_uncommitted, mode, self)
                 # NOTE: _p_blob data appears by virtue of Connection._setstate
                 utils.cp(file(self._p_blob_data), uncommitted)
@@ -103,7 +105,7 @@
                 dm = BlobDataManager(self, result)
 
                 # Blobs need to always participate in transactions.
-                if self._p_jar:
+                if self._p_jar is not None:
                     # If we are connected to a database, then we register
                     # with the transaction manager for that.
                     self._p_jar.transaction_manager.get().register(dm)

Modified: ZODB/branches/blob-merge-branch/src/ZODB/Blobs/tests/basic.txt
===================================================================
--- ZODB/branches/blob-merge-branch/src/ZODB/Blobs/tests/basic.txt	2006-02-27 23:31:40 UTC (rev 65547)
+++ ZODB/branches/blob-merge-branch/src/ZODB/Blobs/tests/basic.txt	2006-02-27 23:45:57 UTC (rev 65548)
@@ -145,4 +145,17 @@
     'rb'
     >>> f9.close()
 
+We can specify the tempdir that blobs use to keep uncommitted data by
+modifying the ZODB_BLOB_TEMPDIR environment variable:
 
+    >>> import os, tempfile, shutil
+    >>> tempdir = tempfile.mkdtemp()
+    >>> os.environ['ZODB_BLOB_TEMPDIR'] = tempdir
+    >>> myblob = Blob()
+    >>> len(os.listdir(tempdir))
+    0
+    >>> f = myblob.open('w')
+    >>> len(os.listdir(tempdir))
+    1
+    >>> shutil.rmtree(tempdir)
+    >>> del os.environ['ZODB_BLOB_TEMPDIR']

Modified: ZODB/branches/blob-merge-branch/src/ZODB/utils.py
===================================================================
--- ZODB/branches/blob-merge-branch/src/ZODB/utils.py	2006-02-27 23:31:40 UTC (rev 65547)
+++ ZODB/branches/blob-merge-branch/src/ZODB/utils.py	2006-02-27 23:45:57 UTC (rev 65548)
@@ -289,9 +289,9 @@
         return self.data.data.values()
 
 
-def mktemp():
+def mktemp(dir=None):
     """Create a temp file, known by name, in a semi-secure manner."""
-    handle, filename = mkstemp()
+    handle, filename = mkstemp(dir=dir)
     os.close(handle)
     return filename
 



More information about the Zodb-checkins mailing list