diff options
| author | Gertjan van den Burg <gertjanvandenburg@gmail.com> | 2019-03-28 11:37:05 +0000 |
|---|---|---|
| committer | Gertjan van den Burg <gertjanvandenburg@gmail.com> | 2019-03-28 11:37:05 +0000 |
| commit | bdc1eb1d8bb800f7938c485e3c876fd06b535029 (patch) | |
| tree | 592067ad1091ac4dd8b77d13515d6def894425c9 /config.py | |
| parent | Flash warning when insufficient users present (diff) | |
| download | AnnotateChange-bdc1eb1d8bb800f7938c485e3c876fd06b535029.tar.gz AnnotateChange-bdc1eb1d8bb800f7938c485e3c876fd06b535029.zip | |
Update configuration to use env files throughout
Diffstat (limited to 'config.py')
| -rw-r--r-- | config.py | 46 |
1 files changed, 33 insertions, 13 deletions
@@ -1,27 +1,47 @@ # -*- coding: utf-8 -*- +"""Configuration for the AnnotateChange app + +Almost all configuration options are expected to be supplied through +environment variables. +""" + import os -from dotenv import load_dotenv +BASEDIR = os.path.abspath(os.path.dirname(__file__)) -# TODO: change these things to an instance path -basedir = os.path.abspath(os.path.dirname(__file__)) -load_dotenv(os.path.join(basedir, '.env')) class Config(object): SECRET_KEY = os.environ.get("SECRET_KEY") or "you-will-never-guess" - SQLALCHEMY_DATABASE_URI = os.environ.get( - "DATABASE_URL" - ) or "sqlite:///" + os.path.join(basedir, "app.db") + DB_TYPE = os.environ.get("DB_TYPE") or "sqlite3" + if DB_TYPE == "mysql": + SQLALCHEMY_DATABASE_URI = "mysql+pymysql://{username}:{password}@{host}:{port}/{database}".format( + username=os.environ.get("MYSQL_USER"), + password=os.environ.get("MYSQL_PASSWORD"), + host=os.environ.get("MYSQL_HOST"), + port=os.environ.get("MYSQL_PORT"), + database=os.environ.get("MYSQL_DATABASE"), + ) + else: + SQLALCHEMY_DATABASE_URI = "sqlite:///{filepath}".format( + filepath=os.path.join( + BASEDIR, os.environ.get("SQL3_FILENAME") or "app.db" + ) + ) + SQLALCHEMY_TRACK_MODIFICATIONS = False - MAIL_SERVER = os.environ.get('MAIL_SERVER') - MAIL_PORT = int(os.environ.get('MAIL_PORT') or 25) - MAIL_USE_TLS = os.environ.get('MAIL_USE_TLS') is not None - MAIL_USERNAME = os.environ.get('MAIL_USERNAME') - MAIL_PASSWORD = os.environ.get('MAIL_PASSWORD') - ADMINS = ["annotatechange@gmail.com"] + MAIL_SERVER = os.environ.get("MAIL_SERVER") + MAIL_PORT = int(os.environ.get("MAIL_PORT") or 25) + MAIL_USE_TLS = os.environ.get("MAIL_USE_TLS") is not None + MAIL_USERNAME = os.environ.get("MAIL_USERNAME") + MAIL_PASSWORD = os.environ.get("MAIL_PASSWORD") + ADMINS = [ + x.strip() + for x in os.environ.get("ADMIN_EMAILS").split(";") + if x.strip() + ] # these should be used relative to the instance path DATASET_DIR = "datasets" |
