snipt/fabfile.py

98 lines
2.2 KiB
Python
Raw Normal View History

2012-04-29 08:28:27 -07:00
from fabric.api import cd, local, env, run
2011-10-23 20:13:37 -07:00
2012-04-29 13:25:56 -07:00
from boto.s3.connection import S3Connection
from boto.s3.key import Key
2012-04-29 13:27:48 -07:00
import datetime, sys
2012-04-26 19:49:43 -07:00
2011-10-23 20:07:59 -07:00
2012-04-08 14:41:25 -07:00
env.hosts = ['nick@snipt.net:39039']
2012-03-05 13:48:03 -08:00
env.site_path = '/var/www/snipt'
2012-03-05 13:57:18 -08:00
env.venv_path = '/home/nick/.virtualenvs/snipt'
2012-01-25 07:20:52 -08:00
2012-03-05 13:57:18 -08:00
def _python(cmd):
return env.venv_path.rstrip('/') + '/bin/python ' + cmd
2012-04-29 08:03:17 -07:00
def dep():
2012-04-29 08:28:27 -07:00
_display_message('Collect static')
################
2012-06-05 12:47:07 -07:00
local('python manage.py collectstatic --ignore cache --noinput')
2012-03-05 13:57:18 -08:00
2012-04-29 08:28:27 -07:00
_display_message('Git push')
################
2012-04-07 16:17:27 -07:00
try:
2012-04-29 08:28:27 -07:00
local('git push')
_display_message('Get last commit info')
################
local('./get-last-commit-url.py')
2012-04-07 16:17:27 -07:00
except:
pass
2012-03-05 13:57:18 -08:00
2012-04-29 08:28:27 -07:00
print('')
2012-03-05 13:48:03 -08:00
with cd(env.site_path):
2012-04-29 08:28:27 -07:00
_display_message('Git pull')
################
2012-04-29 08:05:07 -07:00
run('git pull')
2012-04-29 08:28:27 -07:00
_display_message('Collect static', False)
################
2012-06-05 12:47:07 -07:00
run(_python('manage.py collectstatic --ignore cache --noinput'))
2012-03-05 13:57:18 -08:00
2012-05-24 20:21:56 -07:00
def db():
with cd(env.site_path):
_display_message('Sync DB and migrate')
################
run(_python('manage.py syncdb'))
run(_python('manage.py migrate'))
2012-03-12 21:16:19 -07:00
def re():
with cd(env.site_path):
2012-04-29 08:28:27 -07:00
_display_message('Kill gunicorn process')
################
2012-04-29 08:03:08 -07:00
run('./gk')
2012-04-29 08:28:27 -07:00
_display_message('Restart gunicorn process')
################
2012-04-29 08:03:08 -07:00
run('/home/nick/.virtualenvs/snipt/bin/python /home/nick/.virtualenvs/snipt/bin/gunicorn -c gunicorn.conf.py debug_wsgi:application')
2012-04-26 19:49:43 -07:00
def db_backup():
2012-04-29 13:25:56 -07:00
filename = datetime.datetime.now().strftime('%h-%d-%y__%I-%M-%S_%p.pgdump')
2012-04-26 19:49:43 -07:00
2012-04-29 13:25:56 -07:00
local('pg_dump snipt > {}'.format(filename))
2012-04-26 19:49:43 -07:00
2012-04-29 13:27:48 -07:00
conn = S3Connection('AKIAJJRRQPTSPKB7GYOA', 'DIYz2g5vPjcWE4/YI7wEuUVAskwJxs2llFvGyI1a')
snipt_bucket = conn.get_bucket('snipt')
2012-04-26 19:49:43 -07:00
2012-04-29 13:27:48 -07:00
k = Key(snipt_bucket)
k.key = filename
2012-04-29 13:27:48 -07:00
k.set_contents_from_filename(filename)
2012-04-29 13:25:56 -07:00
local('rm {}'.format(filename))
2012-04-29 08:28:27 -07:00
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)