"""
from subprocess import check_output
from os.path import abspath, dirname, exists, join
"""
from subprocess import check_output
from os.path import abspath, dirname, exists, join
-from fabric.api import *
+from fabric.api import env, task, require, run, cd, abort, sudo, path, local, put
from fabric.context_managers import settings
from fabric.contrib import files
from fabric.tasks import Task, execute
from fabric.context_managers import settings
from fabric.contrib import files
from fabric.tasks import Task, execute
class DebianGunicorn(Service):
def __init__(self, name):
super(Task, self).__init__()
class DebianGunicorn(Service):
def __init__(self, name):
super(Task, self).__init__()
class Apache(Service):
def run(self):
print '>>> restart webserver by touching WSGI'
with path('/sbin'):
run('touch %(app_path)s/%(project_name)s/wsgi.py' % env)
class Apache(Service):
def run(self):
print '>>> restart webserver by touching WSGI'
with path('/sbin'):
run('touch %(app_path)s/%(project_name)s/wsgi.py' % env)
class Supervisord(Service):
def __init__(self, name):
super(Task, self).__init__()
class Supervisord(Service):
def __init__(self, name):
super(Task, self).__init__()
print '>>> supervisord: restart %s' % self.name
sudo('supervisorctl restart %s' % self.name, shell=False)
print '>>> supervisord: restart %s' % self.name
sudo('supervisorctl restart %s' % self.name, shell=False)
if not hasattr(commands, '__iter__'):
commands = [commands]
self.name = 'Command: %s @ %s' % (commands, working_dir)
if not hasattr(commands, '__iter__'):
commands = [commands]
self.name = 'Command: %s @ %s' % (commands, working_dir)
def upload_sample(name, where="samples/", ext='.sample', **kwargs):
require('app_path', 'project_name')
upload_path = '%s/%s%s%s' % (env['app_path'], where, name, ext)
def upload_sample(name, where="samples/", ext='.sample', **kwargs):
require('app_path', 'project_name')
upload_path = '%s/%s%s%s' % (env['app_path'], where, name, ext)
template = join(dirname(abspath(__file__)), 'templates/' + name + '.template')
files.upload_template(template, upload_path, env, **kwargs)
template = join(dirname(abspath(__file__)), 'templates/' + name + '.template')
files.upload_template(template, upload_path, env, **kwargs)
env.secret_key = get_random_string(50)
upload_sample('localsettings.py', where="")
env.secret_key = get_random_string(50)
upload_sample('localsettings.py', where="")
print '>>> upload tar from git'
require('release', provided_by=[deploy])
require('app_path')
print '>>> upload tar from git'
require('release', provided_by=[deploy])
require('app_path')
run('cd %(app_path)s/releases/%(release)s && tar zxf ../../packages/%(release)s.tar.gz' % env, pty=True)
local('rm %(release)s.tar.gz' % env)
run('cd %(app_path)s/releases/%(release)s && tar zxf ../../packages/%(release)s.tar.gz' % env, pty=True)
local('rm %(release)s.tar.gz' % env)
print '>>> install requirements'
require('release', provided_by=[deploy])
require('app_path')
print '>>> install requirements'
require('release', provided_by=[deploy])
require('app_path')
require('virtualenv')
run('%(virtualenv)s %(ve)s' % env, pty=True)
with cd('%(app_path)s/releases/%(release)s' % env):
require('virtualenv')
run('%(virtualenv)s %(ve)s' % env, pty=True)
with cd('%(app_path)s/releases/%(release)s' % env):
- run('%(ve)s/bin/pip install -r %(reqs)s' % {'ve': env.ve, 'reqs': env.get('requirements_file', 'requirements.txt')}, pty=True)
+ run('%(ve)s/bin/pip install -r %(reqs)s' % {
+ 've': env.ve, 'reqs': env.get('requirements_file', 'requirements.txt')}, pty=True)
print ">>> copy localsettings"
require('release', provided_by=[deploy])
require('app_path', 'project_name')
print ">>> copy localsettings"
require('release', provided_by=[deploy])
require('app_path', 'project_name')
copy_to = join(get_django_root_path(env['release']), env.get('localsettings_dst_path', env['project_name']))
run('cp %(app_path)s/localsettings.py ' % env + copy_to)
copy_to = join(get_django_root_path(env['release']), env.get('localsettings_dst_path', env['project_name']))
run('cp %(app_path)s/localsettings.py ' % env + copy_to)
print '>>> symlink current release'
require('release', provided_by=[deploy])
require('app_path')
print '>>> symlink current release'
require('release', provided_by=[deploy])
require('app_path')
run('rm releases/previous; mv releases/current releases/previous')
run('ln -s %(release)s releases/current' % env)
run('rm releases/previous; mv releases/current releases/previous')
run('ln -s %(release)s releases/current' % env)
print '>>> migrate'
require('app_path', 'project_name')
with cd(get_django_root_path('current')):
print '>>> migrate'
require('app_path', 'project_name')
with cd(get_django_root_path('current')):
run('%s/bin/python manage.py migrate %s --fake %s' % (env.ve, app, migration), pty=True)
run('%(ve)s/bin/python manage.py migrate' % env, pty=True)
run('%s/bin/python manage.py migrate %s --fake %s' % (env.ve, app, migration), pty=True)
run('%(ve)s/bin/python manage.py migrate' % env, pty=True)
def pre_collectstatic():
print '>>> pre_collectstatic'
for task in env.get('pre_collectstatic', []):
execute(task)
def pre_collectstatic():
print '>>> pre_collectstatic'
for task in env.get('pre_collectstatic', []):
execute(task)
with cd(get_django_root_path('current')):
run('%(ve)s/bin/python manage.py collectstatic --noinput' % env, pty=True)
with cd(get_django_root_path('current')):
run('%(ve)s/bin/python manage.py collectstatic --noinput' % env, pty=True)
if 'django_root_path' in env:
path = join(path, env['django_root_path'])
return path
if 'django_root_path' in env:
path = join(path, env['django_root_path'])
return path