django-fab-deploy / fab_deploy /

The default branch has multiple heads

# coding: utf-8
from __future__ import with_statement

from fabric.api import run, settings, env, hide, warn
from fabric.contrib import files
from taskset import task_method

from fab_deploy.apps import WebApp
from fab_deploy import utils
from fab_deploy import db

__all__ = ['Django']

class Django(WebApp):

    def __init__(self, frontend, backend, local_config='', remote_config=''):
        super(Django, self).__init__(frontend, backend)
        self.local_config = local_config
        self.remote_config = remote_config

    def update_config(self, restart=True):
        """ Updates :file:`` on server (using :file:``) """
            env.conf, True
        if restart:

    def command_is_available(self, command):
        with settings(hide('warnings', 'running', 'stdout', 'stderr'), warn_only=True):
            output = run('python help ' + command)
        if output.succeeded:
            return True
        # that's ugly
        unknown_command_msg = "Unknown command: '%s'" % command
        if unknown_command_msg in output:
            return False
        # re-raise the original exception
        run('python help ' + command)
    def manage(self, command):
        Runs django management command. Example::
            fab manage:createsuperuser
        command_name = command.split()[0]
        if not self.command_is_available(command_name):
            warn('Management command "%s" is not available' % command_name)
            run('python ' + command)
    def migrate(self, params='', do_backup=True):
        """ Runs migrate management command. Database backup is performed
        before migrations until ``do_backup=False`` is passed. """
        if do_backup:
            database = db.get_backend()
            backup_dir = env.conf['ENV_DIR'] + '/var/backups/before-migrate'
            run('mkdir -p ' + backup_dir)
        self.manage('migrate --noinput %s' % params)
    def syncdb(self, params=''):
        """ Runs syncdb management command. """
        self.manage('syncdb --noinput %s' % params)
    def compress(self, params=''):
        with settings(warn_only=True):
            self.manage('synccompress %s' % params)
    def collectstatic(self, params=''):
        self.manage('collectstatic --noinput %s' % params)
    def test(self, what=''):
        Runs '' script from project root.
        Example content::
            default_tests='accounts forum firms blog'
            if [ $# -eq 0 ]
                ./ test $default_tests --settings=test_settings
                ./ test $* --settings=test_settings
        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'])