snipt/fabfile.py

87 lines
2.3 KiB
Python
Raw Normal View History

2013-04-14 20:35:05 -07:00
#!/usr/bin/env python
# -- coding: utf-8 --
2012-09-18 16:22:55 -07:00
from fabric.api import cd, local, env, run, sudo
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
2013-04-14 20:35:05 -07:00
import datetime, hashlib, sys
2012-04-26 19:49:43 -07:00
2013-03-25 18:41:29 -07:00
from settings_local import AMAZON_API_KEY, AMAZON_API_SECRET, ENV_HOST
2011-10-23 20:07:59 -07:00
2012-09-18 13:45:00 -07:00
env.hosts = [ENV_HOST]
2014-09-26 08:49:09 -07:00
env.site_path = '/home/nick/snipt'
2012-03-05 13:57:18 -08:00
2013-04-14 20:35:05 -07:00
2012-04-29 08:03:17 -07:00
def dep():
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-07 16:17:27 -07:00
try:
2012-04-29 08:28:27 -07:00
local('git push')
2012-04-07 16:17:27 -07:00
except:
pass
2012-03-05 13:57:18 -08:00
2012-03-05 13:48:03 -08:00
with cd(env.site_path):
2012-04-29 08:05:07 -07:00
run('git pull')
2014-09-26 08:46:15 -07:00
run('/home/nick/snipt/.docker/control.sh collectstatic')
run('/home/nick/snipt/.docker/control.sh deploy')
2012-03-05 13:57:18 -08:00
2013-04-14 20:35:05 -07:00
def db_backup():
filename = datetime.datetime.now().strftime('%h-%d-%y__%I-%M-%S_%p.pgdump')
2014-09-26 08:49:09 -07:00
path = '/home/nick/snipt/{}'.format(filename)
2014-09-30 13:06:12 -07:00
local('/home/nick/snipt/.docker/control.sh backupdb > {}'.format(path))
2013-04-14 20:35:05 -07:00
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)
2014-09-26 08:49:09 -07:00
local('rm {}'.format(path))
2013-04-14 20:35:05 -07:00
2012-05-24 20:21:56 -07:00
def db():
with cd(env.site_path):
2014-09-26 08:46:15 -07:00
run('/home/nick/snipt/.docker/control.sh syncdb')
run('/home/nick/snipt/.docker/control.sh migrate')
2012-05-24 20:21:56 -07:00
2013-04-14 20:35:05 -07:00
def gravatars():
2012-04-29 08:28:27 -07:00
2013-04-14 20:35:05 -07:00
from fabric.contrib import django
django.settings_module('settings')
2012-04-29 08:28:27 -07:00
2013-04-14 20:35:05 -07:00
from django.contrib.auth.models import User
2012-04-29 08:28:27 -07:00
2013-04-14 20:35:05 -07:00
import requests
for user in User.objects.all().order_by('id'):
email_md5 = hashlib.md5(user.email.lower()).hexdigest()
2012-04-26 19:49:43 -07:00
2013-04-14 20:35:05 -07:00
print 'Email MD5: {}'.format(email_md5)
2012-04-26 19:49:43 -07:00
greq = requests.get('https://secure.gravatar.com/avatar/{}?s=50&d=404'.format(email_md5))
2012-04-26 19:49:43 -07:00
if greq.status_code == 404:
has_gravatar = False
2013-04-14 20:35:05 -07:00
else:
has_gravatar = True
2012-04-29 13:25:56 -07:00
profile = user.profile
profile.has_gravatar = has_gravatar
profile.save()
2012-04-29 08:28:27 -07:00
2013-04-14 20:35:05 -07:00
try:
from fabric.colors import green, red
if has_gravatar:
print 'Has Gravatar: {}'.format(green(has_gravatar))
else:
print 'Has Gravatar: {}'.format(red(has_gravatar))
except ImportError:
print 'Has Gravatar: {}'.format(has_gravatar)
def re():
with cd(env.site_path):
2014-09-26 08:46:15 -07:00
run('/home/nick/snipt/.docker/control.sh restart')