diff --git a/fabfile.py b/fabfile.py index 9f86381..0d8d968 100644 --- a/fabfile.py +++ b/fabfile.py @@ -1,8 +1,10 @@ + +from fabric.operations import put from fabric.api import run, sudo, env from fabric.contrib.files import exists -from fabric.context_managers import prefix, cd from fabric.decorators import with_settings +from fabric.context_managers import prefix, cd env.user = 'colab' # key depends on env env.use_shell = False @@ -30,21 +32,56 @@ def environment(name): environment('dev') -def install(): - if not exists('~colab/.virtualenvs/colab'): +def mkvirtualenv(): + if not exists('~/.virtualenvs/colab'): with prefix(SOURCE_VENV): run('mkvirtualenv colab') + return True + + +def install(local_settings=None): + env_created = mkvirtualenv() + + if not exists('~/colab'): + run('git clone https://github.com/TracyWebTech/colab ~/colab') + + if local_settings: + put(local_settings, '~/colab/src/colab/local_settings.py') - if not exists('~colab/colab'): - run('git clone https://github.com/TracyWebTech/colab ~colab/colab') + if env_created: + update_requirements() - sudo('supervisorctl reload', shell=False ) + sudo('supervisorctl reload', shell=False) -def deploy(): - with cd('~colab/colab'): +def update_requirements(): + with cd('~/colab'), prefix(WORKON_COLAB): + run('pip install -r requirements.txt') + + +def deploy(update=False): + if update: + update_requirements() + + with cd('~/colab/src/'), prefix(WORKON_COLAB): run('git pull') + run('python manage.py syncdb') + run('python manage.py migrate') + run('python manage.py collectstatic --noinput') + + sudo('supervisorctl restart all') + + +@with_settings(user='vagrant') +def runserver(update_requirements=False): + env_created = mkvirtualenv() + + with cd('/vagrant/src/'), prefix(WORKON_COLAB): - with prefix(WORKON_COLAB): - run('pip install -r ~colab/colab/requirements.txt') + # If explicitly called or if it's a new environment + if update_requirements or env_created: + run('pip install -r /vagrant/requirements.txt') + run('python manage.py syncdb') + run('python manage.py migrate') + run('python manage.py runserver 0.0.0.0:7000') -- libgit2 0.21.2