Commit 80e87f3d974ee47776d546ebeb3cea85050a96a2

Authored by Sergio Oliveira
1 parent 84381809

Updating fabric

Tasks to run django with runserver
Showing 1 changed file with 47 additions and 10 deletions   Show diff stats
1 1
  2 +
  3 +from fabric.operations import put
2 from fabric.api import run, sudo, env 4 from fabric.api import run, sudo, env
3 from fabric.contrib.files import exists 5 from fabric.contrib.files import exists
4 -from fabric.context_managers import prefix, cd  
5 from fabric.decorators import with_settings 6 from fabric.decorators import with_settings
  7 +from fabric.context_managers import prefix, cd
6 8
7 env.user = 'colab' # key depends on env 9 env.user = 'colab' # key depends on env
8 env.use_shell = False 10 env.use_shell = False
@@ -30,21 +32,56 @@ def environment(name): @@ -30,21 +32,56 @@ def environment(name):
30 environment('dev') 32 environment('dev')
31 33
32 34
33 -def install():  
34 - if not exists('~colab/.virtualenvs/colab'): 35 +def mkvirtualenv():
  36 + if not exists('~/.virtualenvs/colab'):
35 with prefix(SOURCE_VENV): 37 with prefix(SOURCE_VENV):
36 run('mkvirtualenv colab') 38 run('mkvirtualenv colab')
  39 + return True
  40 +
  41 +
  42 +def install(local_settings=None):
  43 + env_created = mkvirtualenv()
  44 +
  45 + if not exists('~/colab'):
  46 + run('git clone https://github.com/TracyWebTech/colab ~/colab')
  47 +
  48 + if local_settings:
  49 + put(local_settings, '~/colab/src/colab/local_settings.py')
37 50
38 - if not exists('~colab/colab'):  
39 - run('git clone https://github.com/TracyWebTech/colab ~colab/colab') 51 + if env_created:
  52 + update_requirements()
40 53
41 - sudo('supervisorctl reload', shell=False ) 54 + sudo('supervisorctl reload', shell=False)
42 55
43 56
44 -def deploy():  
45 - with cd('~colab/colab'): 57 +def update_requirements():
  58 + with cd('~/colab'), prefix(WORKON_COLAB):
  59 + run('pip install -r requirements.txt')
  60 +
  61 +
  62 +def deploy(update=False):
  63 + if update:
  64 + update_requirements()
  65 +
  66 + with cd('~/colab/src/'), prefix(WORKON_COLAB):
46 run('git pull') 67 run('git pull')
  68 + run('python manage.py syncdb')
  69 + run('python manage.py migrate')
  70 + run('python manage.py collectstatic --noinput')
  71 +
  72 + sudo('supervisorctl restart all')
  73 +
  74 +
  75 +@with_settings(user='vagrant')
  76 +def runserver(update_requirements=False):
  77 + env_created = mkvirtualenv()
  78 +
  79 + with cd('/vagrant/src/'), prefix(WORKON_COLAB):
47 80
48 - with prefix(WORKON_COLAB):  
49 - run('pip install -r ~colab/colab/requirements.txt') 81 + # If explicitly called or if it's a new environment
  82 + if update_requirements or env_created:
  83 + run('pip install -r /vagrant/requirements.txt')
50 84
  85 + run('python manage.py syncdb')
  86 + run('python manage.py migrate')
  87 + run('python manage.py runserver 0.0.0.0:7000')