Skip to content
Permalink
Browse files

Refactor settings

  • Loading branch information...
jochenklar committed Sep 5, 2019
1 parent dc73955 commit 303c414bef26582b06bf14e3f4fc95100e9f74ff
@@ -1,24 +1,22 @@
testing/config/settings/local.py
testing/log
testing/download
testing/media_root
testing/static_root
__pycache__/
*.py[cod]

*-
*~
*.pyc
*-
*.swp
.DS_Store

*.sqlite3

env
env3
/testing/config/settings/local.py
/testing/download
/testing/upload
/testing/log
/testing/media_root
/testing/static_root
/.coverage
/htmlcov
/env
/venv

build
dist
*.egg-info

.coverage
htmlcov

@@ -1,7 +1,14 @@
from django.apps import AppConfig

from django.conf import settings
from django.core.exceptions import ImproperlyConfigured

class ArchiveConfig(AppConfig):
name = 'daiquiri.archive'
label = 'daiquiri_archive'
verbose_name = 'Archive'

def ready(self):
if not settings.ARCHIVE_BASE_PATH:
raise ImproperlyConfigured('ARCHIVE_BASE_PATH is not set')
if not settings.ARCHIVE_DOWNLOAD_DIR:
raise ImproperlyConfigured('ARCHIVE_DOWNLOAD_DIR is not set')
@@ -0,0 +1,31 @@
import daiquiri.core.env as env

ARCHIVE_BASE_PATH = env.get_abspath('ARCHIVE_BASE_PATH')
ARCHIVE_DOWNLOAD_DIR = env.get_abspath('ARCHIVE_DOWNLOAD_DIR')

ARCHIVE_ANONYMOUS = False
ARCHIVE_SCHEMA = 'daiquiri_archive'
ARCHIVE_TABLE = 'files'
ARCHIVE_COLUMNS = [
{
'name': 'id',
'hidden': True
},
{
'name': 'timestamp',
'label': 'Timestamp'
},
{
'name': 'file',
'label': 'Filename',
'ucd': 'meta.file'
},
{
'name': 'collection',
'hidden': True
},
{
'name': 'path',
'hidden': True
}
]
@@ -0,0 +1,7 @@
import daiquiri.core.env as env

AUTH_SIGNUP = env.get_bool('AUTH_SIGNUP')

AUTH_WORKFLOW = None
AUTH_DETAIL_KEYS = []
AUTH_TERMS_OF_USE = False
@@ -4,4 +4,4 @@
class ConeSearchConfig(AppConfig):
name = 'daiquiri.conesearch'
label = 'daiquiri_conesearch'
verbose_name = 'Daiquiri ConeSearch'
verbose_name = 'Cone search'
@@ -0,0 +1,2 @@
CONESEARCH_ADAPTER = 'daiquiri.conesearch.adapter.SimpleConeSearchAdapter'
CONESEARCH_ANONYMOUS = False
@@ -0,0 +1,86 @@
import os

import dj_database_url

from urllib.parse import urlparse

from django.core.exceptions import ImproperlyConfigured

def get(key, default=None):
return os.getenv(key, default)


def get_bool(key, default=None):
value = os.getenv(key)
if value:
return True if value.lower() in ['1', 't', 'true', 'y', 'yes', 'on'] else False
else:
return default

def get_abspath(key, default=None):
value = os.getenv(key, default)
return os.path.abspath(value) if value else default


def get_schema(key):
return os.getenv(key, key.lower())


def get_list(key, default=[]):
value = os.getenv(key)
if value:
return [value.strip() for value in value.split(',')]
else:
return default


def get_url(key, default=None):
value = os.getenv(key, default)
return value if value.endswith('/') else value + '/'


def get_database(key):
database_string = os.getenv('DATABASE_%s' % key.upper())
if database_string:
database_type = urlparse(database_string).scheme

# rewrite mariadb since it is not supported by dj_database_url
if database_type == 'mariadb':
database_string = database_string.replace('mariadb://', 'mysql://')

database_config = dj_database_url.parse(database_string)

# patch bug in dj_database_url
if database_type in ['postgres', 'postgresql', 'pgsql']:
database_config['ENGINE'] = 'django.db.backends.postgresql'
print(database_config)
return database_config

else:
return {}


def get_database_adapter():
database_string = os.getenv('DATABASE_DATA')
database_type = urlparse(database_string).scheme

if database_type in ['postgres', 'postgresql', 'pgsql']:
return 'daiquiri.core.adapter.database.postgres.PostgreSQLAdapter'
elif database_type == 'mysql':
return 'daiquiri.core.adapter.database.mysql.MySQLAdapter'
elif database_type == 'mariadb':
return 'daiquiri.core.adapter.database.mariadb.MariaDBAdapter'
else:
return None


def get_download_adapter():
database_string = os.getenv('DATABASE_DATA')
database_type = urlparse(database_string).scheme

if database_type in ['postgres', 'postgresql', 'pgsql']:
return 'daiquiri.core.adapter.download.pgdump.PgDumpAdapter'
elif database_type in ['mysql', 'mariadb']:
return 'daiquiri.core.adapter.download.mysqldump.MysqldumpAdapter'
else:
return None
@@ -1,5 +0,0 @@
from .base import *
from .celery import *
from .daiquiri import *
from .logging import *
from .vendor import *

0 comments on commit 303c414

Please sign in to comment.
You can’t perform that action at this time.