Load config from TOML

This commit is contained in:
RunasSudo 2023-01-05 16:19:29 +11:00
parent 2e5ae4c20b
commit 8777ddd0ef
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
6 changed files with 11 additions and 7 deletions

2
.gitignore vendored
View File

@ -1,4 +1,4 @@
__pycache__ __pycache__
/drcr/config.py /drcr/config.toml
/instance /instance
/venv /venv

View File

@ -1 +0,0 @@
PLUGINS = ['austax']

3
drcr/config.toml.example Normal file
View File

@ -0,0 +1,3 @@
SQLALCHEMY_DATABASE_URI = "sqlite:///drcr.db"
PLUGINS = ["austax"]

View File

@ -14,7 +14,7 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
from .config import PLUGINS from .webapp import app
import importlib import importlib
@ -23,6 +23,6 @@ account_kinds = [] # list of tuplet (id, label)
transaction_providers = [] # list of callable transaction_providers = [] # list of callable
def init_plugins(): def init_plugins():
for plugin in PLUGINS: for plugin in app.config['PLUGINS']:
module = importlib.import_module(plugin) module = importlib.import_module(plugin)
module.plugin_init() module.plugin_init()

View File

@ -15,6 +15,10 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
from flask import Flask, g 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 flask_sqlalchemy.record_queries import get_recorded_queries
from .database import db from .database import db
@ -24,9 +28,6 @@ from .statements.models import StatementLine
import time import time
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///drcr.db'
app.config['SQLALCHEMY_RECORD_QUERIES'] = app.debug app.config['SQLALCHEMY_RECORD_QUERIES'] = app.debug
db.init_app(app) db.init_app(app)

View File

@ -1,5 +1,6 @@
Flask==2.2.2 Flask==2.2.2
Flask-SQLAlchemy==3.0.2 Flask-SQLAlchemy==3.0.2
toml==0.10.2
# For OFX 1.x import # For OFX 1.x import
lxml==4.9.2 lxml==4.9.2