diff options
author | Oliver Poignant <oliver@poignant.se> | 2015-05-17 21:08:29 +0200 |
---|---|---|
committer | Oliver Poignant <oliver@poignant.se> | 2015-05-17 21:08:29 +0200 |
commit | c88ae14185b8d829eeb6d099f49867d37f7723d5 (patch) | |
tree | 1f32e046ec3af1f27ac253cd814bd5196362ada0 /GitAutoDeploy.py | |
parent | 72f40fc96e50452b5fa1201c2e5dbf03f84e891e (diff) | |
parent | 9393a4d0d7b3edc24eea30882f49172bf1d37b88 (diff) | |
download | Git-Auto-Deploy-c88ae14185b8d829eeb6d099f49867d37f7723d5.zip Git-Auto-Deploy-c88ae14185b8d829eeb6d099f49867d37f7723d5.tar.gz Git-Auto-Deploy-c88ae14185b8d829eeb6d099f49867d37f7723d5.tar.bz2 |
Merge pull request #25 from quizzz-and-chiv/lock
Wait while previous deploy request is finished or just exit if some other request is waiting
Diffstat (limited to 'GitAutoDeploy.py')
-rwxr-xr-x | GitAutoDeploy.py | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/GitAutoDeploy.py b/GitAutoDeploy.py index 9f8b26e..6a6afc8 100755 --- a/GitAutoDeploy.py +++ b/GitAutoDeploy.py @@ -40,6 +40,7 @@ class GitAutoDeploy(BaseHTTPRequestHandler): if(not os.path.isdir(repository['path'] + '/.git')): print "Directory %s is not a Git repository" % repository['path'] sys.exit(2) + myClass.clearLock(repository['path']) return myClass.config @@ -52,8 +53,17 @@ class GitAutoDeploy(BaseHTTPRequestHandler): for url in urls: repos = self.getMatchingPaths(url) for repo in repos: - self.pull(repo['path'], repo['branch']) - self.deploy(repo['path']) + if self.lock(repo['path']): + try: + n = 4 + while 0 < n and 0 != self.pull(repo['path'], repo['branch']): + --n + if 0 < n: + self.deploy(repo['path']) + except: + call(['echo "Error during \'pull\' or \'deploy\' operation on path: ' + repo['path'] + '"'], shell=True) + finally: + self.unlock(repo['path']) def parseRequest(self): contenttype = self.headers.getheader('content-type') @@ -116,11 +126,23 @@ class GitAutoDeploy(BaseHTTPRequestHandler): self.send_header('Content-type', 'text/plain') self.end_headers() + def lock(self, path): + return 0 == call(['sh lock.sh "' + path + '"'], shell=True) + + def unlock(self, path): + call(['sh unlock.sh "' + path + '"'], shell=True) + + @classmethod + def clearLock(myClass, path): + call(['sh clear_lock.sh "' + path + '"'], shell=True) + def pull(self, path, branch): if(not self.quiet): print "\nPost push request received" print 'Updating ' + path - call(['cd "' + path + '" && git fetch origin ; git update-index --refresh &> /dev/null ; git reset --hard origin/' + branch], shell=True) + res = call(['sleep 5; cd "' + path + '" && git fetch origin ; git update-index --refresh &> /dev/null ; git reset --hard origin/' + branch], shell=True) + call(['echo "Pull result: ' + str(res) + '"'], shell=True) + return res def deploy(self, path): config = self.getConfig() |