-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfabfile.py
113 lines (82 loc) · 3.16 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
111
112
113
# -*- coding: utf-8 -*-
from datetime import datetime
import sys
from fabric.api import env, run, local, task, cd, get
from fabric.contrib.console import confirm
from fabric.context_managers import lcd
from fabtools.python import virtualenv
import fab_settings
################################################################################
################################################################################
env.virtualenv_path = 'env'
env.user = fab_settings.USER
env.output_prefix = False
env.forward_agent = True
env.roledefs = fab_settings.ROLEDEFS
env.local_dumps_dir = fab_settings.DUMPS_DIR
################################################################################
################################################################################
@task
def start():
"""
Run application
"""
with virtualenv(env.virtualenv_path, local=True):
with lcd("./openode/"):
local("python manage.py runserver")
################################################################################
@task
def dump_db():
ctx = env
ctx['timestamp'] = datetime.now().strftime('%Y_%m_%d_%H_%M_%S')
ctx['tar_name'] = '%(user)s_db_dump_%(timestamp)s.tar' % ctx
with cd("~/dumps"):
run('pg_dump -U %(user)s -Ox -Ft -f %(tar_name)s %(user)s' % ctx)
run('gzip %(tar_name)s' % ctx)
return ctx
@task
def update_locale_db():
"""
Create databaze dump on production server and restore on development (local) machine
"""
ctx = env
ctx.update(dump_db())
ctx['gz_name'] = '%(tar_name)s.gz' % ctx
local("mkdir -p %(local_dumps_dir)s" % env)
get("~/dumps/%(gz_name)s" % ctx, local_path=env.local_dumps_dir)
local("gzip -d %(local_dumps_dir)s/%(gz_name)s" % ctx)
local('psql -d openode -c "DROP SCHEMA public CASCADE; CREATE SCHEMA public;"')
local("pg_restore -O -d openode %(local_dumps_dir)s/%(tar_name)s" % ctx)
################################################################################
@task
def create_tag():
sys.stdout.write("Current tags:\n")
local('git tag -l')
version = raw_input("Enter name of new tag: ")
local('git tag -a "%s"' % version)
if confirm("Call git push --tags "
"and send information to remote server?", default=False):
local('git push --tags')
################################################################################
@task
def deploy():
"""
TODO: add all related commands
"""
if confirm('Create tag for this release?', default=False):
create_tag()
if confirm('Backup DB?', default=False):
dump_db()
if confirm("Start deploying to remote server?"):
with cd("cgi-bin"):
run("git pull")
alter_sql_path = "alter.sql"
if confirm('Show alter.sql file?', default=False):
print 40 * "-"
run("cat %s" % alter_sql_path)
print 40 * "-"
if confirm('Execute alter.sql file?', default=False):
run("psql -f %s" % alter_sql_path)
with virtualenv(env.virtualenv_path):
run("compilemessages.sh")
run("./reload_webserver.py")