From: Edward Delaporte Date: Tue, 7 Apr 2026 01:01:03 +0000 (-0500) Subject: Add invoke debug task to check db X-Git-Url: https://us-delaporte.pagekite.me/gitweb/matrix-chore-bot.git/commitdiff_plain/c9a600f294a52bf535e1c60d16b1715623183a69?ds=sidebyside Add invoke debug task to check db --- diff --git a/matrix_chore_bot/db.py b/matrix_chore_bot/db.py index 1a07bec..a0eae22 100644 --- a/matrix_chore_bot/db.py +++ b/matrix_chore_bot/db.py @@ -35,14 +35,14 @@ def get_chore(session, chore_id): return session.exec(cmd).first() class Data(): - def __init__(self, db_file=None): - - if not db_file: - db_file = DB_FILE + def __init__(self, db_file): self.file = db_file self.engine = self.get_engine() + def get_db_file(self): + return self.file + def get_engine(self): return create_engine(f"sqlite:///{self.file}") diff --git a/matrix_chore_bot/tasks.py b/matrix_chore_bot/tasks.py index 5a4eaa6..f95400b 100644 --- a/matrix_chore_bot/tasks.py +++ b/matrix_chore_bot/tasks.py @@ -1,42 +1,55 @@ +import os + from invoke import task from .db import Data + +# Where to store data +DATA_DIR = os.environ.get('MATRIX_DATA_DIR', '') +DB_FILE = os.environ.get('MATRIX_DB_FILE', 'chore.db') +db_file = os.path.join(DATA_DIR, DB_FILE) + +DATA = Data(db_file) + @task def add(c, task): - result = Data().add(task) + result = DATA.add(task) print(result) @task def check(c, task): - result = Data().check(task) + result = DATA.check(task) print(result) @task def done(c, task): - result = Data().done(task) + result = DATA.done(task) print(result) @task def undo(c, task): - result = Data().undo(task) + result = DATA.undo(task) print(result) @task def remove(c, task): - result = Data().remove(task) + result = DATA.remove(task) print(result) @task def list(c): - result = Data().list() + result = DATA.list() for item in result: print(f'{item}') @task def filter(c, term): - result = Data().filter(term) + result = DATA.filter(term) for item in result: print(f'{item}') +@task +def debug(c): + print(DATA.get_db_file())