# -*- coding: utf-8 -*- """ StickyNotes, yet another paste bin """ from configparser import ConfigParser from pathlib import Path import quart_flask_patch # noqa: F401 from quart import Quart from stickynotes.db import db from stickynotes.views import views def read_config(config_path=None): """ Read the configuration file and return the values in a dictionary """ if config_path: config_file = config_path / 'stickynotes.cfg' else: config_file = Path(__file__).parent / '..' / 'stickynotes.cfg' if not config_file.exists(): return {} config_parser = ConfigParser() config_parser.read(config_file) config = {} for option in config_parser.options('stickynotes'): config[option.upper()] = config_parser.get('stickynotes', option) return config def make_app(config_path=None): """ Create the application object """ app = Quart(__name__) # Load the config file config = read_config(config_path) app.config.update(config) app.config.update({'SQLALCHEMY_TRACK_MODIFICATIONS': False}) db.init_app(app) app.register_blueprint(views) @app.before_first_request async def setup_db(): db.create_all() return app