Created
April 17, 2012 12:39
-
-
Save schwuk/2405722 to your computer and use it in GitHub Desktop.
Django manage.py for split settings.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os | |
import sys | |
from django.core.management import execute_manager | |
PRODUCTION = 'production' | |
DEVELOPMENT = 'development' | |
ENVIRONMENTS = [ | |
DEVELOPMENT, | |
PRODUCTION, | |
] | |
SETTINGS = 'SETTINGS' | |
try: | |
config = os.environ[SETTINGS].lower() | |
except KeyError: | |
print "*** Please provide the %s environment variable! ***\n" % SETTINGS | |
sys.exit(1) | |
if config not in ENVIRONMENTS: | |
print "*** Please provide a valid environment for %s! ***" % SETTINGS | |
print "Valid environments are: %s\n" % ", ".join(ENVIRONMENTS) | |
sys.exit(1) | |
try: | |
_settings = __import__('settings', globals(), locals(), ENVIRONMENTS, -1) | |
if config == PRODUCTION: | |
settings = _settings.production | |
if config == DEVELOPMENT: | |
settings = _settings.development | |
except ImportError: | |
print "*** Invalid configuration! ***\n" | |
sys.exit(1) | |
sys.path.insert(0, os.path.abspath(os.path.pardir)) | |
if __name__ == "__main__": | |
execute_manager(settings) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment