[Zope-CVS] CVS: Products/AdaptableStorage - patches.py:1.1 Zope2FS.py:1.2 __init__.py:1.5

Shane Hathaway shane@zope.com
Tue, 3 Dec 2002 18:11:23 -0500


Update of /cvs-repository/Products/AdaptableStorage
In directory cvs.zope.org:/tmp/cvs-serv22143

Modified Files:
	Zope2FS.py __init__.py 
Added Files:
	patches.py 
Log Message:
Running AdaptableStorage with the latest Zope revealed some flaws.
Fixed them all.

- Consistent ordering of transaction participants now makes it impossible to
  add a jar to the transaction after the commit() method has begun.
  AdaptableStorage (and perhaps other projects like ZPatterns) relied on
  the ability to add a jar after commit has started.  This could lead to
  a deadlock.  Reworked ASStorage, FSConnection, and the tests to deal with
  this.

- Serials are now required to be hashable.  This makes serials, used to
  prevent conflicts, simpler and more robust.

- DBTab needs some kind of class it can call directly, so I added
  the small subclasses FSStorage and FSDatabase to Zope2FS.

- Restored the PersistentExtra patch.

- The directory items gateway wants to write data about its children, but
  sometimes its children aren't being written at the same time.  Added
  a "conditional" optional flag to FSConnection.writeSection(), allowing
  data to be written only if other data gets written.


=== Added File Products/AdaptableStorage/patches.py ===
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Patches necessary to make AdaptableStorage work in Zope.

$Id: patches.py,v 1.1 2002/12/03 23:10:52 shane Exp $
"""

from DateTime import DateTime


def applyPersistentPatch():
    # We need to do this until mtimes are made available.
    # It makes mtime always look like the current time.
    def bobobase_modification_time(self):
        jar=self._p_jar
        oid=self._p_oid
        if jar is None or oid is None or getattr(jar, 'no_mtime_available', 0):
            return DateTime()

        try:
            t=self._p_mtime
            if t is None: return DateTime()
        except: t=0
        return DateTime(t)

    from Persistence import Persistent
    import App.PersistentExtra  # Let Zope do its own patching, then override
    Persistent.__dict__[
        'bobobase_modification_time'] = bobobase_modification_time


def applyPatches():
    applyPersistentPatch()



=== Products/AdaptableStorage/Zope2FS.py 1.1 => 1.2 ===
--- Products/AdaptableStorage/Zope2FS.py:1.1	Wed Nov 27 13:37:05 2002
+++ Products/AdaptableStorage/Zope2FS.py	Tue Dec  3 18:10:52 2002
@@ -25,7 +25,6 @@
 from gateway_fs.public import FSConnection, FSDirectoryItems, FSAutoId
 
 
-
 def createDomainMapper(basepath, volatile=1):
     fs_conn = FSConnection(basepath)
 
@@ -39,6 +38,9 @@
     s = ObjectSerializer(class_info)
     s.addAspect('items', FolderItems())
     s.addAspect('id', IdAttribute())
+    s.addAspect('owner', IgnoredAttribute('_owner'))
+    s.addAspect('local_roles', IgnoredAttribute('__ac_local_roles__'))
+    s.addAspect('title', IgnoredAttribute('title'))
     s.addAspect('roll_call', RollCall())
     object_serializers['OFS/Folder'] = s
 
@@ -46,6 +48,9 @@
     class_info = (('OFS.Application', 'Application'), None)
     s = ObjectSerializer(class_info)
     s.addAspect('items', FolderItems())
+    s.addAspect('owner', IgnoredAttribute('_owner'))
+    s.addAspect('local_roles', IgnoredAttribute('__ac_local_roles__'))
+    s.addAspect('title', IgnoredAttribute('title'))
     s.addAspect('roll_call', RollCall())
     object_serializers['OFS/Application'] = s
 
@@ -91,5 +96,23 @@
                               dm, volatile)
         dm.addMapper(name, mapper)
 
-    return dm
+    return dm, fs_conn
+
+
+# For use in dbtab.conf:
+
+from zodb.public import ASConnection, ASStorage, ASDB, StaticResource
+
+
+class FSStorage (ASStorage):
+
+    def __init__(self, basepath, volatile=0, **kw):
+        dm, fs_conn = createDomainMapper(basepath, int(volatile))
+        res = StaticResource(dm)
+        ASStorage.__init__(self, res, [fs_conn], **kw)
+
+
+class FSDatabase (ASDB):
 
+    def __init__(self, storage, **kw):
+        ASDB.__init__(self, storage, storage._domain_resource, **kw)


=== Products/AdaptableStorage/__init__.py 1.4 => 1.5 ===
--- Products/AdaptableStorage/__init__.py:1.4	Wed Nov 27 13:37:05 2002
+++ Products/AdaptableStorage/__init__.py	Tue Dec  3 18:10:52 2002
@@ -19,3 +19,10 @@
 
 $Id$
 """
+
+import sys
+
+if sys.modules.has_key('Zope'):
+    from patches import applyPatches
+    applyPatches()
+