-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfabfile.py
110 lines (81 loc) · 2.94 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
from __future__ import with_statement
import posixpath
from fabric.api import run, env, task
from fabric.context_managers import cd, settings
# Host and login username:
env.hosts = ['[email protected]']
# Directory where everything to do with this app will be stored on the server.
DJANGO_APP_ROOT = '/home/jgraham32/webapps/handprints_app/'
# Directory where static sources should be collected. This must equal the value
# of STATIC_ROOT in the settings.py that is used on the server.
STATIC_ROOT = '/home/jgraham32/webapps/handprints_static/'
# Subdirectory of DJANGO_APP_ROOT in which project sources will be stored
SRC_SUBDIR = 'handprints'
# Python version
PYTHON_BIN = "python2.7"
PYTHON_PREFIX = "" # e.g. /usr/local Use "" for automatic
PYTHON_FULL_PATH = "%s/bin/%s" % (PYTHON_PREFIX, PYTHON_BIN) if PYTHON_PREFIX else PYTHON_BIN
# Commands to stop and start the webserver that is serving the Django app.
DJANGO_SERVER_STOP = posixpath.join(DJANGO_APP_ROOT, 'apache2', 'bin', 'stop')
DJANGO_SERVER_START = posixpath.join(DJANGO_APP_ROOT, 'apache2', 'bin', 'start')
DJANGO_SERVER_RESTART = None
src_dir = posixpath.join(DJANGO_APP_ROOT, SRC_SUBDIR)
def push_sources():
"""
Push source code to server
"""
run("rm -rf /home/jgraham32/webapps/handprints_app/handprints")
run("git clone https://[email protected]/josh_graham/handprints.git /home/jgraham32/webapps/handprints_app/handprints")
def update_database():
"""
Update the database using syncdb and south
"""
run("python2.7 /home/jgraham32/webapps/handprints_app/handprints/manage.py syncdb")
#run("python2.7 /home/jgraham32/webapps/handprints_app/handprints/manage.py migrate")
def install_dependencies():
"""
Install required packages
"""
run("pip install -r /home/jgraham32/webapps/handprints_app/handprints/requirements.txt")
@task
def webserver_stop():
"""
Stop the webserver that is running the Django instance
"""
run(DJANGO_SERVER_STOP)
@task
def webserver_start():
"""
Starts the webserver that is running the Django instance
"""
run(DJANGO_SERVER_START)
@task
def webserver_restart():
"""
Restarts the webserver that is running the Django instance
"""
if DJANGO_SERVER_RESTART:
run(DJANGO_SERVER_RESTART)
else:
with settings(warn_only=True):
webserver_stop()
webserver_start()
def build_static():
assert STATIC_ROOT.strip() != '' and STATIC_ROOT.strip() != '/'
# Before Django 1.4 we don't have the --clear option to collectstatic
run("rm -rf %s/*" % STATIC_ROOT)
with cd(src_dir):
run("python2.7 ./manage.py collectstatic -v 0 --noinput")
run("chmod -R ugo+r %s" % STATIC_ROOT)
@task
def deploy():
"""
Deploy project.
"""
with settings(warn_only=True):
webserver_stop()
push_sources()
#install_dependencies()
update_database()
build_static()
webserver_start()