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