forked from numbas/editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfabfile.py.dist
86 lines (73 loc) · 2.21 KB
/
fabfile.py.dist
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
from fabric.api import *
from fabric.contrib.console import confirm
import json
"""
fabhosts.json should look like:
{
"hosts": {
"hostname": {
"numbas_path": path to numbas on server,
"editor_path": path to numbas_editor on server,
"python": path of python executable to use with Django
},
etc...
},
"roledefs": {
alias: hostname
}
}
"""
# load host settings
try:
config = json.loads(open('fabhosts.json').read())
env.hosts_settings = config['hosts']
env.roledefs = config['roledefs']
#if no hosts given on command-line, use all hosts defined in the setting file
if len(env.hosts)==len(env.roles)==0:
env.hosts = list(env.hosts_settings.keys())
except IOError:
pass # no hosts defined, so tasks will run on localhost only
# decorator to get settings for current host and put them in env.host_settings
def with_host_settings(f):
def inner(*args,**kwargs):
env.host_settings = env.hosts_settings[env.host]
return f(*args,**kwargs)
return inner
# update the Numbas compiler on the server
@with_host_settings
def update_numbas(branch=None):
path = env.host_settings['numbas_path']
with cd(path):
if branch is None:
branch = current_branch()
run('git checkout %s' % branch)
run('git pull readonly %s' % branch)
# update the editor on the server
@with_host_settings
def update_editor(branch=None):
path = env.host_settings['editor_path']
python = env.host_settings['python']
with cd(path):
if branch is None:
branch = current_branch()
with hide('stdout'):
run('git checkout %s' % branch)
run('git pull readonly %s' % branch)
run('%s manage.py syncdb' % python)
run('%s manage.py migrate editor' % python)
run('%s manage.py migrate accounts' % python)
run('%s manage.py collectstatic --noinput' % python)
run('touch web/django.wsgi')
# run a django management command
@with_host_settings
def manage(cmd):
path = env.host_settings['editor_path']
python = env.host_settings['python']
with cd(path):
run('%s manage.py %s' % (python,cmd))
def latest_users():
manage('latestusers')
# get the current branch of the git repository in current directory
def current_branch():
with hide('running', 'stdout', 'stderr'):
return run('git rev-parse --abbrev-ref HEAD')