python-gallery/onlylegs/config.py

49 lines
1.4 KiB
Python
Raw Normal View History

2023-04-10 15:43:42 +00:00
"""
Gallery configuration file
"""
import os
import platformdirs
import importlib.metadata
2023-04-10 15:43:42 +00:00
from dotenv import load_dotenv
from yaml import safe_load
from utils import startup
# App Sanity Checks
startup.check_dirs()
startup.check_env()
startup.check_conf()
2023-04-10 15:43:42 +00:00
# Set dirs
APPLICATION_ROOT = platformdirs.user_config_dir("onlylegs")
2023-09-27 12:59:31 +00:00
UPLOAD_FOLDER = os.path.join(APPLICATION_ROOT, "media", "uploads")
MEDIA_FOLDER = os.path.join(APPLICATION_ROOT, "media")
CACHE_FOLDER = os.path.join(APPLICATION_ROOT, "media", "cache")
PFP_FOLDER = os.path.join(APPLICATION_ROOT, "media", "pfp")
BANNER_FOLDER = os.path.join(APPLICATION_ROOT, "media", "banner")
2023-04-10 15:43:42 +00:00
2023-09-27 12:59:31 +00:00
# Load env and config files
load_dotenv(os.path.join(APPLICATION_ROOT, ".env"))
2023-04-10 15:43:42 +00:00
2023-09-27 12:59:31 +00:00
config_file = os.path.join(APPLICATION_ROOT, "conf.yml")
with open(config_file, encoding="utf-8", mode="r") as file:
2023-04-10 15:43:42 +00:00
conf = safe_load(file)
# Flask config
SECRET_KEY = os.environ.get("FLASK_SECRET")
MAX_CONTENT_LENGTH = 1024 * 1024 * conf["upload"]["max-size"]
ALLOWED_EXTENSIONS = conf["upload"]["allowed-extensions"]
2023-09-27 12:59:31 +00:00
APP_VERSION = importlib.metadata.version("OnlyLegs")
# Database
2023-09-27 12:59:31 +00:00
DATABASE_NAME = "gallery.sqlite3"
SQLALCHEMY_DATABASE_URI = "sqlite:///" + DATABASE_NAME
INSTANCE_DIR = os.path.join(APPLICATION_ROOT, "instance")
MIGRATIONS_DIR = os.path.join(INSTANCE_DIR, "migrations")
2023-09-27 12:59:31 +00:00
# Pass YAML config to app
ADMIN_CONF = conf["admin"]
UPLOAD_CONF = conf["upload"]
WEBSITE_CONF = conf["website"]