From 8777ddd0efb228fc77e3bfb5e988510532460a43 Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Thu, 5 Jan 2023 16:19:29 +1100 Subject: [PATCH] Load config from TOML --- .gitignore | 2 +- drcr/config.py.example | 1 - drcr/config.toml.example | 3 +++ drcr/plugins.py | 4 ++-- drcr/webapp.py | 7 ++++--- requirements.txt | 1 + 6 files changed, 11 insertions(+), 7 deletions(-) delete mode 100644 drcr/config.py.example create mode 100644 drcr/config.toml.example diff --git a/.gitignore b/.gitignore index 975657e..f1e0b50 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ __pycache__ -/drcr/config.py +/drcr/config.toml /instance /venv diff --git a/drcr/config.py.example b/drcr/config.py.example deleted file mode 100644 index 1bc714f..0000000 --- a/drcr/config.py.example +++ /dev/null @@ -1 +0,0 @@ -PLUGINS = ['austax'] diff --git a/drcr/config.toml.example b/drcr/config.toml.example new file mode 100644 index 0000000..81f6a94 --- /dev/null +++ b/drcr/config.toml.example @@ -0,0 +1,3 @@ +SQLALCHEMY_DATABASE_URI = "sqlite:///drcr.db" + +PLUGINS = ["austax"] diff --git a/drcr/plugins.py b/drcr/plugins.py index a034f17..b3f4cad 100644 --- a/drcr/plugins.py +++ b/drcr/plugins.py @@ -14,7 +14,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from .config import PLUGINS +from .webapp import app import importlib @@ -23,6 +23,6 @@ account_kinds = [] # list of tuplet (id, label) transaction_providers = [] # list of callable def init_plugins(): - for plugin in PLUGINS: + for plugin in app.config['PLUGINS']: module = importlib.import_module(plugin) module.plugin_init() diff --git a/drcr/webapp.py b/drcr/webapp.py index f02a84e..0115d8a 100644 --- a/drcr/webapp.py +++ b/drcr/webapp.py @@ -15,6 +15,10 @@ # along with this program. If not, see . from flask import Flask, g +import toml +app = Flask(__name__) +app.config.from_file('config.toml', load=toml.load) + from flask_sqlalchemy.record_queries import get_recorded_queries from .database import db @@ -24,9 +28,6 @@ from .statements.models import StatementLine import time -app = Flask(__name__) - -app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///drcr.db' app.config['SQLALCHEMY_RECORD_QUERIES'] = app.debug db.init_app(app) diff --git a/requirements.txt b/requirements.txt index 1e970cb..8e0c72c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ Flask==2.2.2 Flask-SQLAlchemy==3.0.2 +toml==0.10.2 # For OFX 1.x import lxml==4.9.2