summaryrefslogtreecommitdiffstats
path: root/gitautodeploy
diff options
context:
space:
mode:
authorOliver Poignant <oliver@poignant.se>2016-05-28 16:16:48 +0200
committerOliver Poignant <oliver@poignant.se>2016-05-28 16:16:48 +0200
commit34b3205c0ce3c6bf54c42cd5296ee9a06befc452 (patch)
treec877ed3c06b216d52f6c8221a8772a3d79aece34 /gitautodeploy
parentb4e3c96aecc821ce089442a62a825cd2c78bb876 (diff)
parent2afdae5f9f68de7ff14d7238986e190c1450be12 (diff)
downloadGit-Auto-Deploy-34b3205c0ce3c6bf54c42cd5296ee9a06befc452.zip
Git-Auto-Deploy-34b3205c0ce3c6bf54c42cd5296ee9a06befc452.tar.gz
Git-Auto-Deploy-34b3205c0ce3c6bf54c42cd5296ee9a06befc452.tar.bz2
Merge branch 'vladionescu-windows-compat'
Diffstat (limited to 'gitautodeploy')
-rw-r--r--gitautodeploy/gitautodeploy.py20
-rw-r--r--gitautodeploy/lock.py35
-rw-r--r--gitautodeploy/wrappers/git.py21
3 files changed, 45 insertions, 31 deletions
diff --git a/gitautodeploy/gitautodeploy.py b/gitautodeploy/gitautodeploy.py
index f24ec6e..8f3b172 100644
--- a/gitautodeploy/gitautodeploy.py
+++ b/gitautodeploy/gitautodeploy.py
@@ -160,7 +160,13 @@ class GitAutoDeploy(object):
logger.warning('No process is currently using port %s.' % self._config['port'])
return False
- os.kill(pid, signal.SIGKILL)
+ if hasattr(signal, 'SIGKILL'):
+ os.kill(pid, signal.SIGKILL)
+ elif hasattr(signal, 'SIGHUP'):
+ os.kill(pid, signal.SIGHUP)
+ else:
+ os.kill(pid, 1)
+
return True
def create_pid_file(self):
@@ -410,10 +416,14 @@ def main():
app = GitAutoDeploy()
- signal.signal(signal.SIGHUP, app.signal_handler)
- signal.signal(signal.SIGINT, app.signal_handler)
- signal.signal(signal.SIGABRT, app.signal_handler)
- signal.signal(signal.SIGPIPE, signal.SIG_IGN)
+ if hasattr(signal, 'SIGHUP'):
+ signal.signal(signal.SIGHUP, app.signal_handler)
+ if hasattr(signal, 'SIGINT'):
+ signal.signal(signal.SIGINT, app.signal_handler)
+ if hasattr(signal, 'SIGABRT'):
+ signal.signal(signal.SIGABRT, app.signal_handler)
+ if hasattr(signal, 'SIGPIPE') and hasattr(signal, 'SIG_IGN'):
+ signal.signal(signal.SIGPIPE, signal.SIG_IGN)
config = get_config_defaults()
diff --git a/gitautodeploy/lock.py b/gitautodeploy/lock.py
index b0b408b..f894bb3 100644
--- a/gitautodeploy/lock.py
+++ b/gitautodeploy/lock.py
@@ -1,12 +1,15 @@
+from lockfile import LockFile
+
class Lock():
"""Simple implementation of a mutex lock using the file systems. Works on
*nix systems."""
path = None
- _has_lock = False
+ lock = None
def __init__(self, path):
self.path = path
+ self.lock = LockFile(path)
def obtain(self):
import os
@@ -14,39 +17,31 @@ class Lock():
logger = logging.getLogger()
try:
- os.open(self.path, os.O_CREAT | os.O_EXCL | os.O_WRONLY)
- self._has_lock = True
+ self.lock.acquire(0)
logger.debug("Successfully obtained lock: %s" % self.path)
- except OSError:
+ except AlreadyLocked:
return False
- else:
- return True
+
+ return True
def release(self):
import os
import logging
logger = logging.getLogger()
- if not self._has_lock:
+ if not self.has_lock():
raise Exception("Unable to release lock that is owned by another process")
- try:
- os.remove(self.path)
- logger.debug("Successfully released lock: %s" % self.path)
- finally:
- self._has_lock = False
+
+ self.lock.release()
+ logger.debug("Successfully released lock: %s" % self.path)
def has_lock(self):
- return self._has_lock
+ return self.lock.i_am_locking()
def clear(self):
import os
import logging
logger = logging.getLogger()
- try:
- os.remove(self.path)
- except OSError:
- pass
- finally:
- logger.debug("Successfully cleared lock: %s" % self.path)
- self._has_lock = False \ No newline at end of file
+ self.lock.break_lock()
+ logger.debug("Successfully cleared lock: %s" % self.path)
diff --git a/gitautodeploy/wrappers/git.py b/gitautodeploy/wrappers/git.py
index 7d18550..78a469c 100644
--- a/gitautodeploy/wrappers/git.py
+++ b/gitautodeploy/wrappers/git.py
@@ -20,11 +20,20 @@ class GitWrapper():
logger.info('No local repository path configured, no pull will occure')
return 0
- cmd = 'unset GIT_DIR ' + \
- '&& git fetch ' + repo_config['remote'] + \
- '&& git reset --hard ' + repo_config['remote'] + '/' + repo_config['branch'] + ' ' + \
- '&& git submodule init ' + \
- '&& git submodule update'
+ import platform
+
+ if platform.system().lower() == "windows":
+ # This assumes Git for Windows is installed.
+ cmd = ['"\Program Files\Git\usr\\bin\\bash.exe"',
+ ' -c "cd ' + repo_config['path'],
+ ' && unset GIT_DIR ']
+ else:
+ cmd = ['unset GIT_DIR ']
+
+ cmd.append(' && git fetch ' + repo_config['remote'])
+ cmd.append(' && git reset --hard ' + repo_config['remote'] + '/' + repo_config['branch'])
+ cmd.append(' && git submodule init ')
+ cmd.append(' && git submodule update')
# '&& git update-index --refresh ' +\
res = ProcessWrapper().call([cmd], cwd=repo_config['path'], shell=True)
@@ -67,4 +76,4 @@ class GitWrapper():
logger.info('%s commands executed with status; %s' % (str(len(res)), str(res)))
- return res \ No newline at end of file
+ return res