-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfabfile.py
72 lines (51 loc) · 1.6 KB
/
fabfile.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
from fabric.api import *
from fabtools.vagrant import vagrant, vagrant_settings
import os
PROJECT_PATH = '/vagrant/{{ project_name }}/'
VENV_PATH = '/home/vagrant/env'
MANAGE_BIN = os.path.join(PROJECT_PATH, 'manage.py')
SETTINGS = '{{ project_name }}.settings.local'
TEST_SETTINGS = '{{ project_name }}.settings.test'
@task
def manage_py(command):
"""
Runs a manage.py command on the server
"""
with cd(PROJECT_PATH):
run('{python} {manage} {command} --settings={settings}'.format(python=VENV_PATH + '/bin/python',
manage=MANAGE_BIN,
command=command,
settings=SETTINGS))
@task
def test():
manage_py("test", settings=TEST_SETTINGS)
@task
def migrate():
manage_py("makemigrations")
manage_py("migrate")
@task
def createsuperuser():
manage_py("createsuperuser")
@task
def gunicorn_hup():
sudo("kill -HUP $(supervisorctl pid gunicorn_app)")
@task
def gunicorn_restart():
"""Restarts gunicorn completely (use when settings files have been changed)"""
sudo("supervisorctl restart gunicorn_app")
@task
def watchdog():
local('watchmedo shell-command --patterns="*.py" --recursive --command="fab vagrant gunicorn_hup" {{ project_name }}/')
@task
def provision():
sudo('salt-call state.highstate')
@task
def vagrant_up():
local('vagrant up')
with vagrant_settings():
execute(provision)
execute(migrate)
execute(watchdog)
@task
def clean_pyc():
local('find . -name "*.pyc" -delete')