45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
import os
|
|
import configparser
|
|
import logging
|
|
from peewee import SqliteDatabase
|
|
from rich.logging import RichHandler
|
|
|
|
# first things first: logging
|
|
logging.basicConfig(
|
|
format='%(message)s',
|
|
level=logging.INFO,
|
|
datefmt='%Y-%m-%d %H:%M:%S',
|
|
handlers=[RichHandler()]
|
|
)
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
# load config file containing constants and secrets
|
|
parsed = configparser.ConfigParser()
|
|
parsed.read("/app/file_storage/config.ini")
|
|
|
|
if os.getenv("DEBUG", "false") == "true":
|
|
logger.warning("Found 'DEBUG=true', setting up dummy databases")
|
|
|
|
db_base_path = parsed["DATABASE"]["db_path_dev"]
|
|
parsed["SLACK"]["archive_id"] = parsed["SLACK"]["debug_id"]
|
|
parsed["MAIL"]["recipient"] = parsed["MAIL"]["sender"]
|
|
else:
|
|
logger.warning("Found 'DEBUG=false' and running on production databases, I hope you know what you're doing...")
|
|
|
|
db_base_path = parsed["DATABASE"]["db_path_prod"]
|
|
|
|
|
|
from utils_storage import models
|
|
|
|
# Set up the database
|
|
models.set_db(
|
|
SqliteDatabase(
|
|
os.path.join(db_base_path, parsed["DATABASE"]["chat_db_name"]),
|
|
pragmas = {'journal_mode': 'wal'} # mutliple threads can read at once
|
|
),
|
|
SqliteDatabase(
|
|
os.path.join(db_base_path, parsed["DATABASE"]["download_db_name"]),
|
|
pragmas = {'journal_mode': 'wal'} # mutliple threads can read at once
|
|
)
|
|
) |