gump-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r748028 - in /gump/trunk/python/gump: core/update/git.py core/update/scmupdater.py core/update/svn.py util/process/command.py
Date Thu, 26 Feb 2009 06:06:31 GMT
Author: bodewig
Date: Thu Feb 26 06:06:31 2009
New Revision: 748028

URL: http://svn.apache.org/viewvc?rev=748028&view=rev
Log:
extract common logic from svn and git updaters

Modified:
    gump/trunk/python/gump/core/update/git.py
    gump/trunk/python/gump/core/update/scmupdater.py
    gump/trunk/python/gump/core/update/svn.py
    gump/trunk/python/gump/util/process/command.py

Modified: gump/trunk/python/gump/core/update/git.py
URL: http://svn.apache.org/viewvc/gump/trunk/python/gump/core/update/git.py?rev=748028&r1=748027&r2=748028&view=diff
==============================================================================
--- gump/trunk/python/gump/core/update/git.py (original)
+++ gump/trunk/python/gump/core/update/git.py Thu Feb 26 06:06:31 2009
@@ -17,9 +17,9 @@
 # limitations under the License.
 
 from gump import log
-from gump.core.update.scmupdater import ScmUpdater, should_be_quiet
+from gump.core.update.scmupdater import match_workspace_template, ScmUpdater, \
+    should_be_quiet
 from gump.util.process.command import Cmd
-from gump.util.process.launcher import execute
 from gump.util.tools import tailFileToString
 
 def log_repository_and_url(module):
@@ -72,24 +72,7 @@
         """
             Run git config remote.origin.url to see whether the URL matches
         """
-        cmd = Cmd('git', 'check_workspace_' + module.getName(), 
-                  module.getSourceControlStagingDirectory())
-        cmd.addParameter('config')
-        cmd.addParameter('remote.origin.url')
-
-        result = execute(cmd)
-
-        output = None
-        if result.hasOutput():
-            output = tailFileToString(result.getOutput(), 1).rstrip()
-
-        if not result.isOk():
-            return (False, 'git config returned ' + str(result.exit_code))
-
-        elif not output:
-            return (False, 'git config didn\'t return any output.')
-
-        expectedURL = module.getScm().getRootUrl()
-
-        return (expectedURL == output, 'Expected URL \'' + expectedURL + \
-                    '\' but working copy was \'' + output + '\'')
+        return match_workspace_template(module, 'git config remote.origin.url',
+                                        lambda result:
+                                            tailFileToString(result.getOutput(),
+                                                             1).rstrip())

Modified: gump/trunk/python/gump/core/update/scmupdater.py
URL: http://svn.apache.org/viewvc/gump/trunk/python/gump/core/update/scmupdater.py?rev=748028&r1=748027&r2=748028&view=diff
==============================================================================
--- gump/trunk/python/gump/core/update/scmupdater.py (original)
+++ gump/trunk/python/gump/core/update/scmupdater.py Thu Feb 26 06:06:31 2009
@@ -25,6 +25,7 @@
 from gump.core.run.gumprun import RunSpecific
 from gump.util.process.launcher import execute
 from gump.util.tools import wipeDirectoryTree
+from gump.util.process.command import getCmdFromString
 
 def should_be_quiet(module):
     """
@@ -36,6 +37,29 @@
         and not module.getScm().isDebug() \
         and not module.getScm().isVerbose()
 
+def match_workspace_template(module, cmd_string, extract_url,
+                             expectedURL = None):
+    """
+    Template for the common run-a-command-and-extract-URL-from-output logic
+    for workspaceMatchesModule Method of ScmUpdater
+    """
+    if not expectedURL:
+        expectedURL = module.getScm().getRootUrl()
+
+    cmd = getCmdFromString(cmd_string, 'check_workspace_' + module.getName(), 
+                           module.getSourceControlStagingDirectory())
+
+    result = execute(cmd)
+
+    if not result.isOk():
+        return (False, cmd_string + ' returned ' + str(result.exit_code))
+
+    elif not result.hasOutput():
+        return (False, cmd_string + ' didn\'t return any output.')
+
+    actualURL = extract_url(result)
+    return (expectedURL == actualURL, 'Expected URL \'' + expectedURL + \
+                '\' but working copy was \'' + actualURL + '\'')
 
 ###############################################################################
 # Classes

Modified: gump/trunk/python/gump/core/update/svn.py
URL: http://svn.apache.org/viewvc/gump/trunk/python/gump/core/update/svn.py?rev=748028&r1=748027&r2=748028&view=diff
==============================================================================
--- gump/trunk/python/gump/core/update/svn.py (original)
+++ gump/trunk/python/gump/core/update/svn.py Thu Feb 26 06:06:31 2009
@@ -20,9 +20,9 @@
 import StringIO
 
 from gump import log
-from gump.core.update.scmupdater import ScmUpdater, should_be_quiet
+from gump.core.update.scmupdater import match_workspace_template, ScmUpdater, \
+    should_be_quiet
 from gump.util.process.command import Cmd
-from gump.util.process.launcher import execute
 from gump.util.tools import catFile
 
 def getCommand(module, forUpdate):
@@ -75,6 +75,19 @@
 
 URL_REGEX = re.compile('^URL:\s+(.*)\s*$', re.MULTILINE | re.UNICODE)
 
+def extract_URL(result):
+    """
+    Extracs the URL from 'svn info' output
+    """
+    stream = StringIO.StringIO()
+    catFile(stream, result.getOutput())
+    output = stream.getvalue()
+    stream.close()
+    match = URL_REGEX.search(output)
+    if not match:
+        return 'Couldn\'t find URL in svn info output ' + output
+    return match.group(1)
+
 ###############################################################################
 # Classes
 ###############################################################################
@@ -104,31 +117,6 @@
         """
             Run svn info to see whether the URL matches
         """
-        cmd = Cmd('svn', 'check_workspace_' + module.getName(), 
-                  module.getSourceControlStagingDirectory())
-        cmd.addParameter('info')
-
-        result = execute(cmd)
-
-        output = None
-        if result.hasOutput():
-            stream = StringIO.StringIO()
-            catFile(stream, result.getOutput())
-            output = stream.getvalue()
-            stream.close()
-
-        if not result.isOk():
-            return (False, 'svn info returned ' + str(result.exit_code))
-
-        elif not output:
-            return (False, 'svn info didn\'t return any output.')
-
-        match = URL_REGEX.search(output)
-        if not match:
-            return (False, 'Couldn\'t find URL in svn info output ' + output)
-
-        expectedURL = module.getScm().getRootUrl().rstrip('/')
-        actualURL = match.group(1)
-
-        return (expectedURL == actualURL, 'Expected URL \'' + expectedURL + \
-                    '\' but working copy was \'' + actualURL + '\'')
+        return match_workspace_template(module, 'svn info', extract_URL,
+                                        module.getScm().getRootUrl() \
+                                            .rstrip('/'))

Modified: gump/trunk/python/gump/util/process/command.py
URL: http://svn.apache.org/viewvc/gump/trunk/python/gump/util/process/command.py?rev=748028&r1=748027&r2=748028&view=diff
==============================================================================
--- gump/trunk/python/gump/util/process/command.py (original)
+++ gump/trunk/python/gump/util/process/command.py Thu Feb 26 06:06:31 2009
@@ -221,12 +221,12 @@
     def dump(self,indent=''):
         print self.overview(indent)
         
-def getCmdFromString(strcmd,name=None):
+def getCmdFromString(strcmd, name = None, cwd = None):
     """Extract a Cmd Object from a String"""
     parts = split(strcmd,' ')
     cmdcmd = parts[0]
     if not name: name = cmdcmd
-    cmd = Cmd(cmdcmd,name)
+    cmd = Cmd(cmdcmd, name, cwd)
     for i in range(1,len(parts)):
         if parts[i]:
             cmd.addParameterObject(getParameterFromString(parts[i]))



Mime
View raw message