Source code for fab_deploy.django_commands

#coding: utf-8
from __future__ import with_statement
from fabric.api import *

from fab_deploy import mysql
from fab_deploy import utils

__all__ = ['migrate', 'manage', 'syncdb', 'compress', 'collectstatic', 'test',

def command_is_available(command):
    with settings(hide('warnings', 'running', 'stdout', 'stderr'), warn_only=True):
        output = run('python help ' + command)
    return output.succeeded

[docs]def manage(command): """ Runs django management command. Example:: fab manage:createsuperuser """ if not command_is_available(command): warn('Management command "%s" is not available' % command) else: run('python ' + command)
[docs]def migrate(params='', do_backup=True): """ Runs migrate management command. Database backup is performed before migrations if ``do_backup=False`` is not passed. """ if do_backup: backup_dir = env.conf['ENV_DIR'] + '/var/backups/before-migrate' run('mkdir -p ' + backup_dir) with settings(warn_only=True): mysql.mysqldump(backup_dir) manage('migrate --noinput %s' % params)
[docs]def syncdb(params=''): """ Runs syncdb management command. """ manage('syncdb --noinput %s' % params)
def compress(params=''): with settings(warn_only=True): manage('synccompress %s' % params) def collectstatic(params=''): manage('collectstatic --noinput %s' % params) @utils.inside_project
[docs]def test(what=''): """ Runs '' script from project root. Example content:: #!/bin/sh default_tests='accounts forum firms blog' if [ $# -eq 0 ] then ./ test $default_tests --settings=test_settings else ./ test $* --settings=test_settings fi """ with settings(warn_only=True): run('./ ' + what) #def coverage(): # pass # with cd(env.conf['SRC_DIR']): # run('source %s/bin/activate; ./bin/' % env.conf['ENV_DIR'])