forked from MSylvia/snipt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
111 lines (73 loc) · 2.64 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 fabric.api import cd, local, env, run, sudo
from boto.s3.connection import S3Connection
from boto.s3.key import Key
import datetime, sys
from local_settings import AMAZON_API_KEY, AMAZON_API_SECRET, ENV_HOST
env.hosts = [ENV_HOST]
env.site_path = '/var/www/snipt'
env.venv_path = '/home/nick/.virtualenvs/snipt'
def _python(cmd):
return env.venv_path.rstrip('/') + '/bin/python ' + cmd
def dep():
_display_message('Compiling CSS')
################
local('scss -t compressed media/css/style.scss media/css/style.css')
local('scss -t compressed media/css/blog-themes/default/style.scss media/css/blog-themes/default/style.css')
local('scss -t compressed media/css/blog-themes/pro-adams/style.scss media/css/blog-themes/pro-adams/style.css')
local('media/css/compile-css.sh')
try:
local('git commit -am "Compiling CSS."')
except:
pass
_display_message('Collect static')
################
local('python manage.py collectstatic --ignore cache --noinput')
_display_message('Git push')
################
try:
local('git push')
_display_message('Get last commit info')
################
except:
pass
print('')
with cd(env.site_path):
_display_message('Git pull')
################
run('git pull')
_display_message('Collect static', False)
################
run(_python('manage.py collectstatic --ignore cache --noinput'))
def db():
with cd(env.site_path):
_display_message('Sync DB and migrate')
################
run(_python('manage.py syncdb'))
run(_python('manage.py migrate'))
def re():
with cd(env.site_path):
_display_message('Kill gunicorn process')
################
sudo('supervisorctl stop snipt')
_display_message('Restart gunicorn process')
################
sudo('supervisorctl start snipt')
def db_backup():
filename = datetime.datetime.now().strftime('%h-%d-%y__%I-%M-%S_%p.pgdump')
local('pg_dump snipt > {}'.format(filename))
conn = S3Connection(AMAZON_API_KEY, AMAZON_API_SECRET)
snipt_bucket = conn.get_bucket('snipt')
k = Key(snipt_bucket)
k.key = filename
k.set_contents_from_filename(filename)
local('rm {}'.format(filename))
def _display_message(message, extra_line=True):
if extra_line:
msg = '\n{}\n========================\n\n'.format(message)
else:
msg = '{}\n========================\n\n'.format(message)
try:
from fabric.colors import cyan
sys.stderr.write(cyan(msg))
except ImportError:
print(msg)