flaschengeist/geruecht/__init__.py

79 lines
2.2 KiB
Python

""" Server-package
Initialize app, cors, database and bcrypt (for passwordhashing) and added it to the application.
Initialize also a singelton for the AccesTokenControler and start the Thread.
"""
import logging
from logging.handlers import WatchedFileHandler
import sys
MONEY = "moneymaster"
GASTRO = "gastro"
USER = "user"
BAR = "bar"
FORMATTER = logging.Formatter("%(asctime)s%(name)s%(levelname)s%(message)s")
logFileHandler = WatchedFileHandler("testlog.log")
logFileHandler.setFormatter(FORMATTER)
logStreamHandler = logging.StreamHandler(stream=sys.stdout)
logStreamHandler.setFormatter(FORMATTER)
def getLogger(logger_name):
logger = logging.getLogger(logger_name)
logger.setLevel(logging.DEBUG)
logger.addHandler(logFileHandler)
logger.addHandler(logStreamHandler)
logger.propagate = False
return logger
LOGGER = getLogger(__name__)
LOGGER.info("Initialize App")
class Singleton(type):
_instances = {}
def __call__(cls, *args, **kwargs):
if cls not in cls._instances:
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
return cls._instances[cls]
from .controller.databaseController import DatabaseController
db = DatabaseController()
from .controller.ldapController import LDAPController
ldapController = LDAPController()
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_bcrypt import Bcrypt
from flask_cors import CORS
from .controller.accesTokenController import AccesTokenController
# from flask_login import LoginManager
LOGGER.info("Build APP")
app = Flask(__name__)
CORS(app)
# app.config['SECRET_KEY'] = '0a657b97ef546da90b2db91862ad4e29'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db'
#db = SQLAlchemy(app)
bcrypt = Bcrypt(app)
accesTokenController = AccesTokenController("GERUECHT")
accesTokenController.start()
# login_manager = LoginManager(app)
# login_manager.login_view = 'login'
# login_manager.login_message_category = 'info'
from geruecht import routes
#from geruecht.baruser.routes import baruser
#from geruecht.finanzer.routes import finanzer
#LOGGER.info("Registrate bluebrints")
#app.register_blueprint(baruser)
#app.register_blueprint(finanzer)