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/06 07:21:36 UTC
svn commit: r741429 - /gump/trunk/python/gump/core/update/git.py
Author: bodewig
Date: Fri Feb 6 06:21:36 2009
New Revision: 741429
URL: http://svn.apache.org/viewvc?rev=741429&view=rev
Log:
initial git updater
Added:
gump/trunk/python/gump/core/update/git.py (with props)
Added: gump/trunk/python/gump/core/update/git.py
URL: http://svn.apache.org/viewvc/gump/trunk/python/gump/core/update/git.py?rev=741429&view=auto
==============================================================================
--- gump/trunk/python/gump/core/update/git.py (added)
+++ gump/trunk/python/gump/core/update/git.py Fri Feb 6 06:21:36 2009
@@ -0,0 +1,206 @@
+#!/usr/bin/python
+
+
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# 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.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""
+
+"""
+
+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 *
+
+###############################################################################
+# Classes
+###############################################################################
+
+class GitUpdater(RunSpecific):
+
+ def __init__(self,run):
+ RunSpecific.__init__(self,run)
+
+
+ def updateModule(self,module):
+ """
+ Perform a GIT update on a module
+ """
+
+ log.info('Perform GIT Update on #[' + `module.getPosition()` + \
+ '] : ' + module.getName())
+
+ # Did we 'GIT checkout' already?
+ exists = os.path.exists(module.getSourceControlStagingDirectory())
+
+ self.performUpdate(module, exists)
+
+ return module.okToPerformWork()
+
+ def performStatus(self,module):
+ """
+
+ Do a status comparison between our copy and server
+
+ """
+
+ # need to look up how to do that with git
+
+ def getStatusCommand(self,module):
+ """
+
+ Build the 'git status --show-updates --non-interative' command
+
+ """
+
+ # need to look up how to do that with git, this is certainly wrong
+
+ log.debug("Git Module Status : " + module.getName() + \
+ ", Repository Name: " + str(module.repository.getName()))
+
+ url=module.git.getRootUrl()
+
+ log.debug("GIT URL: [" + url + "] on Repository: " + module.repository.getName())
+
+ #
+ # Prepare GIT checkout/update command...
+ #
+ cmd=Cmd('git', 'status_'+module.getName(),
+ module.getSourceControlStagingDirectory())
+
+ #
+ # Be 'quiet' (but not silent) unless requested otherwise.
+ #
+ if not module.isDebug() \
+ and not module.isVerbose() \
+ and not module.git.isDebug() \
+ and not module.git.isVerbose():
+ cmd.addParameter('--quiet')
+
+ #
+ # Allow trace for debug
+ #
+ # if module.isDebug() or module.git.isDebug():
+ # cmd.addParameter('--verbose')
+
+ # do an GIT status
+ cmd.addParameter('status')
+
+ return cmd
+
+
+ def performUpdate(self,module,exists):
+ """
+
+ Clone or Pull from GIT
+
+ """
+
+ # Get the Update Command
+ (repository, url, cmd ) = self.getUpdateCommand(module, exists)
+
+
+ # 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 to clone/pull module: ' + module.name)
+ module.changeState(STATE_FAILED,REASON_UPDATE_FAILED)
+ else:
+ module.changeState(STATE_SUCCESS)
+
+
+ def preview(self,module):
+ (repository, url, command ) = self.getUpdateCommand(module,0)
+ command.dump()
+
+ (repository, url, command ) = self.getUpdateCommand(module,1)
+ command.dump()
+
+ def getUpdateCommand(self,module,exists=0):
+ """
+ Build the appropriate GIT command for clone/pull
+ """
+ repository=module.repository
+
+ log.debug("Git Module Update : " + module.getName() + \
+ ", Repository Name: " + repository.getName())
+
+ url=module.git.getRootUrl()
+
+ log.debug("GIT URL: [" + url + "] on Repository: " + repository.getName())
+
+ #
+ # Prepare GIT clone/pull command...
+ #
+
+ if exists:
+ # do a GIT pull inside working copy
+ cmd=Cmd('git-pull', 'update_'+module.getName(),
+ module.getSourceControlStagingDirectory())
+ else:
+ # do a GIT clone
+ cmd=Cmd('git-clone', 'update_'+module.getName(),
+ module.getWorkspace().getSourceControlStagingDirectory())
+
+ #
+ # Be 'quiet' (but not silent) unless requested otherwise.
+ #
+ if not module.isDebug() \
+ and not module.isVerbose() \
+ and not module.git.isDebug() \
+ and not module.git.isVerbose():
+ cmd.addParameter('--quiet')
+
+ #
+ # Allow trace for debug
+ #
+ # if module.isDebug() or module.git.isDebug():
+ # cmd.addParameter('--verbose')
+
+ if not exists:
+ # do an GIT pull
+ cmd.addParameter(url)
+ cmd.addParameter(module.getName())
+
+ return (module.repository, url, cmd)
+
+
Propchange: gump/trunk/python/gump/core/update/git.py
------------------------------------------------------------------------------
svn:eol-style = native