-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
135 lines (115 loc) · 5.23 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
from fabric.api import local, settings, env, roles, run, cd, hide, shell_env
import os
env.roledefs["web"] = ["sitar.s.upf.edu"]
env.roledefs["workers"] = ["itri.s.upf.edu", "devaraya.s.upf.edu", "amirkhusro.s.upf.edu", "kora.s.upf.edu", "guqin.s.upf.edu", "ziryab.s.upf.edu"]
env.use_ssh_config = True
env.forward_agent = True
def up(port="8001"):
local("python manage.py runserver 0.0.0.0:%s"%port)
def celery():
local("celery worker --app=dunya -l info")
def test(module=None, keepdb=True):
command = "python manage.py test --settings=dunya.test_settings --noinput"
if keepdb:
command += " --keepdb"
if module:
command += " %s" % module
if keepdb:
print "Keeping DB (if available), run cleantest to recreate schema"
local(command)
def cleantest(module=None):
test(module, False)
@roles("workers")
def pipinstall():
"""Install new dependencies added to requirements"""
env.user = "mtg_dunya"
with cd("/srv/dunya"):
run("env/bin/pip install -r requirements")
run("sudo supervisorctl restart dunya")
@roles("web")
def updateweb():
"""Update the webserver"""
env.user = "mtg_dunya"
with cd("/srv/dunya"):
run("git pull", pty=False)
# compile and compress less
# compress javascript
run("env/bin/python manage.py collectstatic --noinput")
run("env/bin/node env/bin/lessc carnatic/static/carnatic/css/main.less static/carnatic/css/main.css")
run("env/bin/node env/bin/lessc carnatic/static/carnatic/css/browse.less static/carnatic/css/browse.css")
run("env/bin/node env/bin/lessc carnatic/static/carnatic/css/recording.less static/carnatic/css/recording.css")
run("env/bin/node env/bin/lessc carnatic/static/carnatic/css/pages.less static/carnatic/css/pages.css")
run("env/bin/node env/bin/lessc carnatic/static/carnatic/css/presentation.less static/carnatic/css/presentation.css")
run("env/bin/node env/bin/lessc makam/static/makam/css/main.less static/makam/css/main.css")
run("env/bin/node env/bin/lessc makam/static/makam/css/browse.less static/makam/css/browse.css")
run("env/bin/node env/bin/lessc makam/static/makam/css/recording.less static/makam/css/recording.css")
run("env/bin/node env/bin/lessc makam/static/makam/css/pages.less static/makam/css/pages.css")
run("env/bin/node env/bin/lessc makam/static/makam/css/presentation.less static/makam/css/presentation.css")
with cd("/srv/dunya/env/src/pycompmusic"):
run("git pull", pty=False)
run("sudo supervisorctl restart dunya")
@roles("workers")
@roles("web")
def essentia(branch=None):
"""Update essentia on all workers"""
with cd("/srv/essentia"):
run("git pull", pty=False)
run("./waf -j4")
run("./waf install")
@roles("workers")
def updatecelery():
env.user = "mtg_dunya"
"""Update the code for celery on all workers and restart"""
with cd("/srv/dunya"):
run("git pull", pty=False)
with cd("/srv/dunya/env/src/pycompmusic"):
run("git pull", pty=False)
run("sudo supervisorctl restart dunyacelery")
def setupdb():
""" Run this when you are setting up a new installation
or have deleted your database
"""
local("python manage.py migrate")
def updatedb():
""" Run this when someone has committed some changes to the
database migration scripts
"""
local("python manage.py migrate")
def dumpfixture(modname):
redir_base = "%s/fixtures/%s_%%s.json" % (modname, modname)
if modname == "data":
redir = redir_base % "initial_data"
local("python manage.py dumpdata data.SourceName --indent=4 > %s" % redir)
elif modname == "carnatic":
tablemap = {"instrument": ["Instrument", "InstrumentAlias"],
"taala": ["Taala", "TaalaAlias"],
"raaga": ["Raaga", "RaagaAlias"],
"form": ["Form", "FormAlias"],
"misc": ["Language", "MusicalSchool"]}
elif modname == "hindustani":
tablemap = {"instrument": ["Instrument"],
"taal": ["Taal", "TaalAlias"],
"raag": ["Raag", "RaagAlias"],
"form": ["Form", "FormAlias"],
"laya": ["Laya", "LayaAlias"],
"section": ["Section", "SectionAlias"]}
elif modname == "makam":
tablemap = {"instrument": ["Instrument"],
"makam": ["Makam", "MakamAlias"],
"form": ["Form", "FormAlias"],
"usul": ["Usul", "UsulAlias"]}
for filename, tables in tablemap.items():
modellist = " ".join(["%s.%s[:]" % (modname, t) for t in tables])
redir = redir_base % filename
local("python manage.py makefixture %s --indent=4 > %s" % (modellist, redir))
def dumpdata(fname="dunya_data.json"):
with hide('running', 'status'):
modules = ["carnatic", "data", "docserver", "account", "auth", "dashboard"]
local("python manage.py dumpdata --indent=4 %s > %s" % (" ".join(modules), fname))
print "dumped data to %s" % fname
def loaddata(fname="dunya_data.json"):
print "Loading data from %s" % fname
if os.path.exists(fname):
local("python manage.py loaddata %s" % fname)
else:
print " (missing!)"