You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gump.apache.org by bo...@apache.org on 2009/02/27 20:58:20 UTC

svn commit: r748661 - /gump/trunk/python/gump/core/update/cvs.py

Author: bodewig
Date: Fri Feb 27 19:58:20 2009
New Revision: 748661

URL: http://svn.apache.org/viewvc?rev=748661&view=rev
Log:
allow CVS to detect a bad working copy

Modified:
    gump/trunk/python/gump/core/update/cvs.py

Modified: gump/trunk/python/gump/core/update/cvs.py
URL: http://svn.apache.org/viewvc/gump/trunk/python/gump/core/update/cvs.py?rev=748661&r1=748660&r2=748661&view=diff
==============================================================================
--- gump/trunk/python/gump/core/update/cvs.py (original)
+++ gump/trunk/python/gump/core/update/cvs.py Fri Feb 27 19:58:20 2009
@@ -15,9 +15,12 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import os.path
+
 from gump.core.model.workspace import Cmd
 from gump.core.update.scmupdater import ScmUpdater, should_be_quiet
 from gump.tool.integration.cvs import readLogins, loginToRepositoryOnDemand
+from gump.util.tools import tailFileToString
 
 def maybe_add_tag(module, cmd):
     # Determine if a tag is set, on <cvs or on <module
@@ -40,6 +43,16 @@
     # Set the CVS root
     cmd.addParameter('-d', module.getScm().getCvsRoot())    
 
+def error_unless_file_content_matches(cvsdir, filename, expected_content,
+                                      prop):
+    f = os.path.join(cvsdir, filename)
+    if not os.path.exists(f):
+        return (False, 'workspace doesn\'t contain a ' + filename + ' file')
+    actual = tailFileToString(f, 1).rstrip()
+    if actual != expected_content:
+        return (False, 'expected ' + prop + ' to be \'' + \
+                        expected_content + '\' but is \'' + actual + '\'')
+    return None
 
 ###############################################################################
 # Classes
@@ -103,6 +116,49 @@
 
         return cmd
     
+    def workspaceMatchesModule(self, module):
+        """
+        look for a CVS directory and the files contained therein, try to match
+        the contents of said files
+        """
+        cvsdir = os.path.join(module.getSourceControlStagingDirectory(),
+                               'CVS')
+        if not os.path.exists(cvsdir):
+            return (False, 'workspace doesn\'t contain a CVS directory')
+
+        root = error_unless_file_content_matches(cvsdir, 'Root',
+                                                 module.getScm().getCvsRoot(),
+                                                 'CVSROOT')
+        if root:
+            return root
+
+        expected_module = module.getName()
+        if module.getScm().hasModule():
+            expected_module = module.getScm().getModule()
+        rep = error_unless_file_content_matches(cvsdir, 'Repository',
+                                                expected_module, 'Module')
+        if rep:
+            return rep
+
+        if module.getScm().hasTag() or module.hasTag():
+            expected_tag = None
+            if module.getScm().hasTag():
+                expected_tag = module.getScm().getTag()
+            elif module.hasTag():
+                expected_tag = module.getTag()
+            tag = error_unless_file_content_matches(cvsdir, 'Tag',
+                                                    expected_tag, 'Tag')
+            if tag:
+                return tag
+
+        elif os.path.exists(os.path.join(cvsdir, 'Tag')):
+            return (False, 'workspace is tagged with \'' + \
+                        tailFileToString(os.path.join(cvsdir, 'Tag'),
+                                         1).rstrip() + \
+                        '\' but shouldn\'t have a tag at all.')
+
+        return (True, '')
+
     def maybeLogin(self, module):
         repository = module.repository
         root = module.getScm().getCvsRoot()