import sys

from fabric.api import *
from fabric.colors import red, green
import requests

web = ['openhealthcare.org.uk']
serves = [
    'http://openhealthcare.org.uk',
    'http://prescriptions.openhealthcare.org.uk'
    ]

def manage(what):
    """
    Run a manage.py command

    Return: None
    Exceptions: None
    """
    with cd('/var/apps/nhs-prescriptions/nhs-prescriptions/nhs'):
        run('./venv/bin/python manage.py {0}'.format(what))


@hosts(web)
def deploy():
    """
    Make it so!

    Return: None
    Exceptions: None
    """
    # FIXME stop deploying out of git for atomicity.
    with cd('/var/apps/nhs-prescriptions/nhs-prescriptions'):
        sudo('git pull github master') #not ssh - key stuff
        sudo('chown ross:ross .') # !!! FIXME
        sudo('/etc/init.d/apache2 reload')
    for site in serves:
        req = requests.get(site)
        if req.status_code != 200:
            print red("Cripes! something just blew up Larry! ({0})".format(site))
            sys.exit(1)
    print green("Deploy-o-rama!")



@hosts(web)
def migrate():
    """
    Update to latest please

    Return: None
    Exceptions: None
    """
    manage('syncdb')
    manage('migrate')
    manage('create_groups')

@@ -97,31 +97,38 @@
  %5B'o
-penhealthcare.org.uk
+hc@horsell.scraperwiki.com
 '%5D%0A
+%0A
 serv
@@ -150,80 +150,24 @@
 p://
-openhealthcare.org.uk',%0A    'http://prescriptions.openhealthcare.org.uk'
+localhost:4567',
 %0A   
@@ -289,34 +289,27 @@
 d('/
-var/apps/nhs-prescriptions
+usr/local/ohc/scrip
 /nhs
@@ -347,14 +347,36 @@
 un('
-./venv
+/home/ohc/.virtualenvs/scrip
 /bin
@@ -582,16 +582,21 @@
 d('/
-var/apps
+usr/local/ohc
 /nhs
@@ -639,20 +639,19 @@
         
-sudo
+run
 ('git pu
@@ -657,14 +657,11 @@
 ull 
-github
+ohc
  mas
@@ -699,86 +699,185 @@
     
-sudo('chown ross:ross .') # !!! FIXME%0A        sudo('/etc/init.d/apache2 reload
+run('pkill gunicorn')%0A    with cd('/usr/local/ohc/nhs-prescriptions/nhs-prescriptions/nhs'):%0A        run('/home/ohc/.virtualenvs/scrip/bin/gunicorn_django -D -c gunicorn_conf.py
 ')%0A 

Update fabfile to deploy@Scraperwiki