From af3e14a7aa32c728f518bc2b92f0ce29f7da33e0 Mon Sep 17 00:00:00 2001 From: Alek Ratzloff Date: Wed, 2 Aug 2023 18:40:45 -0700 Subject: [PATCH] Add DB_SQLITE3_PATH config option Rather than being hardcoded Signed-off-by: Alek Ratzloff --- chanbans/config.py | 2 ++ chanbans/db.py | 7 +++---- example.env | 3 +++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/chanbans/config.py b/chanbans/config.py index 294efb0..7a12755 100644 --- a/chanbans/config.py +++ b/chanbans/config.py @@ -26,5 +26,7 @@ def default(name: str, default: str) -> str: THUMBS_DIR = Path(default("THUMBS_DIR", "thumbs")) CACHE_DIR = Path(default("CACHE_DIR", "cache")) +DB_SQLITE3_PATH = Path(default("DB_SQLITE3_PATH", "bans.db")) + HTTP_DOMAIN = required("HTTP_DOMAIN") HTTP_ROOT = default("HTTP_ROOT", r"/") diff --git a/chanbans/db.py b/chanbans/db.py index 99cde1a..900e5a6 100644 --- a/chanbans/db.py +++ b/chanbans/db.py @@ -2,12 +2,11 @@ import sqlite3 import sys from typing import Optional - -DB_PATH = "bans.db" +from . import config -def get_db(db_path: str = DB_PATH): - db = sqlite3.connect(db_path) +def get_db(): + db = sqlite3.connect(config.DB_SQLITE3_PATH) # ensure that the database exists db.executescript( """ diff --git a/example.env b/example.env index 070322e..b612346 100644 --- a/example.env +++ b/example.env @@ -4,6 +4,9 @@ # HTML cache directory. Defaults to "cache" #CACHE_DIR=cache +# Sqlite3 database path. Defaults to "bans.db" +#DB_SQLITE3_PATH=bans.db + # Domain name of the server HTTP_DOMAIN=domain.com