-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathpavement.py
73 lines (61 loc) · 1.96 KB
/
pavement.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import os
from paver.easy import *
from paver.setuputils import setup
import time
def _kill(arg1, arg2): #TODO(MridulS) add functionality to kill server by port.
"""Stops a proces that contains arg1 and is filtered by arg2
"""
from subprocess import Popen, PIPE
# Wait until ready
t0 = time.time()
# Wait no more than these many seconds
time_out = 30
running = True
while running and time.time() - t0 < time_out:
if os.name == 'nt':
p = Popen('tasklist | find "%s"' % arg1, shell=True,
stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=False)
else:
p = Popen('ps aux | grep %s' % arg1, shell=True,
stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True)
lines = p.stdout.readlines()
running = False
for line in lines:
#this kills python including self in windows
if ('%s' % arg2 in line) or (os.name == 'nt' and '%s' % arg1 in line):
running = True
# Get pid
fields = line.strip().split()
info('Stopping %s (process number %s)' % (arg1, fields[1]))
if os.name == 'nt':
kill = 'taskkill /F /PID "%s"' % fields[1]
else:
kill = 'kill -9 %s 2> /dev/null' % fields[1]
os.system(kill)
# Give it a little more time. Go have some beer!!!
time.sleep(1)
else:
pass
if running:
raise Exception('Could not stop %s: '
'Running processes are\n%s'
% (arg1, '\n'.join([l.strip() for l in lines])))
@task
def setup():
"""
Install dependencies
"""
sh('pip install -r requirements.txt')
sh('python manage.py syncdb')
@task
def start():
"""
Start HealthDB at localhost
"""
sh('python manage.py runserver')
@task
def stop():
"""
Stop HealthDB
"""
_kill('python', 'runserver')