codesmidgen/stickynotes/__init__.py

44 lines
1.1 KiB
Python

# -*- coding: utf-8 -*-
"""
StickyNotes, yet another paste bin
"""
from configparser import ConfigParser
from pathlib import Path
from flask import Flask
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'
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 = Flask(__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)
with app.app_context():
db.create_all()
app.register_blueprint(views)
return app