import os
import socket
env = lambda key, returntype=str: returntype(os.environ[key])

DEBUG = env('DJANGO_DEBUG', bool)
TEMPLATE_DEBUG = DEBUG

MIDDLEWARE_CLASSES = (
    'supstream.middleware.VHostMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
)
INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'gunicorn',
    'djapp',
    'supstream',
)

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.', # 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.
    }
}

DOMAIN = env('DOMAIN')
if os.environ['NETLOC_SUFFIX']:
    NETLOC_SUFFIX = env('NETLOC_SUFFIX')
else:
    NETLOC_SUFFIX = '%s.%s:%s' % (socket.gethostname().split('.')[0], DOMAIN, os.environ['PORT'])
HOST_SUFFIX = NETLOC_SUFFIX.split(':')[0]

STATIC_ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'static')
STATIC_URL = '//static.' + NETLOC_SUFFIX

MEDIA_ROOT = ''
MEDIA_URL = ''

TIME_ZONE = 'UTC'
LANGUAGE_CODE = 'en-us'
USE_I18N = True
USE_L10N = True

ADMINS = ()
MANAGERS = ADMINS
SITE_ID = 1
SECRET_KEY = env('DJANGO_SECRET_KEY')

TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
)
TEMPLATE_DIRS = (
)

ROOT_URLCONF = 'djproj.urls.root'
VHOST_URLCONFS = dict(
    static = 'djproj.urls.static',
)

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'mail_admins': {
            'level': 'ERROR',
            'class': 'django.utils.log.AdminEmailHandler'
        }
    },
    'loggers': {
        'django.request': {
            'handlers': ['mail_admins'],
            'level': 'ERROR',
            'propagate': True,
        },
    }
}

@@ -2453,16 +2453,191 @@
      %7D,%0A    %7D%0A%7D%0A
+%0Atry:%0A    with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'SLUG_UUID')) as handle:%0A        RELEASE_ID=handle.read().strip()%0Aexcept IOError:%0A    pass%0A%0A

read SLUG_UUID into settings (if it exists)