[Zodb-checkins] SVN: ZODB/branches/patricks-blob-dir-perm/src/ZODB/ Add conversion to the FileStorage config handler, add config tests.

Patrick Strawderman cvs-admin at zope.org
Wed Oct 17 15:35:07 UTC 2012


Log message for revision 128027:
  Add conversion to the FileStorage config handler, add config tests.
  

Changed:
  U   ZODB/branches/patricks-blob-dir-perm/src/ZODB/config.py
  U   ZODB/branches/patricks-blob-dir-perm/src/ZODB/tests/testConfig.py

-=-
Modified: ZODB/branches/patricks-blob-dir-perm/src/ZODB/config.py
===================================================================
--- ZODB/branches/patricks-blob-dir-perm/src/ZODB/config.py	2012-10-17 15:23:05 UTC (rev 128026)
+++ ZODB/branches/patricks-blob-dir-perm/src/ZODB/config.py	2012-10-17 15:35:03 UTC (rev 128027)
@@ -169,11 +169,20 @@
                 options['packer'] = getattr(m, name)
 
         for name in ('blob_dir', 'create', 'read_only', 'quota', 'pack_gc',
-                     'pack_keep_old', 'blob_dir_permissions'):
+                     'pack_keep_old',):
             v = getattr(config, name, self)
             if v is not self:
                 options[name] = v
-
+        # We perform the conversion of the blob dir permissions here,
+        # as ZConfig currently does not provide a sufficient data type
+        permissions = getattr(config, "blob_dir_permissions", None)
+        if permissions is not None:
+            try:
+               options["blob_dir_permissions"] = int(permissions, 8)
+            except ValueError:
+                raise ValueError(
+                    "Expected an octal for blob_dir_permissions option, "
+                    "got: %r" % (permissions,))
         return FileStorage(config.path, **options)
 
 class BlobStorage(BaseConfig):

Modified: ZODB/branches/patricks-blob-dir-perm/src/ZODB/tests/testConfig.py
===================================================================
--- ZODB/branches/patricks-blob-dir-perm/src/ZODB/tests/testConfig.py	2012-10-17 15:23:05 UTC (rev 128026)
+++ ZODB/branches/patricks-blob-dir-perm/src/ZODB/tests/testConfig.py	2012-10-17 15:35:03 UTC (rev 128027)
@@ -114,7 +114,7 @@
     False
     """
 
-def multi_atabases():
+def multi_databases():
     r"""If there are multiple codb sections -> multidatabase
 
     >>> db = ZODB.config.databaseFromString('''
@@ -183,6 +183,58 @@
 
     """
 
+def test_blob_dir_permissions():
+    """
+
+    Blob directory permissions can be specified with the
+    `blob-dir-permissions` option.
+
+    >>> import os, tempfile
+    >>> fd, path = tempfile.mkstemp()
+    >>> os.close(fd)
+    >>> blob_dir = tempfile.mkdtemp()
+    >>> db = ZODB.config.databaseFromString('''
+    ... <zodb>
+    ...     <filestorage>
+    ...        path %s
+    ...        blob-dir %s
+    ...        blob-dir-permissions 0770
+    ...        create true
+    ...     </filestorage>
+    ... </zodb>
+    ... ''' % (path, blob_dir))
+
+    >>> oct(os.stat(db.storage.blob_dir).st_mode)
+    '040770'
+
+    The `blob-dir-permissions` option expects an octal.
+
+    >>> ZODB.config.databaseFromString('''
+    ... <zodb>
+    ...     <filestorage>
+    ...         path %s
+    ...         blob-dir %s
+    ...         blob-dir-permissions 888
+    ...     </filestorage>
+    ... </zodb>''' % (path, blob_dir,))
+    Traceback (most recent call last):
+    ...
+    ValueError: Expected an octal for blob_dir_permissions option, got: '888'
+
+    >>> ZODB.config.databaseFromString('''
+    ... <zodb>
+    ...     <filestorage>
+    ...         path %s
+    ...         blob-dir %s
+    ...         blob-dir-permissions xxxx
+    ...     </filestorage>
+    ... </zodb>''' % (path, blob_dir,))
+    Traceback (most recent call last):
+    ...
+    ValueError: Expected an octal for blob_dir_permissions option, got: 'xxxx'
+
+    """
+
 def test_suite():
     suite = unittest.TestSuite()
     suite.addTest(doctest.DocTestSuite(



More information about the Zodb-checkins mailing list