Commit 9a97aad7 by Mushtaq Ali

Divide settings into environment specific sub modules - EDUCATOR-1596

parent ee2de74e
...@@ -15,6 +15,8 @@ omit = ...@@ -15,6 +15,8 @@ omit =
frontend/tests/* frontend/tests/*
dependencies/* dependencies/*
control/tests/* control/tests/*
VEDA/settings/*
VEDA/wsgi.py
VEDA/tests/* VEDA/tests/*
VEDA_OS01/tests/* VEDA_OS01/tests/*
VEDA_OS01/migrations/* VEDA_OS01/migrations/*
......
...@@ -15,4 +15,4 @@ reports/ ...@@ -15,4 +15,4 @@ reports/
.cache/ .cache/
VEDA/private.py VEDA/settings/private.py
"""
Video Pipeline Django Secrets Shim
This acts as a django-secret shimmer until we can finish pushing all changes to terraform/prod
"""
import os
from VEDA.utils import get_config
CONFIG_DATA = get_config()
DJANGO_SECRET_KEY = CONFIG_DATA['django_secret_key'] or 'test_secret_key'
DJANGO_ADMIN = ('', '')
DJANGO_DEBUG = CONFIG_DATA['debug'] if 'debug' in CONFIG_DATA else False
DATABASES = CONFIG_DATA['DATABASES']
STATIC_ROOT_PATH = CONFIG_DATA.get(
'STATIC_ROOT_PATH',
os.path.join(
os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
'static'
)
)
""" """
Settings Base settings
""" """
from os.path import join, dirname, abspath
DATABASES = None
import os import os
from django_secrets import *
ROOT_DIR = os.path.dirname(os.path.dirname((__file__))) ROOT_DIR = os.path.dirname(os.path.dirname(os.path.dirname((__file__))))
DJANGO_ADMIN = ('', '')
ADMINS = ( ADMINS = (
DJANGO_ADMIN, DJANGO_ADMIN,
) )
...@@ -19,22 +15,11 @@ EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' # Port the war ...@@ -19,22 +15,11 @@ EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' # Port the war
MANAGERS = ADMINS MANAGERS = ADMINS
if DATABASES is None:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': pipeline_dbname,
'USER': DJANGO_DB_USER,
'PASSWORD': DJANGO_DB_PASS,
'HOST': DBHOST,
'PORT': '3306',
}
}
# Make this unique, and don't share it with anybody. # Make this unique, and don't share it with anybody.
SECRET_KEY = DJANGO_SECRET_KEY SECRET_KEY = 'insecure-secret-key'
DEBUG = DJANGO_DEBUG # SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
ALLOWED_HOSTS = ['*'] ALLOWED_HOSTS = ['*']
TIME_ZONE = 'UTC' TIME_ZONE = 'UTC'
...@@ -46,7 +31,7 @@ USE_TZ = True ...@@ -46,7 +31,7 @@ USE_TZ = True
# Absolute filesystem path to the directory that will hold user-uploaded files. # Absolute filesystem path to the directory that will hold user-uploaded files.
STATIC_ROOT = STATIC_ROOT_PATH STATIC_ROOT = os.path.join(ROOT_DIR, 'static')
STATIC_URL = '/static/' STATIC_URL = '/static/'
# Additional locations of static files # Additional locations of static files
...@@ -111,6 +96,19 @@ ROOT_URLCONF = 'VEDA.urls' ...@@ -111,6 +96,19 @@ ROOT_URLCONF = 'VEDA.urls'
# Python dotted path to the WSGI application used by Django's runserver. # Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'VEDA.wsgi.application' WSGI_APPLICATION = 'VEDA.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
# Set this value in the environment-specific files (e.g. local.py, production.py, test.py)
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.',
'NAME': '',
'USER': '',
'PASSWORD': '',
'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
'PORT': '', # Set to empty string for default.
}
}
REST_FRAMEWORK = { REST_FRAMEWORK = {
'PAGE_SIZE': 10, 'PAGE_SIZE': 10,
...@@ -179,7 +177,3 @@ LOGGING = { ...@@ -179,7 +177,3 @@ LOGGING = {
}, },
} }
} }
# See if the developer has any local overrides.
if os.path.isfile(join(dirname(abspath(__file__)), 'private.py')):
from .private import * # pylint: disable=import-error, wildcard-import
from VEDA.settings.base import *
DEBUG = True
ALLOWED_HOSTS = ['*']
# DATABASE CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(ROOT_DIR, 'sandbox.db'),
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': '',
}
}
# END DATABASE CONFIGURATION
# See if the developer has any local overrides.
if os.path.isfile(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'private.py')):
from .private import * # pylint: disable=import-error, wildcard-import
import yaml
from os import environ
from VEDA.settings.base import *
from VEDA.utils import get_config
DEBUG = False
TEMPLATE_DEBUG = DEBUG
ALLOWED_HOSTS = ['*']
# Keep track of the names of settings that represent dicts. Instead of overriding the values in base.py,
# the values read from disk should UPDATE the pre-configured dicts.
DICT_UPDATE_KEYS = ('DATABASES', 'SECRET_KEY', 'STATIC_ROOT_PATH')
CONFIG_DATA = get_config()
# Remove the items that should be used to update dicts, and apply them separately rather
# than pumping them into the local vars.
dict_updates = {key: CONFIG_DATA.pop(key, None) for key in DICT_UPDATE_KEYS}
for key, value in dict_updates.items():
if value:
vars()[key].update(value)
vars().update(CONFIG_DATA)
""" """
Test Settings Test settings
""" """
from settings import * from VEDA.settings.base import *
DATABASES = { DATABASES = {
'default': { 'default': {
......
...@@ -2,7 +2,7 @@ import sys ...@@ -2,7 +2,7 @@ import sys
import os import os
sys.path.append(os.path.abspath(__file__)) sys.path.append(os.path.abspath(__file__))
os.environ['DJANGO_SETTINGS_MODULE'] = 'VEDA.settings' os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'VEDA.settings.local')
from django.conf import settings from django.conf import settings
from rest_framework import routers from rest_framework import routers
......
...@@ -5,5 +5,5 @@ from django.core.wsgi import get_wsgi_application ...@@ -5,5 +5,5 @@ from django.core.wsgi import get_wsgi_application
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
os.environ.setdefault("PYTHON_EGG_CACHE", BASE_DIR + "/egg_cache") os.environ.setdefault("PYTHON_EGG_CACHE", BASE_DIR + "/egg_cache")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "VEDA.settings") os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'VEDA.settings.local')
application = get_wsgi_application() application = get_wsgi_application()
#!/usr/bin/env python
import os
import sys
import django
"""
VEDA Environment variables
"""
"""
Import Django Shit
"""
project_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if project_path not in sys.path:
sys.path.append(project_path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'VEDA.settings'
django.setup()
from VEDA_OS01.models import Institution
from VEDA_OS01.models import Course
from VEDA_OS01.models import Video
from VEDA_OS01.models import URL
from VEDA_OS01.models import VedaUpload
...@@ -14,7 +14,7 @@ project_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) ...@@ -14,7 +14,7 @@ project_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if project_path not in sys.path: if project_path not in sys.path:
sys.path.append(project_path) sys.path.append(project_path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'VEDA.settings' os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'VEDA.settings.local')
django.setup() django.setup()
......
...@@ -14,7 +14,7 @@ project_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) ...@@ -14,7 +14,7 @@ project_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if project_path not in sys.path: if project_path not in sys.path:
sys.path.append(project_path) sys.path.append(project_path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'VEDA.settings' os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'VEDA.settings.local')
django.setup() django.setup()
......
...@@ -19,7 +19,7 @@ DATABASES: ...@@ -19,7 +19,7 @@ DATABASES:
HOST: 'localhost' HOST: 'localhost'
PORT: 3306 PORT: 3306
django_secret_key: "" SECRET_KEY: ""
# Django DEBUG global # Django DEBUG global
# (set to false in prod) # (set to false in prod)
......
...@@ -3,7 +3,7 @@ import os ...@@ -3,7 +3,7 @@ import os
import sys import sys
if __name__ == "__main__": if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "VEDA.settings") os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'VEDA.settings.local')
from django.core.management import execute_from_command_line from django.core.management import execute_from_command_line
......
[pytest] [pytest]
DJANGO_SETTINGS_MODULE = VEDA.test_settings DJANGO_SETTINGS_MODULE = VEDA.settings.test
...@@ -5,8 +5,6 @@ Fix resolution 'progressive)' bug ...@@ -5,8 +5,6 @@ Fix resolution 'progressive)' bug
""" """
import os import os
import sys import sys
import django
from django.utils.timezone import utc
import datetime import datetime
from datetime import timedelta from datetime import timedelta
...@@ -14,8 +12,8 @@ sys.path.append( ...@@ -14,8 +12,8 @@ sys.path.append(
os.path.dirname(os.path.dirname(os.path.abspath(__file__))) os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
) )
# import abvid_reporting # import abvid_reporting
from pipeline_env import *
from veda_heal import VedaHeal from veda_heal import VedaHeal
from VEDA_OS01.models import Video
sick_list = [ sick_list = [
'EDXABVID2014-V148900', 'EDXABVID2014-V148900',
......
...@@ -19,7 +19,7 @@ project_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) ...@@ -19,7 +19,7 @@ project_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if project_path not in sys.path: if project_path not in sys.path:
sys.path.append(project_path) sys.path.append(project_path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'VEDA.settings' os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'VEDA.settings.local')
django.setup() django.setup()
......
...@@ -17,7 +17,8 @@ import xml.etree.ElementTree as ET ...@@ -17,7 +17,8 @@ import xml.etree.ElementTree as ET
project_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) project_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if project_path not in sys.path: if project_path not in sys.path:
sys.path.append(project_path) sys.path.append(project_path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'VEDA.settings'
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'VEDA.settings.local')
django.setup() django.setup()
from VEDA_OS01.models import Video, Encode, URL from VEDA_OS01.models import Video, Encode, URL
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment