[Zope-CVS] SVN: zversioning/trunk/src/versioning/ minor changes

Uwe Oestermeier uwe_oestermeier at iwm-kmrc.de
Thu Oct 14 06:39:50 EDT 2004


Log message for revision 28154:
  minor changes

Changed:
  U   zversioning/trunk/src/versioning/MOTIVATION.txt
  U   zversioning/trunk/src/versioning/README.txt
  U   zversioning/trunk/src/versioning/interfaces.py
  U   zversioning/trunk/src/versioning/policies.py
  U   zversioning/trunk/src/versioning/storage.py
  U   zversioning/trunk/src/versioning/tests/test_versioncontrol.py

-=-
Modified: zversioning/trunk/src/versioning/MOTIVATION.txt
===================================================================
--- zversioning/trunk/src/versioning/MOTIVATION.txt	2004-10-14 10:35:43 UTC (rev 28153)
+++ zversioning/trunk/src/versioning/MOTIVATION.txt	2004-10-14 10:39:48 UTC (rev 28154)
@@ -139,14 +139,12 @@
 the object in the histories storage (this will be called later on by
 IVersionControl.applyVersionControl) :
 
-    >>> histories.register(sample)
-    '\x00\x00\x00\x00\x00\x00\x00\x01'
-    >>> histories.register(a)
-    '\x00\x00\x00\x00\x00\x00\x00\x03'
-    >>> histories.register(b)
-    '\x00\x00\x00\x00\x00\x00\x00\x04'
-    >>> histories.register(c)
-    '\x00\x00\x00\x00\x00\x00\x00\x06'
+    >>> for x in [sample, a, b, c] :
+    ...     histories.register(x) is not None
+    True
+    True
+    True
+    True
     >>> util.commit()
     >>> len(histories.values())
     4
@@ -168,8 +166,7 @@
     '001'
     >>> saveAsVersion(c, histories)
     '001'
-    >>> version = histories[a._p_oid]['001']
-    >>> version.text
+    >>> histories.getVersion(a, '001').text
     'First text version of a'
     
 Add some additional content versions :
@@ -178,7 +175,7 @@
     >>> c.text = "Second text version of c"
     >>> saveAsVersion(a, histories)
     '002'
-    >>> version = histories[a._p_oid]['002']
+    >>> version = histories.getVersion(a, '002')
     >>> version.text
     'Second text version of a'
     >>> saveAsVersion(c, histories)

Modified: zversioning/trunk/src/versioning/README.txt
===================================================================
--- zversioning/trunk/src/versioning/README.txt	2004-10-14 10:35:43 UTC (rev 28153)
+++ zversioning/trunk/src/versioning/README.txt	2004-10-14 10:39:48 UTC (rev 28154)
@@ -34,6 +34,32 @@
         of the original with a saved copy is sufficient, sometimes references
         to the original objects must remain intact. These different variants
         are also defined in policies.py
+        
+Within this overall pattern the following components are pluggable :
+
+    1.  IHistoriesStorage. This is the main persistent storage that is used
+        to ensure that the changing versions can be accessed later on. 
+        We use the abstract term ticket to describe the fact that different
+        storages use quite different reference schemes, e.g. global unique ids,
+        paths and revision numbers, python pointers, the _p_oid in the ZODB etc.
+        to retrieve and access parts of the history of an object.
+        
+    2.  IVersionableAspects. 
+    
+   
+    3.  INameChooser.
+    
+    
+    4.  ICheckoutAware.
+    
+    XXX
+    
+    5.  IMergeStrategies 
+    
+    
+    
+        
+    
          
 
 General Setup Stuff
@@ -91,11 +117,24 @@
 
   >>> from zope.app.tests import ztapi
   >>> from zope.app import zapi
+  >>> import persistent
   >>> from versioning import interfaces, repository, policies, storage
 
+  
+Configure a unique id utility. In this case we use the one provided by
+zope and enable this utility to adapt all persistent object into
+unique references:     
+
+  >>> ztapi.provideUtility(zope.app.uniqueid.interfaces.IUniqueIdUtility,
+  ...                           zope.app.uniqueid.UniqueIdUtility())
+  >>> ztapi.provideAdapter(persistent.interfaces.IPersistent, 
+  ...                           zope.app.uniqueid.interfaces.IReference,
+  ...                           zope.app.uniqueid.ReferenceToPersistent)    
+
 Configure the 'IHistoryStorage' utility being responsible for the storage 
 of the objects histories:
 
+
   >>> ztapi.provideUtility(interfaces.IHistoryStorage,
   ...                      storage.SimpleHistoryStorage())
   

Modified: zversioning/trunk/src/versioning/interfaces.py
===================================================================
--- zversioning/trunk/src/versioning/interfaces.py	2004-10-14 10:35:43 UTC (rev 28153)
+++ zversioning/trunk/src/versioning/interfaces.py	2004-10-14 10:39:48 UTC (rev 28154)
@@ -39,7 +39,9 @@
 from zope.interface import Interface, Attribute
 
 from zope.app.container.interfaces import INameChooser
+from zope.app.uniqueid.interfaces import IReference
 
+
 class RepositoryError(Exception):
     pass
 
@@ -316,7 +318,7 @@
         """Returns the whole metadata history of the objects aspects.
         """
 
-class IVersionable(persistent.interfaces.IPersistent):
+class IVersionable(IReference):
     """Version control is allowed for objects that provide this."""
 
    

Modified: zversioning/trunk/src/versioning/policies.py
===================================================================
--- zversioning/trunk/src/versioning/policies.py	2004-10-14 10:35:43 UTC (rev 28153)
+++ zversioning/trunk/src/versioning/policies.py	2004-10-14 10:39:48 UTC (rev 28154)
@@ -28,7 +28,8 @@
         and the copied object of type IContained.
         
         It further assumes that we only version objects
-        that have been persistently stored (and thus have a _p_oid)
+        that have been persistently stored and thus are
+        able to be adapted to zope.app.uniqueid.IReference.
         
     """
     

Modified: zversioning/trunk/src/versioning/storage.py
===================================================================
--- zversioning/trunk/src/versioning/storage.py	2004-10-14 10:35:43 UTC (rev 28153)
+++ zversioning/trunk/src/versioning/storage.py	2004-10-14 10:39:48 UTC (rev 28154)
@@ -17,12 +17,15 @@
 
 from zope.interface import implements
 from persistent.dict import PersistentDict
+
+from zope.app import zapi
 from zope.app.folder import Folder
 from zope.app.annotation.interfaces import IAnnotatable
 from zope.app.exception.interfaces import UserError
 from zope.app.copypastemove.interfaces import IObjectCopier 
 from zope.app.container.interfaces import INameChooser
 from zope.app.annotation.interfaces import IAnnotations
+from zope.app.uniqueid.interfaces import IUniqueIdUtility
 
 from versioning.interfaces import IVersionHistory
 from versioning.interfaces import IHistoryStorage
@@ -61,7 +64,7 @@
         Implements the probably most simple way of version control in Zope3.
         It uses the following existing Zope mechanisms :
             
-           the _p_oid as an identification ticket for objects and their versions
+           a unique id as an identification ticket for objects and their versions
            a Folder as a container for histories were each History is itself a Folder
            
         >>> from versioning.policies import VersionableAspectsAdapter
@@ -73,6 +76,12 @@
     """
     
     implements(IHistoryStorage, IAnnotatable)
+    
+    
+    def __init__(self) :
+        super(SimpleHistoryStorage, self).__init__()
+        self.unique_ids = zapi.getUtility(IUniqueIdUtility)
+        
  
     def register(self, obj):
         """ Register an obj for version control.
@@ -83,12 +92,11 @@
         return ticket
   
     def getTicket(self, obj) :
-        """ Returns the persistent oid of an object as
+        """ Returns a unique id of an object as
             a ticket that remains stable across time.
         """
-        if obj._p_oid is None :
-            raise RuntimeError("cannot version uncommited objects")
-        return str(obj._p_oid)
+        return str(self.unique_ids.register(obj))
+    
   
     def getVersion(self, obj, selector) :
         """ Returns the version of an object that is specified by selector. """

Modified: zversioning/trunk/src/versioning/tests/test_versioncontrol.py
===================================================================
--- zversioning/trunk/src/versioning/tests/test_versioncontrol.py	2004-10-14 10:35:43 UTC (rev 28153)
+++ zversioning/trunk/src/versioning/tests/test_versioncontrol.py	2004-10-14 10:39:48 UTC (rev 28154)
@@ -23,7 +23,9 @@
 from zope.app.container.sample import SampleContainer
 from zope.app.tests import placelesssetup
 from zope.app.tests import ztapi
+from persistent.interfaces import IPersistent
 
+
 # import basic test infrastructure from existing version control implementation
 from zope.app.versioncontrol.tests import setUp, tearDown, name
 
@@ -61,6 +63,11 @@
 from zope.app.file.file import File
 from zope.app.folder.folder import Folder
 
+from zope.app.uniqueid.interfaces import IUniqueIdUtility
+from zope.app.uniqueid.interfaces import IReference
+from zope.app.uniqueid import UniqueIdUtility
+from zope.app.uniqueid import ReferenceToPersistent
+ 
 from zope.app.copypastemove.interfaces import IObjectCopier
 from zope.app.copypastemove import ObjectCopier
 
@@ -103,6 +110,7 @@
  
     classImplements(File, IAttributeAnnotatable)
     classImplements(Folder, IAttributeAnnotatable)
+    
 
     ztapi.provideAdapter(IAttributeAnnotatable, IAnnotations, AttributeAnnotations)
     ztapi.provideAdapter(None, ITraverser, Traverser)
@@ -114,6 +122,8 @@
     # for copy and moves
     ztapi.provideAdapter(None, IObjectCopier, ObjectCopier)
     ztapi.provideAdapter(IWriteContainer, INameChooser, NameChooser)
+    ztapi.provideUtility(IUniqueIdUtility, UniqueIdUtility())
+    ztapi.provideAdapter(IPersistent, IReference, ReferenceToPersistent)    
 
 
 def setUpReadMe(test) :



More information about the Zope-CVS mailing list