[Zope-CVS] SVN: zversioning/trunk/src/versioning/ added checkedout/checkedin bookkeeping

Grégoire Weber zope.org at incept.ch
Wed Oct 13 18:39:39 EDT 2004


Log message for revision 28139:
  added checkedout/checkedin bookkeeping

Changed:
  U   zversioning/trunk/src/versioning/README.txt
  U   zversioning/trunk/src/versioning/repository.py

-=-
Modified: zversioning/trunk/src/versioning/README.txt
===================================================================
--- zversioning/trunk/src/versioning/README.txt	2004-10-13 21:46:30 UTC (rev 28138)
+++ zversioning/trunk/src/versioning/README.txt	2004-10-13 22:39:38 UTC (rev 28139)
@@ -14,6 +14,7 @@
          |--> c
      
   >>> import zope.app.versioncontrol.interfaces
+  >>> from zope.app.annotation.interfaces import IAnnotatable
   >>> from zope.interface import directlyProvides
   >>> from zope.app.folder import Folder, rootFolder
   >>> from zope.app.tests.setup import setUpTraversal
@@ -81,8 +82,12 @@
 
   >>> ztapi.provideAdapter(interfaces.IHistoryStorage,
   ...                      interfaces.ICheckoutAware,
-  ...                      repository.DummyCheckoutAware)
+  ...                      repository.DefaultCheckoutAware)
 
+Our 'ICheckoutAware' adapter XXX
+
+  >>> directlyProvides(histories_storage, IAnnotatable)
+
 In this implementation the repository is simply a adapter to a 
 'IHistoryStorage'. This ensures that several versioning strategies 
 can be used with the same storage:
@@ -91,6 +96,7 @@
   ...                      interfaces.ICopyModifyMergeRepository,
   ...                      repository.CheckoutCheckinRepository)
 
+
 Now we adapt our history storage to the chosen repository strategy:
 
   >>> repo = interfaces.ICopyModifyMergeRepository(histories_storage)
@@ -130,14 +136,14 @@
 
 The example data must be now in checked in state:
 
-  #>>> repo.isCheckedOut(sample)
+  >>> repo.isCheckedOut(sample)
   False
   
 Let's have a look how 'checkout', 'checkin' and 'isCheckedOut' work 
 together:
 
-  #>>> #repo.checkout(sample)
-  #>>> #repo.isCheckedOut(sample)
+  >>> repo.checkout(sample)
+  >>> repo.isCheckedOut(sample)
   True
 
 The text shall be unchanged:

Modified: zversioning/trunk/src/versioning/repository.py
===================================================================
--- zversioning/trunk/src/versioning/repository.py	2004-10-13 21:46:30 UTC (rev 28138)
+++ zversioning/trunk/src/versioning/repository.py	2004-10-13 22:39:38 UTC (rev 28139)
@@ -19,45 +19,69 @@
 import zope.interface
 from zope.interface import Interface
 from zope.app import zapi
+from zope.app.annotation.interfaces import IAnnotations
 
 from versioning import interfaces
+from datetime import datetime
 
 # doc tests import
 import unittest
 from zope.testing import doctest
 from zope.app.tests import ztapi
+from persistent.dict import PersistentDict
 
 
-class DummyCheckoutAware(object):
+class DefaultCheckoutAware(object):
     """Just ignores checkin and checkout without generating exceptions.
     
     Use this for IHistoryStorage components beeing unable to store checkin
     and checkout information.
     
-    XXX Should 'DummyCheckoutAware' live here?
+    XXX Should 'DefaultCheckoutAware' live here?
+    
+    XXX CAUTION! If currently a checked out object gets deleted
+    the counter doesn't get decremented! We should
+    
+    Asserts IContained (the same object can not live in different
+    locations).
     """
     
     zope.interface.implements(interfaces.ICheckoutAware)
     __used_for__ = interfaces.IHistoryStorage
     
+    namespace_key = 'versioning.interfaces.ICheckoutAware'
+    
+    def getCheckedOutList(self):
+        return self.annotations.get(self.namespace_key)
+    
+    checkedOutDict = property(getCheckedOutList)
+    
     def __init__(self, histories):
         self.histories = histories
+        self.annotations = anno = IAnnotations(histories)
+        data = self.getCheckedOutList()
+        if data is None:
+            anno[self.namespace_key] = PersistentDict()
     
-    def markAsCheckedIn(self, obj):
-        """Fake checkin mark doing anything.
+    def markAsCheckedOut(self, obj):
+        """See versioning.interfaces.ICheckoutAware
         """
-        pass
+        ticket = self.histories.getTicket(obj)
+        self.checkedOutDict[ticket] = datetime.now()
         
-    def markAsCheckedOut(self, obj):
-        """Fake checkout mark doing anything.
+    def markAsCheckedIn(self, obj):
+        """See versioning.interfaces.ICheckoutAware
         """
-        pass
+        ticket = self.histories.getTicket(obj)
+        del self.checkedOutDict[ticket]
         
     def isCheckedOut(self, obj):
-        """Fake check
+        """See versioning.interfaces.ICheckoutAware
         """
-        return False
+        ticket = self.histories.getTicket(obj)
+        return self.checkedOutDict.has_key(ticket)
 
+
 class CopyModifyMergeRepository(object):
     """The repository handles simple linear histories.
     """



More information about the Zope-CVS mailing list