fabfile.py 1.67 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
#!/usr/bin/env python
'''Download/sync to git repository
Create/update virtualenv
django syncdb collectstatic'''

import os
from fabric.api import env, local, run, settings, cd, lcd, sudo
import sys
if sys.version_info[:2] == (2, 6):
        from contextlib import nested

name = 'flyers'
repository = 'http://git.domainepublic.net/git/%s.git' % name
directory = os.path.abspath(os.path.join(os.path.dirname(__file__), name))


def prod():
    env.user = 'chris'
    env.hosts = ['domainepublic.net']
    env.port = 3265
    global directory
    directory = '/var/alternc/html/c/chris/test'


def deploy_remote():
    with settings(warn_only=True):
        if sudo("test -d %s" % directory).failed:
            sudo("git clone %s %s" % (repository, directory))
    with settings(warn_only=True), cd(directory):
        if sudo("test -d %s/env" % directory).failed:
            sudo('virtualenv env')
    run('echo "currently web folders are not owned by their owners"')
    with cd(directory):
        sudo('git pull')
        sudo('touch %s/wsgi.py' % name)
        #sudo('chown -R www-data .')
        sudo('mkdir -p media/uploads')
        sudo('env/bin/pip install -r requirements.txt')
        sudo('env/bin/python manage.py collectstatic --noinput')
        sudo('env/bin/python manage.py syncdb --noinput')


def deploy_local():
    with settings(warn_only=True):
        if local("test -d %s" % directory).failed:
            local("git clone %s %s" % (repository, directory))
    with lcd(directory):
        local('git pull')
        local('touch %s/wsgi.py' % name)


def deploy():
    if env.hosts:
        deploy_remote()
    else:
        deploy_local()


if __name__ == "__main__":
    deploy()