2023-09-26 20:00:26 +00:00
|
|
|
# pylint: disable=too-few-public-methods
|
|
|
|
|
2023-09-26 20:54:40 +00:00
|
|
|
from datetime import datetime
|
2023-09-26 20:00:26 +00:00
|
|
|
from flask import Flask
|
|
|
|
from flask_smorest import Api
|
2023-11-24 19:50:18 +00:00
|
|
|
from .config import APISettings
|
2023-09-26 20:00:26 +00:00
|
|
|
|
|
|
|
class IsSingletonException(Exception):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class Application:
|
|
|
|
"""
|
|
|
|
This is a singleton that can be accessed using get_instance()
|
|
|
|
|
|
|
|
It has 2 properties
|
|
|
|
- app: Used for WSGI servers and such
|
|
|
|
- api: Used for Blueprints
|
|
|
|
"""
|
2023-11-24 19:50:18 +00:00
|
|
|
|
2023-09-26 20:00:26 +00:00
|
|
|
__instance = None
|
|
|
|
app = Flask(__name__)
|
2023-11-24 19:50:18 +00:00
|
|
|
app.config.from_object(APISettings)
|
2023-09-26 20:00:26 +00:00
|
|
|
api = None
|
2023-09-26 20:54:40 +00:00
|
|
|
alive_since = None
|
2023-09-26 20:00:26 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_instance():
|
|
|
|
if Application.__instance is None:
|
|
|
|
Application()
|
|
|
|
return Application.__instance
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
if Application.__instance is not None:
|
|
|
|
raise IsSingletonException("This class is a singleton")
|
|
|
|
Application.__instance = self
|
|
|
|
self.api = Api(self.app)
|
2023-09-26 20:54:40 +00:00
|
|
|
self.alive_since = datetime.now()
|