codesmidgen/stickynotes/__init__.py

44 lines
1.1 KiB
Python
Raw Normal View History

2016-01-08 21:41:24 +00:00
# -*- coding: utf-8 -*-
"""
StickyNotes, yet another paste bin
"""
from configparser import ConfigParser
from pathlib import Path
2016-01-08 21:41:24 +00:00
from flask import Flask
from stickynotes.db import db
from stickynotes.views import views
2016-01-08 21:41:24 +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
"""
if config_path:
config_file = config_path / 'stickynotes.cfg'
else:
config_file = Path(__file__).parent / '..' / 'stickynotes.cfg'
config_parser = ConfigParser()
2016-01-08 21:41:24 +00:00
config_parser.read(config_file)
config = {}
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
def make_app(config_path=None):
2016-01-08 21:41:24 +00:00
"""
Create the application object
"""
app = Flask(__name__)
# Load the config file
config = read_config(config_path)
2016-01-08 21:41:24 +00:00
app.config.update(config)
app.config.update({'SQLALCHEMY_TRACK_MODIFICATIONS': False})
db.init_app(app)
with app.app_context():
db.create_all()
2016-01-08 21:41:24 +00:00
app.register_blueprint(views)
return app