1 """Management utilities."""
4 from contextlib import contextmanager as _contextmanager
6 from fabric.api import cd, env, prefix, run, settings, task, local
10 env.proj_repo = 'git@github.com:FinalsClub/karmaworld.git'
11 env.virtualenv = 'venv-kw'
12 env.activate = 'workon %s' % env.virtualenv
14 # Using this env var to be able to specify the function
15 # used to run the commands. By default it's `run`, which
16 # runs commands remotely, but in the `here` task we set
17 # env.run to `local` to run commands locally.
19 ########## END GLOBALS
26 Changes to the proj_dir and activates the virtualenv
28 with cd(env.proj_dir):
29 with prefix(env.activate):
32 ########## END HELPERS
34 ########## ENVIRONMENTS
38 Connection information for the local machine
40 env.proj_dir = os.getcwd()
41 env.proj_root = os.path.dirname(env.proj_dir)
43 env.reqs = 'reqs/dev.txt'
44 env.confs = 'confs/dev/'
51 Beta connection information
54 env.hosts = ['beta.karmanotes.org']
55 env.proj_root = '/var/www/karmaworld'
56 env.proj_dir = os.path.join(env.proj_root, 'karmaworld')
57 env.reqs = 'reqs/prod.txt'
58 env.confs = 'confs/beta/'
65 Production connection information
68 env.hosts = ['karmanotes.org']
69 env.proj_root = '/var/www/karmaworld'
70 env.proj_dir = os.path.join(env.proj_root, 'karmaworld')
71 env.reqs = 'reqs/prod.txt'
72 env.confs = 'confs/prod/'
74 ########## END ENVIRONMENTS
77 ########## DATABASE MANAGEMENT
80 """Runs syncdb (along with any pending South migrations)"""
81 env.run('python manage.py syncdb --noinput --migrate')
82 ########## END DATABASE MANAGEMENT
85 ########## FILE MANAGEMENT
95 """Collect all static files, and copy them to S3 for production usage."""
96 env.run('python manage.py collectstatic --noinput')
100 def compress_static():
102 Compresses the static files.
110 Uploads the static files to the specified host.
113 ########## END FILE MANAGEMENT
119 def make_virtualenv():
121 Creates a virtualenv on the remote host
123 env.run('mkvirtualenv %s' % env.virtualenv)
129 Makes sure all packages listed in requirements are installed
132 with cd(env.proj_dir):
133 env.run('pip install -r %s' % env.reqs)
139 Clones the project from the central repository
141 env.run('git clone %s %s' % (env.proj_repo, env.proj_dir))
147 Pulls the latest changes from the central repository
149 with cd(env.proj_dir):
156 Creates or updates the project, runs migrations, installs dependencies.
159 with settings(warn_only=True):
160 if env.run('test -d %s' % env.proj_dir).failed:
161 # first_deploy var is for initial deploy information
164 if env.run('test -d $WORKON_HOME/%s' % env.virtualenv).failed:
172 ########## END COMMANDS