[Zope-CVS] CVS: Packages/VersionControl - VersionControl.py:1.4 VersionSupport.py:1.4

Brian Lloyd brian@digicool.com
Fri, 19 Oct 2001 16:49:22 -0400


Update of /cvs-repository/Packages/VersionControl
In directory cvs.zope.org:/tmp/cvs-serv31181

Modified Files:
	VersionControl.py VersionSupport.py 
Log Message:
cleanups

=== Packages/VersionControl/VersionControl.py 1.3 => 1.4 ===
 import string
 
+
 class VersionControl(ExtensionClass.Base):
     """ """
+    security = AccessControl.ClassSecurityInfo()
 
     def __init__(self, context):
         self.context = context
 
+    security.declarePublic('isUnderVersionControl')
+    def isUnderVersionControl(self, object):
+        """Return true if the given object is under version control."""
+        return hasattr(object, '_vc_info')
+
+    security.declarePublic('isResourceUpToDate')
+    def isResourceUpToDate(self, object):
+        """Return true if a resource reflects the latest version."""
+        # TODO - fix this. checking for last id won't work when we
+        # have versions on branches.
+        history = self.getVersionHistoryFor(object)
+        info = self.getVersionInfo(object)
+        now = info.getSourceVersionId()
+        return history.lastVersionId() == now
+
+    security.declarePublic('getVersionInfo')
+    def getVersionInfo(self, object):
+        """Return version control information associated with an object,
+           or None if the given object is not under version control."""
+        info = getattr(object, '_vc_info', None)
+        if info is None:
+            raise VersionControlError(
+                'This object is not under version control.'
+                )
+        return info
+
+    security.declarePrivate('setVersionInfo')
+    def setVersionInfo(self, object, info):
+        """Set the version control information associated with an object."""
+        object._vc_info = info
+
+    security.declarePublic('getRepositoryIds')
     def getRepositoryIds(self):
-        """Return a list of valid repository ids."""
-        # XXX - fix this
+        """Return a sequence of valid repository ids."""
+        # TODO- fix this (maybe). Do we really want the use the old
+        # acquisition model, or something deeper? You really dont
+        # want movement of the repositories to break everything...
         context = self.context
         base = Acquisition.aq_base(context)
         try:
@@ -24,24 +60,31 @@
             result.append(item.getId())
         return result
 
-    def getRepository(self, id):
-        """Return the named repository object."""
-        return getattr(self.context, id)
-
-    def versionControl(self, object, repository_id, description, use_auto=0):
-        """Place an object under version control."""
+    security.declarePrivate('getRepository')
+    def getRepository(self, repository_id):
+        """Return the repository object named by the given repository id."""
+        # TODO: fix this too, per above.
+        return getattr(self.context, repository_id)
+
+    security.declarePrivate('applyVersionControl')
+    def applyVersionControl(self, object, repository_id, description,
+                            use_auto=0):
+        """Place the given resource under version control."""
 
-        # First, make sure object is not already under version control.
+        # Make sure object is not already under version control.
         if self.isUnderVersionControl(object):
-            raise 
+            raise VersionControlError(
+                'This object is already under version control.'
+                )
 
-        # Check for semantic conflicts
-        # xxx
+        # TODO: check for semantic conflicts here
 
-        # Get the repository we'll be using and create a new version history.
+        # Get the repository and create a new version history.
         repository = self.getRepository(repository_id)
         history = repository.createVersionHistory(object)
         history.setDescription(description)
+
+        # Create an initial version of the given object.
         version = history.createVersion(object)
         version.addMessageEntry('checkin',
                                 self._findUserName(),
@@ -49,8 +92,7 @@
                                 'Initial checkin.'
                                 )
 
-
-        # Set versioning information on the version-controlled object.
+        # Set versioning info on the new versioned resource.
         vinfo = VersionInfo(object)
         vinfo.setRepositoryId(repository.getId())
         vinfo.setVersionHistoryId(history.getId())
@@ -59,32 +101,15 @@
         self.setVersionInfo(object, vinfo)
         return object
 
-    def isUnderVersionControl(self, object):
-        """Return true if object is under version control."""
-        return self.getVersionInfo(object) is not None
-
-    def getVersionInfo(self, object):
-        """Return version control information associated with object."""
-        return getattr(object, '_vc_info', None)
-
-    def setVersionInfo(self, object, info):
-        """Set the version control information associated with object."""
-        object._vc_info = info
+    def checkoutResource(self, object, activity='mainline'):
+        """Put the given resource into the checked-out state."""
 
-    def checkOut(self, object, activity='mainline'):
-        """Checkout"""
-
-        # First, make sure object is not already under version control.
-        if not self.isUnderVersionControl(object):
-            raise 
-
-        # Check for semantic conflicts
-        # xxx
+        # TODO: check for semantic conflicts
 
         vinfo = self.getVersionInfo(object)
         status = vinfo.getResourceStatus()
         if status == 'checked-out':
-            raise CheckOutError(
+            raise VersionControlError(
                 'The selected resource is already checked out.'
                 )
         repository_id = vinfo.getRepositoryId()
@@ -94,16 +119,15 @@
         version_id = vinfo.getSourceVersionId()
         version = history.getVersion(version_id)
 
-
         # These assume linear versioning!
         if history.lastVersionId() != version_id:
-            raise CheckOutError(
-                'The current resource does not reflect the latest version!'
+            raise VersionControlError(
+                'The selected resource is not up to date.'
                 )
 
         co_record = history.getCurrentCheckout(activity)
         if co_record is not None:
-            raise CheckOutError(
+            raise VersionControlError(
                 'The resource is already checked out by %s at %s.' % (
                 co_record.getUserName(), co_record.getTargetPath()
                 ))
@@ -122,22 +146,17 @@
         vinfo.setResourceStatus('checked-out')
         return object
 
-    def checkIn(self, object, message=''):
-        """Checkin"""
+    def checkinResource(self, object, message=''):
+        """Check in (create a new version) of the given resource."""
 
         activity = 'mainline'
 
-        # First, make sure object is not already under version control.
-        if not self.isUnderVersionControl(object):
-            raise 
-
-        # Check for semantic conflicts
-        # xxx
+        # TODO: check for semantic conflicts
 
         vinfo = self.getVersionInfo(object)
         status = vinfo.getResourceStatus()
         if status == 'checked-in':
-            raise CheckInError(
+            raise VersionControlError(
                 'The selected resource is already checked in.'
                 )
         repository_id = vinfo.getRepositoryId()
@@ -149,8 +168,8 @@
 
         # This assumes linear versioning.
         if history.lastVersionId() != last_version_id:
-            raise CheckInError(
-                'The current resource is not up to date.'
+            raise VersionControlError(
+                'The selected resource is not up to date.'
                 )
 
         # Create new version and update the versioning information.
@@ -168,21 +187,18 @@
         vinfo.setVersionPath(self._getObjectPath(version))
         return object
 
-    def unCheckOut(self, object):
-        """Revert to last checked-in version."""
+    def uncheckoutResource(self, object):
+        """Discard changes to a resource since it was checked out."""
+
         activity = 'mainline'
-        # First, make sure object is not already under version control.
-        if not self.isUnderVersionControl(object):
-            raise 
 
-        # Check for semantic conflicts
-        # xxx
+        # TODO: check for semantic conflicts
 
         vinfo = self.getVersionInfo(object)
         status = vinfo.getResourceStatus()
-        if status == 'checked-in':
-            raise CheckInError(
-                'The selected resource is already checked in.'
+        if status != 'checked-out':
+            raise VersionControlError(
+                'The selected resource is not checked out.'
                 )
         repository_id = vinfo.getRepositoryId()
         repository = self.getRepository(repository_id)
@@ -216,20 +232,17 @@
 
 
     def updateResource(self, object, version_id=None):
-        """ """
-        # First, make sure object is not already under version control.
-        if not self.isUnderVersionControl(object):
-            raise 
+        """Update the state of a resource to a specific version."""
 
-        # Check for semantic conflicts
-        # xxx
+        # TODO: check for semantic conflicts
 
         vinfo = self.getVersionInfo(object)
         status = vinfo.getResourceStatus()
         if status != 'checked-in':
-            # This would cause lost changes.
-            raise CheckInError(
-                'The selected resource is already checked in.'
+            # This would cause lost changes or require a merge.
+            raise VersionControlError(
+                'The selected resource must be checked in before it '
+                'can be updated (or else changes would be lost).'
                 )
         repository_id = vinfo.getRepositoryId()
         repository = self.getRepository(repository_id)
@@ -266,9 +279,43 @@
         return new_object
 
 
-    def isObjectUpToDate(self):
-        """ """
-        pass
+
+    security.declarePrivate('getRepositoryFor')
+    def getRepositoryFor(self, object):
+        """Return the repository object associated with a resource."""
+        info = self.getVersionInfo(object)
+        repository_id = info.getRepositoryId()
+        return self.getRepository(repository_id)
+
+    security.declarePrivate('getVersionHistoryFor')
+    def getVersionHistoryFor(self, object):
+        """Return the version history object for the given resource."""
+        info = self.getVersionInfo(object)
+        repository_id = info.getRepositoryId()
+        repository = self.getRepository(repository_id)
+        history_id = info.getVersionHistoryId()
+        return repository.getVersionHistory(history_id)
+
+    security.declarePrivate('getVersionFor')
+    def getVersionFor(self, object):
+        """Return the version object associated with a given resource."""
+        info = self.getVersionInfo(object)
+        repository_id = info.getRepositoryId()
+        repository = self.getRepository(repository_id)
+        history_id = info.getVersionHistoryId()
+        history = repository.getVersionHistory(history_id)
+        version_id = info.getSourceVersionId()
+        return history.getVersion(version_id)
+
+    security.declarePublic('getAvailableVersionIds')
+    def getAvailableVersionIds(self, object, activity='mainline'):
+        """Return the ids of available versions of a resource."""
+        # TODO - take activity into account here.
+        history = self.getVersionHistoryFor(object)
+        return history.getVersionIds()
+
+
+
 
     def _getObjectPath(self, object):
         path = object.getPhysicalPath()
@@ -277,22 +324,7 @@
     def _findUserName(self):
         user = AccessControl.getSecurityManager().getUser()
         return user.getUserName()
-    
-    def getAutoVersion(self):
-        return 'auto versioning settings'
-
-    def getSourceVersionId(self, object):
-        """Return the version of the resource that this object represents."""
-        return self.getVersionInfo(object).getSourceVersionId()
 
-    def getAvailableVersionIds(self, object):
-        """ """
-        vinfo = self.getVersionInfo(object)
-        repository_id = vinfo.getRepositoryId()
-        repository = self.getRepository(repository_id)
-        history_id = vinfo.getVersionHistoryId()
-        history = repository.getVersionHistory(history_id)
-        return history.getVersionIds()
 
     def getAllMessageEntries(self, object):
         """ """
@@ -340,7 +372,8 @@
 InitializeClass(VersionControl)
 
 
-
+class VersionControlError(Exception):
+    pass
 
 
 class CheckOutError(Exception):


=== Packages/VersionControl/VersionSupport.py 1.3 => 1.4 ===
 
         # Note - catch exceptions here later.
-        vc.versionControl(self, repository_id, description)
+        vc.applyVersionControl(self, repository_id, description)
 
         if REQUEST is not None:
             message="This object has been placed under version control."
@@ -65,7 +65,7 @@
         vc = VersionControl(self)
 
         # Note - catch exceptions here later.
-        vc.checkOut(self)
+        vc.checkoutResource(self)
 
         if REQUEST is not None:
             message="This object has been checked out."
@@ -80,7 +80,7 @@
         vc = VersionControl(self)
 
         # Note - catch exceptions here later.
-        vc.checkIn(self, message)
+        vc.checkinResource(self, message)
         new_ver = vc.getVersionInfo(self).getSourceVersionId()
         if REQUEST is not None:
             message="This object has been checked in [version %s]." % new_ver
@@ -97,7 +97,7 @@
         vc = VersionControl(self)
 
         # Note - catch exceptions here later.
-        newself = vc.unCheckOut(self)
+        newself = vc.uncheckoutResource(self)
 
         ver_id = vc.getVersionInfo(newself).getSourceVersionId()