import os
from contextlib import contextmanager as _contextmanager
-from fabric.api import cd, env, prefix, run, settings, task
+from fabric.api import cd, env, prefix, run, settings, task, local
########## GLOBALS
env.proj_repo = 'git@github.com:FinalsClub/karmaworld.git'
env.virtualenv = 'venv-kw'
env.activate = 'workon %s' % env.virtualenv
+
+# Using this env var to be able to specify the function
+# used to run the commands. By default it's `run`, which
+# runs commands remotely, but in the `here` task we set
+# env.run to `local` to run commands locally.
+env.run = run
########## END GLOBALS
########## END HELPERS
########## ENVIRONMENTS
+@task
+def here():
+ """
+ Connection information for the local machine
+ """
+ env.proj_dir = os.getcwd()
+ env.proj_root = os.path.dirname(env.proj_dir)
+ env.run = local
+ env.reqs = 'reqs/dev.txt'
+
+
@task
def beta():
"""
env.hosts = ['beta.karmanotes.org']
env.proj_root = '/var/www/karmaworld'
env.proj_dir = os.path.join(env.proj_root, 'karmaworld')
+ env.reqs = 'reqs/prod.txt'
@task
env.hosts = ['karmanotes.org']
env.proj_root = '/var/www/karmaworld'
env.proj_dir = os.path.join(env.proj_root, 'karmaworld')
+ env.reqs = 'reqs/prod.txt'
########## END ENVIRONMENTS
@task
def syncdb():
"""Runs syncdb (along with any pending South migrations)"""
- run('python manage.py syncdb --noinput --migrate')
+ env.run('python manage.py syncdb --noinput --migrate')
########## END DATABASE MANAGEMENT
@task
def collectstatic():
"""Collect all static files, and copy them to S3 for production usage."""
- run('python manage.py collectstatic --noinput')
+ env.run('python manage.py collectstatic --noinput')
########## END FILE MANAGEMENT
"""
Creates a virtualenv on the remote host
"""
- run('mkvirtualenv %s' % env.virtualenv)
+ env.run('mkvirtualenv %s' % env.virtualenv)
@task
"""
with _virtualenv():
with cd(env.proj_dir):
- run('pip install -r requirements/production.pip')
+ env.run('pip install -r %s' % env.reqs)
@task
"""
Clones the project from the central repository
"""
- run('git clone %s %s' % (env.proj_repo, env.proj_dir))
+ env.run('git clone %s %s' % (env.proj_repo, env.proj_dir))
@task
Pulls the latest changes from the central repository
"""
with cd(env.proj_dir):
- run('git pull')
+ env.run('git pull')
@task
"""
first_deploy = False
with settings(warn_only=True):
- if run('test -d %s' % env.proj_dir).failed:
+ if env.run('test -d %s' % env.proj_dir).failed:
# first_deploy var is for initial deploy information
first_deploy = True
clone()
- if run('test -d $WORKON_HOME/%s' % env.virtualenv).failed:
+ if env.run('test -d $WORKON_HOME/%s' % env.virtualenv).failed:
make_virtualenv()
update_code()