summaryrefslogtreecommitdiffstats
path: root/GitAutoDeploy.py
diff options
context:
space:
mode:
Diffstat (limited to 'GitAutoDeploy.py')
-rwxr-xr-xGitAutoDeploy.py20
1 files changed, 17 insertions, 3 deletions
diff --git a/GitAutoDeploy.py b/GitAutoDeploy.py
index 1bc6ead..485d84f 100755
--- a/GitAutoDeploy.py
+++ b/GitAutoDeploy.py
@@ -47,8 +47,14 @@ 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:
+ self.pull(repo['path'], repo['branch'])
+ 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')
@@ -111,11 +117,19 @@ 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)
+
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(['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()