Source

django-envconf / fabfile.py

Full commit
"""
Creating standalone Django apps is a PITA because you're not in a project, so
you don't have a settings.py file. I can never remember to define
DJANGO_SETTINGS_MODULE, so I run these commands which get the right env
automatically.
"""
import functools
import os

from fabric.api import local, cd, env
from fabric.contrib.project import rsync_project
from django.conf import settings
from django.core import management

NAME = os.path.basename(os.path.dirname(__file__))
ROOT = os.path.abspath(os.path.dirname(__file__))

os.environ['PYTHONPATH'] = os.pathsep.join([ROOT])

env.hosts = ['omer.me']

local = functools.partial(local, capture = False)

def _configure():
    settings.configure(DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': '.', # Or path to database file if using sqlite3.
        'USER': '', # Not used with sqlite3.
        'PASSWORD': '', # Not used with sqlite3.
        'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '', # Set to empty string for default. Not used with sqlite3.
        }
    },
    INSTALLED_APPS = ('envconf',))

def create_settings_suite(setting_suite):
    _configure()
    management.call_command('startenv', setting_suite)

def project():
    _configure()
    management.call_command('startproject', 'name', withenvconf = ['g'])

def test(settings_suite):
    _configure()

    import envconf
    os.environ['SETTINGS_SUITE'] = settings_suite
    management.call_command('test', envconf.__name__)