1. Omer Katz
  2. django-envconf


django-envconf / fabfile.py

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
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):
    management.call_command('startenv', setting_suite)

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

def test(settings_suite):

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