Пример #1
0
def dropdb():
    # Invert apps to avoid dependency problems.
    from django.conf import settings
    apps = list(settings.INSTALLED_APPS)
    apps.reverse()

    failed_apps = []

    for app in apps:
        app = app.split('.')[-1]
        with cd(env.root):
            with virtualenv():
                try:
                    # We need to split DROP TABLEs from DROP FK because MySQL aborts if the FK doesn't exists
                    try:
                        execute('python manage.py sqlclear %(app)s --settings=%(settings)s | grep "DROP FOREIGN KEY" | ./manage.py dbshell --settings=%(settings)s' % {'app': app, 'settings': env.settings})
                    except:
                        # Ignore errors while dropping FK.
                        pass
                    execute('python manage.py sqlclear %(app)s --settings=%(settings)s | grep "DROP TABLE" | ./manage.py dbshell --settings=%(settings)s' % {'app': app, 'settings': env.settings})
                except:
                    failed_apps.insert(0, app)

    if failed_apps:
        dropdb(failed_apps)
Пример #2
0
def install_dependencies(path='requirements.txt'):
    """
    Install dependencies defined in requirements.txt
    """
    require('root', provided_by=('An environment task'))
    with cd(env.root):
        with virtualenv():
            execute('pip install -r %s' % path)
Пример #3
0
def migrate(initial_data=False):
    require('root', provided_by=('An environment task'))
    with cd(env.root):
        with virtualenv():
            if initial_data:
                execute('python manage.py migrate --settings=%(settings)s' % env)
            else:
                execute('python manage.py migrate --no-initial-data --settings=%(settings)s' % env)
Пример #4
0
def syncdb(initial_data=False):
    from django.conf import settings
    require('root', provided_by=('An environment task'))
    with cd(env.root):
        with virtualenv():
            execute('python manage.py syncdb --noinput --settings=%(settings)s' % env)
    if 'south' in settings.INSTALLED_APPS:
        migrate(initial_data)
Пример #5
0
def collect_static():
    from django.conf import settings

    require('root', provided_by=('An environment task'))
    with cd(env.root):
        with virtualenv():
            execute('python manage.py collectstatic --noinput --settings=%(settings)s' % env)
            if 'compressor' in settings.INSTALLED_APPS and getattr(settings, 'COMPRESS_ENABLED', False) and getattr(settings, 'COMPRESS_OFFLINE', False):
                execute('python manage.py compress --force --settings=%(settings)s' % env)
Пример #6
0
def install(package=None, version_str=" "):
    """
    Install a pip package.
    """
    if not package:
        abort('Provide a package name and optionally a version. Example: fab %(command)s:package=django,version===1.2' % env)

    with virtualenv():
        execute('pip install %s%s' % (package, version_str))
        execute('pip freeze > requirements.txt')
Пример #7
0
def uninstall(package=None):
    """
    Uninstall a pip package.
    """
    if not package:
        abort('Provide a package name. Example: fab %(command)s:package=django' % env)

    with virtualenv():
        execute('pip uninstall %s' % package)
        execute('pip freeze > requirements.txt')
Пример #8
0
def rebuild_index():
    require('root', provided_by=('An environment task'))
    with cd(env.root):
        with virtualenv():
            execute('python manage.py rebuild_index --noinput --settings=%(settings)s' % env)