This repository has been archived by the owner on Oct 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
fabfile.py
71 lines (54 loc) · 2.17 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
import os
import secrets as local_secrets
from fabric.api import *
from fabric.contrib import django
from fabric.contrib.project import rsync_project
from urlparse import urlparse
# requires GitPython to be installed: https://github.com/gitpython-developers/GitPython
from git import Repo
remote_url = Repo().remotes.origin.url
parsed = urlparse(remote_url)
remote_path = parsed.path
if parsed.netloc:
remote_host = parsed.netloc
else:
remote_host = parsed.scheme
django.settings_module('%s.settings' % local_secrets.APP_MODULE)
from django.conf import settings
south_installed = 'south' in settings.INSTALLED_APPS
env.hosts = [remote_host]
def update_db():
get(os.path.join(remote_path, 'secrets.py') , 'remote_secrets.py')
execfile('remote_secrets.py')
remote_db = locals()['DATABASES']['default']
run('mysqldump -u %(USER)s -p%(PASSWORD)s -h %(HOST)s %(NAME)s --ignore-table=%(NAME)s.django_session > /tmp/%(NAME)s.sql'
% remote_db)
get('/tmp/%(NAME)s.sql' % remote_db, '/tmp/%(NAME)s.sql' % remote_db)
local('mysql -u root %(NAME)s < /tmp/%(NAME)s.sql' % remote_db)
local('rm remote_secrets.py')
def update_media():
local('rsync -pthrvz %(user)s@%(host)s:%(source)s %(destination)s' % {
'user' : env.local_user,
'host' : remote_host,
'source' : os.path.join(remote_path, 'media/medialibrary'),
'destination' : 'media/'
})
def update_all():
update_db()
update_media()
def publish():
local('git push')
with cd(remote_path):
run('git merge %s' % env.local_user)
run('git submodule update --init')
run('%s/manage.py collectstatic --noinput' % local_secrets.APP_MODULE)
run('%s/manage.py syncdb' % local_secrets.APP_MODULE)
if south_installed:
run('%s/manage.py migrate' % local_secrets.APP_MODULE)
run('touch runner.wsgi')
def push_db():
dbname = local_secrets.DATABASES['default']['NAME']
local('mysqldump -u root %s > /tmp/%s.sql' % (dbname, dbname))
put('/tmp/%s.sql' % dbname, '/tmp/%s-fromdev.sql' % dbname)
with cd(remote_path):
run('%s/manage.py dbshell < /tmp/%s-fromdev.sql' % (local_secrets.APP_MODULE, dbname))