/
fabfile.py
82 lines (57 loc) · 2.01 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
from fabric.api import *
from functools import wraps
import os, sys
__all__ = ['deploy','run','collectstatic']
def patch_python_path(f):
@wraps(f)
def wrap(*args, **kwargs):
ROOT = os.pathsep.join([os.path.abspath(os.path.dirname(__file__))])
if not os.environ.has_key("PYTHONPATH"):
os.environ["PYTHONPATH"] = ""
if not (ROOT in os.environ["PYTHONPATH"].split(":")):
os.environ["PYTHONPATH"] = "%s:%s" % (os.environ["PYTHONPATH"], ROOT)
if not ROOT in sys.path:
sys.path.append(ROOT)
return f(*args, **kwargs)
return wrap
@patch_python_path
def deploy():
from tools.git import check_git_state, is_git_clean
from tools.database import needsdatabase, local_migrate, remote_migrate, remote_syncdb
from tools.apps import enumerate_apps
@check_git_state
@needsdatabase
def __deploy():
print "Deploying your application"
print "----------------------------"
print "Migrations..."
for app in enumerate_apps():
local_migrate(app)
if is_git_clean():
print "Pushing code on Heroku"
local("git push heroku master")
else:
print "Committing migrations..."
#local("git add .")
#local("git commit -a -m '[DHB] data migrations'")
print "Sync remote database"
remote_syncdb()
for app in enumerate_apps():
remote_migrate(app)
__deploy()
@patch_python_path
def run():
print sys.path
from tools.database import needsdatabase, local_migrate
from tools.apps import enumerate_apps
from tools.heroku import start_foreman
@needsdatabase
def __run():
for app in enumerate_apps():
with settings(warn_only=True):
local_migrate(app)
start_foreman()
__run()
@patch_python_path
def collectstatic():
local("python manage.py collectstatic --noinput --settings=settings.static")