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/16 04:55:39 UTC

svn commit: r744796 - /gump/trunk/python/gump/core/update/p4.py

Author: bodewig
Date: Mon Feb 16 03:55:39 2009
New Revision: 744796

URL: http://svn.apache.org/viewvc?rev=744796&view=rev
Log:
pylint assisted refactoring of Perforce Updater

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

Modified: gump/trunk/python/gump/core/update/p4.py
URL: http://svn.apache.org/viewvc/gump/trunk/python/gump/core/update/p4.py?rev=744796&r1=744795&r2=744796&view=diff
==============================================================================
--- gump/trunk/python/gump/core/update/p4.py (original)
+++ gump/trunk/python/gump/core/update/p4.py Mon Feb 16 03:55:39 2009
@@ -15,184 +15,58 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-"""
 
-"""
+from gump.core.model.workspace import Cmd
+from gump.core.update.scmupdater import ScmUpdater
 
-import os.path
-import sys
-from fnmatch import fnmatch
-
-from gump import log
-from gump.core.run.gumprun import *
-from gump.core.config import dir, default, basicConfig
-
-from gump.util import dump, display, getIndent, logResourceUtilization, \
-                            invokeGarbageCollection
-from gump.util.note import Annotatable
-from gump.util.work import *
-
-from gump.util.tools import *
-
-from gump.core.model.workspace import *
-from gump.core.model.module import Module
-from gump.core.model.project import Project
-from gump.core.model.depend import  ProjectDependency
-from gump.core.model.stats import *
-from gump.core.model.state import *
+def getP4Command(module):
+    """
+    Update this module (checking out if needed)
+    """
+    cmd = Cmd('p4', 'update_' + module.getName(),
+              module.getWorkspace().getSourceControlStagingDirectory())
+          
+    # Determine if a tag is set, on <p4 or on <module
+    tag = None
+    if module.getScm().hasTag():
+        tag = module.getScm().getTag()
+    elif module.hasTag():
+        tag = module.getTag()
+
+    # Do a p4 sync
+    cmd.addParameter('-p', module.getScm().getPort())
+    cmd.addParameter('-u', module.getScm().getUser())
+    cmd.addParameter('-P', module.getScm().getPassword())
+    cmd.addParameter('-c', module.getScm().getClientspec())
+    cmd.addParameter('sync')
+    if tag:
+        cmd.addParameter(module.getName() + '/...@', tag, ' ')
+    else:
+        cmd.addParameter(module.getName() + '/...')
 
+    return cmd
 
 ###############################################################################
 # Classes
 ###############################################################################
 
-class P4Updater(RunSpecific):
+class P4Updater(ScmUpdater):
+    """
+    Updater for Perforce
+    """
     
-    def __init__(self,run):
-        RunSpecific.__init__(self,run)
-
-        #
-        # A stash of known logins.
-        #
-        #self.logins=readLogins()
+    def __init__(self, run):
+        ScmUpdater.__init__(self, run)
 
-    def updateModule(self,module):
+    def getCheckoutCommand(self, module):
         """
-        
-            Perform a P4 sync on a module
-            
+            Checkout this module
         """
-            
-        #log.info('Perform P4 Sync on #[' + `module.getPosition()` + \
-        #                '] : ' + module.getName())
-    
-        ## Did we 'P4 checkout' already?
-        exists	=	os.path.exists(module.getSourceControlStagingDirectory())
-       
-        # Doesn't tell us much...
-        if exists:
-            self.performStatus(module)
-                
-        self.performUpdate(module,exists)        
-        
-        return module.okToPerformWork()      
-        
-    def performStatus(self,module):
-        #  Get the Update Command
-        (repository, root, cmd ) = self.getUpdateCommand(module, True, True)
-                
-        ## Provide P4 logins, if not already there
-        #loginToRepositoryOnDemand(repository,root,self.logins)
-               
-        # 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)  
-     
-        if not cmdResult.isOk():              
-            log.error('Failed to checkout/update module: ' + module.name)   
-                                  
-    def performUpdate(self,module,exists):
-        """
-            Update this module (checking out if needed)
+        return getP4Command(module)
+
+    def getUpdateCommand(self, module):
         """
-        #  Get the Update Command
-        (repository, root, cmd ) = self.getUpdateCommand(module, exists)
-                
-        #log.debug("P4 Sync Module " + module.getName() + \
-        #               ", Repository Name: " + str(module.repository.getName()))
-                                        
-        ## Provide P4 logins, if not already there
-        #loginToRepositoryOnDemand(repository,root,self.logins)
-               
-        # 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)  
-        repository.performedWork(work.clone())
-      
-        # Update Context w/ Results  
-        if not cmdResult.isOk():              
-            log.error('Failed w/ P4 Root ' + root + ' for %s on Repository %s.' \
-                % (module.name, module.repository.getName())) 
-            module.changeState(STATE_FAILED,REASON_UPDATE_FAILED)
-        else:
-            module.changeState(STATE_SUCCESS)      
-            
-            # We run P4 so any output means updates occured...
-            if cmdResult.hasOutput():                       
-                log.info('Update(s) received via P4 on #[' \
-                                + `module.getPosition()` + \
-                                '] : ' + module.getName())
-                                 
-    def preview(self,module):
-                
-        (repository, root, command ) = self.getUpdateCommand(module,False)
-        command.dump()
-        
-        # Doesn't tell us much...
-        #(repository, root, command ) = self.getUpdateCommand(module,True,True)
-        #command.dump()
-            
-        (repository, root, command ) = self.getUpdateCommand(module,True)
-        command.dump()                       
-        
-    
-    def getUpdateCommand(self,module,exists=False,nowork=False):
-        """        
-            Format a commandline for doing the P4 update            
+            Update this module
         """
-        if nowork and not exists:
-            raise RuntimeException('Not coded for this combo.')            
-        
-        root=module.getScm().getClientspec()
-        # Prepare P4 sync command...
-        prefix='update'
-        directory=module.getWorkspace().getSourceControlStagingDirectory()
-        #if exists:     
-        #    directory=module.getSourceControlStagingDirectory()            
-        if nowork:
-            prefix='status'
-                
-        cmd=Cmd(	'p4',
-                    prefix+'_'+module.getName(),
-                    directory)
-          
-        ## Allow trace for debug
-        #if module.isDebug():
-        #    cmd.addParameter('-t')
-          
-        ## Request compression
-        #cmd.addParameter('-z3')
-          
-        # Determine if a tag is set, on <p4 or on <module
-        tag=None
-        if module.getScm().hasTag():
-            tag=module.getScm().getTag()
-        elif module.hasTag():
-            tag=module.getTag()
-        
-        # Do a p4 sync
-        cmd.addParameter('-p',module.getScm().getPort())
-        cmd.addParameter('-u',module.getScm().getUser())
-        cmd.addParameter('-P',module.getScm().getPassword())
-        cmd.addParameter('-c',root)
-        cmd.addParameter('sync')
-        if nowork:
-            cmd.addParameter('-n')
-        if tag:
-            cmd.addParameter(module.getName()+'/...@',tag,' ')
-        else:
-            cmd.addParameter(module.getName()+'/...')
-        #cmd.addParameter(module.getName())
+        return getP4Command(module)
 
-        return (module.repository, root, cmd)
-