2020-10-08 10:34:02 +00:00
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
2020-10-21 11:07:10 +00:00
|
|
|
ROOT_DIR = os.path.abspath(os.path.dirname(__file__))
|
2020-10-08 10:34:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Config:
|
2020-10-21 11:07:10 +00:00
|
|
|
''' # Email # '''
|
2020-10-08 10:34:02 +00:00
|
|
|
SMTP_DEFAULT_SENDER = os.environ.get('NOPAQUE_SMTP_DEFAULT_SENDER')
|
|
|
|
SMTP_PASSWORD = os.environ.get('NOPAQUE_SMTP_PASSWORD')
|
2020-10-21 11:07:10 +00:00
|
|
|
SMTP_PORT = int(os.environ.get('NOPAQUE_SMTP_PORT'))
|
2020-10-08 10:34:02 +00:00
|
|
|
SMTP_SERVER = os.environ.get('NOPAQUE_SMTP_SERVER')
|
|
|
|
SMTP_USERNAME = os.environ.get('NOPAQUE_SMTP_USERNAME')
|
2020-10-21 11:07:10 +00:00
|
|
|
SMTP_USE_SSL = os.environ.get(
|
|
|
|
'NOPAQUE_SMTP_USE_SSL', 'false').lower() == 'true'
|
|
|
|
SMTP_USE_TLS = os.environ.get(
|
|
|
|
'NOPAQUE_SMTP_USE_TLS', 'false').lower() == 'true'
|
2020-10-08 10:34:02 +00:00
|
|
|
|
2020-10-21 11:07:10 +00:00
|
|
|
''' # General # '''
|
|
|
|
DATA_DIR = os.environ.get('NOPAQUE_DATA_DIR', '/mnt/nopaque')
|
|
|
|
DOMAIN = os.environ.get('NOPAQUE_DOMAIN', 'localhost')
|
|
|
|
PROTOCOL = os.environ.get('NOPAQUE_PROTOCOL', 'http')
|
|
|
|
SECRET_KEY = os.environ.get('NOPAQUE_SECRET_KEY', 'hard to guess string')
|
2020-10-08 10:34:02 +00:00
|
|
|
|
2020-10-21 11:07:10 +00:00
|
|
|
''' # Logging # '''
|
2020-10-08 10:34:02 +00:00
|
|
|
LOG_DATE_FORMAT = os.environ.get('NOPAQUE_LOG_DATE_FORMAT',
|
2020-10-21 11:07:10 +00:00
|
|
|
'%Y-%m-%d %H:%M:%S')
|
|
|
|
LOG_FILE = os.environ.get('NOPAQUED_LOG_FILE',
|
|
|
|
os.path.join(ROOT_DIR, 'nopaqued.log'))
|
|
|
|
LOG_FORMAT = os.environ.get(
|
|
|
|
'NOPAQUE_LOG_FORMAT',
|
|
|
|
'[%(asctime)s] %(levelname)s in '
|
|
|
|
'%(pathname)s (function: %(funcName)s, line: %(lineno)d): %(message)s'
|
|
|
|
)
|
|
|
|
LOG_LEVEL = os.environ.get('NOPAQUE_LOG_LEVEL', 'WARNING')
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def init(cls):
|
|
|
|
# Set up logging according to the corresponding (LOG_*) variables
|
|
|
|
logging.basicConfig(datefmt=cls.LOG_DATE_FORMAT,
|
|
|
|
filename=cls.LOG_FILE,
|
|
|
|
format=cls.LOG_FORMAT,
|
|
|
|
level=cls.LOG_LEVEL)
|
|
|
|
|
|
|
|
|
|
|
|
class DevelopmentConfig(Config):
|
|
|
|
''' # Database # '''
|
|
|
|
SQLALCHEMY_DATABASE_URI = os.environ.get(
|
|
|
|
'NOPAQUE_DEV_DATABASE_URL',
|
|
|
|
'sqlite:///' + os.path.join(ROOT_DIR, 'data-dev.sqlite')
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class ProductionConfig(Config):
|
|
|
|
''' # Database # '''
|
|
|
|
SQLALCHEMY_DATABASE_URI = os.environ.get(
|
|
|
|
'NOPAQUE_DATABASE_URL',
|
|
|
|
'sqlite:///' + os.path.join(ROOT_DIR, 'data.sqlite')
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class TestingConfig(Config):
|
|
|
|
''' # Database # '''
|
|
|
|
SQLALCHEMY_DATABASE_URI = os.environ.get(
|
|
|
|
'NOPAQUE_TEST_DATABASE_URL', 'sqlite://')
|
|
|
|
|
|
|
|
|
|
|
|
config = {'development': DevelopmentConfig,
|
|
|
|
'production': ProductionConfig,
|
|
|
|
'testing': TestingConfig}
|