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/24 05:24:15 UTC

svn commit: r747273 - /gump/trunk/python/gump/core/update/scmupdater.py

Author: bodewig
Date: Tue Feb 24 04:24:15 2009
New Revision: 747273

URL: http://svn.apache.org/viewvc?rev=747273&view=rev
Log:
Provide infrastructure for updaters to signal a working copy that doesn't match the expected definition

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

Modified: gump/trunk/python/gump/core/update/scmupdater.py
URL: http://svn.apache.org/viewvc/gump/trunk/python/gump/core/update/scmupdater.py?rev=747273&r1=747272&r2=747273&view=diff
==============================================================================
--- gump/trunk/python/gump/core/update/scmupdater.py (original)
+++ gump/trunk/python/gump/core/update/scmupdater.py Tue Feb 24 04:24:15 2009
@@ -7,9 +7,9 @@
 # The ASF licenses this file to You under the Apache License, Version 2.0
 # (the "License"); you may not use this file except in compliance with
 # the License.  You may obtain a copy of the License at
-# 
+#
 #     http://www.apache.org/licenses/LICENSE-2.0
-# 
+#
 # Unless required by applicable law or agreed to in writing, software
 # distributed under the License is distributed on an "AS IS" BASIS,
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -23,6 +23,7 @@
 from gump.core.model.workspace import CommandWorkItem, execute, \
     REASON_UPDATE_FAILED, STATE_FAILED, STATE_SUCCESS, WORK_TYPE_UPDATE
 from gump.core.run.gumprun import RunSpecific
+from gump.util.tools import wipeDirectoryTree
 
 def should_be_quiet(module):
     """
@@ -41,10 +42,10 @@
 class ScmUpdater(RunSpecific):
     """
     Base class for a SCM specific updaters.
-    
+
     Provides helpers and template method implementations.
     """
-    
+
     def __init__(self, run):
         RunSpecific.__init__(self, run)
 
@@ -71,7 +72,7 @@
         log.info('Perform ' + module.getScm().getScmType().displayName + \
                      ' Checkout/Update on #[' + `module.getPosition()` + \
                      '] : ' + module.getName())
-    
+
         (cmd, isUpdate) = self.getCommandAndType(module)
 
         if cmd:
@@ -86,25 +87,25 @@
                               ", Repository Name: " + \
                               module.repository.getName())
 
-            # Execute the command and capture results        
+            # Execute the command and capture results
             cmdResult = execute(cmd, module.getWorkspace().tmpdir)
-      
+
             # Store this as work, on both the module and (cloned) on the repo
             work = CommandWorkItem(WORK_TYPE_UPDATE, cmd, cmdResult)
             module.performedWork(work)
             module.repository.performedWork(work.clone())
-      
-            # Update Context w/ Results  
-            if not cmdResult.isOk():              
-                log.error('Failed to checkout/update module: ' + module.name)   
+
+            # Update Context w/ Results
+            if not cmdResult.isOk():
+                log.error('Failed to checkout/update module: ' + module.name)
                 module.changeState(STATE_FAILED, REASON_UPDATE_FAILED)
             else:
-                module.changeState(STATE_SUCCESS)       
+                module.changeState(STATE_SUCCESS)
 
             return module.okToPerformWork()
 
         log.error("Don't know how to to checkout/update module: " + \
-                      module.name)   
+                      module.name)
         module.changeState(STATE_FAILED, REASON_UPDATE_FAILED)
         return False
 
@@ -116,11 +117,24 @@
         """
         Checks whether an update or a fresh checkout is needed and
         returns a command to perform the required action.
-        
+
         Returns a tuple (command, isUpdate)
         """
         exists = os.path.exists(module.getSourceControlStagingDirectory())
 
+        if exists:
+            (matches, reason) = self.workspaceMatchesModule(module)
+            if not matches:
+                msg = 'The working copy \'' + \
+                    module.getSourceControlStagingDirectory() + \
+                    '\' doesn\'t match the module definition, reason: \'' + \
+                    reason + '\'. Removing it.'
+                log.warn(msg)
+                module.addWarning(msg)
+                wipeDirectoryTree(module.getSourceControlStagingDirectory(),
+                                  False)
+                exists = False
+
         cmd = None
         if exists:
             cmd = self.getUpdateCommand(module)
@@ -145,3 +159,17 @@
         """
         return None
 
+
+    def workspaceMatchesModule(self, module):
+        """
+        Whether the working copy matches what the updater expects it to
+        be - like being a working copy of the module's svn URL or
+        CVS Root etc.
+
+        Must return a tuple (matches, reason) with a bool indicating
+        whether the workspace matches the module defintion and a reason
+        string if it doesn't.
+
+        This base implementation returns (True, '')
+        """
+        return (True, '')