"""
Django settings for testcube project.

Generated by 'django-admin startproject' using Django 1.11.1.

For more information on this file, see
https://docs.djangoproject.com/en/1.11/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.11/ref/settings/
"""

import logging
import os
import sys
from os import environ
from os.path import join, dirname, abspath

import raven

from testcube.utils import setup_logger

SETTINGS_DIR = dirname(abspath(__file__))
BASE_DIR = dirname(SETTINGS_DIR)
VERSION = '1.8.1'

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = environ.get('TESTCUBG_SECRET_KEY', 'hard to guess key')

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG_VALUE = environ.get('TESTCUBE_DEBUG', '').lower()
DEBUG = DEBUG_VALUE in ('true', 'yes', 'y', 'enabled', '1')

if environ.get('TESTCUBE_ALLOWED_HOSTS'):
    ALLOWED_HOSTS = environ['TESTCUBE_ALLOWED_HOSTS'].split(',')

DB_ENGINE = environ.get('TESTCUBE_DB_ENGINE') or 'django.db.backends.sqlite3'
DB_NAME = environ.get('TESTCUBE_DB_NAME') or 'db.sqlite3'
STATIC_URL = environ.get('TESTCUBE_STATIC_URL') or '/static/'
STATIC_ROOT = environ.get('TESTCUBE_STATIC_ROOT') or join(BASE_DIR, 'dist')
MEDIA_URL = environ.get('TESTCUBE_MEDIA_URL') or '/media/'
MEDIA_ROOT = environ.get('TESTCUBE_MEDIA_ROOT') or join(BASE_DIR, 'media')
LOG_ROOT = environ.get('TESTCUBE_LOG_ROOT') or BASE_DIR
TESTCUBE_DSN = environ.get('TESTCUBE_DSN')

# Sentry config
RAVEN_CONFIG = {
    'dsn': TESTCUBE_DSN,
    'release': raven.fetch_git_sha(os.path.abspath(os.curdir)),
}

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.humanize',
    'rest_framework',
    'django_filters',
    'bootstrapform',
    'testcube.core',
    'testcube.users',
    'testcube.runner',
    'tagging'
]

if TESTCUBE_DSN:
    INSTALLED_APPS.append('raven.contrib.django.raven_compat')

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'testcube.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [join(SETTINGS_DIR, 'templates')],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
                'django.template.context_processors.media',
                'testcube.context_processors.settings_context_processor'
            ],
            'debug': DEBUG
        },
    },
]

WSGI_APPLICATION = 'testcube.wsgi.application'

# Database
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': DB_ENGINE,
        'NAME': DB_NAME,
    }
}

# Password validation
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]

# Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = False

USE_L10N = False

USE_TZ = True

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/

STATICFILES_DIRS = [
    join(SETTINGS_DIR, 'static')
]

REST_FRAMEWORK = {
    # Use Django's standard `django.contrib.auth` permissions,
    # or allow read-only access for unauthenticated users.
    'DEFAULT_PERMISSION_CLASSES': [
        'rest_framework.permissions.IsAuthenticatedOrReadOnly'
    ],
    'DEFAULT_FILTER_BACKENDS': (
        'rest_framework_filters.backends.DjangoFilterBackend',
        'rest_framework.filters.SearchFilter',
        'rest_framework.filters.OrderingFilter'
    ),
    'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
    'PAGE_SIZE': 20
}

# global logging entry
logger = setup_logger(debug=DEBUG, log_dir=LOG_ROOT)

# tagging
FORCE_LOWERCASE_TAGS = True

@@ -1727,34 +1727,16 @@
 sha(
-os.path.abspath(os.curdir)
+BASE_DIR
 ),%0A%7D

use basedir for sentry release hash