Added comments to application

This commit is contained in:
Sven Heidemann 2021-03-14 16:57:20 +01:00
parent 3f56247aa7
commit c1fe8c611c
6 changed files with 82 additions and 20 deletions

View File

@ -12,6 +12,9 @@ class ApplicationABC(ABC):
@abstractmethod @abstractmethod
def __init__(self): def __init__(self):
"""
ABC of application
"""
self._startup: Optional[StartupABC] = None self._startup: Optional[StartupABC] = None
self._app_host: Optional[ApplicationHostABC] = None self._app_host: Optional[ApplicationHostABC] = None
self._configuration: Optional[ConfigurationABC] = None self._configuration: Optional[ConfigurationABC] = None
@ -19,9 +22,18 @@ class ApplicationABC(ABC):
self._services: Optional[ServiceProviderABC] = None self._services: Optional[ServiceProviderABC] = None
def use_startup(self, startup: Type[StartupABC]): def use_startup(self, startup: Type[StartupABC]):
"""
Sets the used startup class
:param startup:
:return:
"""
self._startup = startup() self._startup = startup()
def build(self): def build(self):
"""
Creates application host and runtime
:return:
"""
if self._startup is not None: if self._startup is not None:
self._app_host = self._startup.create_application_host() self._app_host = self._startup.create_application_host()
self._runtime = self._app_host.application_runtime self._runtime = self._app_host.application_runtime
@ -29,11 +41,25 @@ class ApplicationABC(ABC):
self._services = self._startup.create_services() self._services = self._startup.create_services()
def run(self): def run(self):
"""
Entry point
:return:
"""
self.configure() self.configure()
self.main() self.main()
@abstractmethod @abstractmethod
def configure(self): pass def configure(self):
"""
Prepare the application
:return:
"""
pass
@abstractmethod @abstractmethod
def main(self): pass def main(self):
"""
Custom entry point
:return:
"""
pass

View File

@ -1,4 +1,3 @@
import atexit
from collections import Callable from collections import Callable
from cpl.application.application_host_abc import ApplicationHostABC from cpl.application.application_host_abc import ApplicationHostABC
@ -6,7 +5,6 @@ from cpl.application.application_runtime import ApplicationRuntime
from cpl.application.application_runtime_abc import ApplicationRuntimeABC from cpl.application.application_runtime_abc import ApplicationRuntimeABC
from cpl.configuration.configuration import Configuration from cpl.configuration.configuration import Configuration
from cpl.configuration.configuration_abc import ConfigurationABC from cpl.configuration.configuration_abc import ConfigurationABC
from cpl.console.console import Console
from cpl.dependency_injection.service_provider import ServiceProvider from cpl.dependency_injection.service_provider import ServiceProvider
from cpl.dependency_injection.service_provider_abc import ServiceProviderABC from cpl.dependency_injection.service_provider_abc import ServiceProviderABC
@ -14,6 +12,9 @@ from cpl.dependency_injection.service_provider_abc import ServiceProviderABC
class ApplicationHost(ApplicationHostABC): class ApplicationHost(ApplicationHostABC):
def __init__(self): def __init__(self):
"""
Representation of application host
"""
ApplicationHostABC.__init__(self) ApplicationHostABC.__init__(self)
# Init # Init
@ -33,9 +34,5 @@ class ApplicationHost(ApplicationHostABC):
def services(self) -> ServiceProviderABC: def services(self) -> ServiceProviderABC:
return self._services return self._services
@staticmethod
def output_at_exit():
atexit.register(Console.close)
def console_argument_error_function(self, function: Callable): def console_argument_error_function(self, function: Callable):
self._config.argument_error_function = function self._config.argument_error_function = function

View File

@ -9,7 +9,11 @@ from cpl.dependency_injection.service_provider_abc import ServiceProviderABC
class ApplicationHostABC(ABC): class ApplicationHostABC(ABC):
@abstractmethod @abstractmethod
def __init__(self): pass def __init__(self):
"""
ABC for application host
"""
pass
@property @property
@abstractmethod @abstractmethod
@ -23,9 +27,11 @@ class ApplicationHostABC(ABC):
@abstractmethod @abstractmethod
def services(self) -> ServiceProviderABC: pass def services(self) -> ServiceProviderABC: pass
@staticmethod
@abstractmethod @abstractmethod
def output_at_exit(): pass def console_argument_error_function(self, function: Callable):
"""
@abstractmethod Defines function to call when a argument error is detected
def console_argument_error_function(self, function: Callable): pass :param function:
:return:
"""
pass

View File

@ -8,6 +8,10 @@ from cpl.configuration.configuration_abc import ConfigurationABC
class ApplicationRuntime(ApplicationRuntimeABC): class ApplicationRuntime(ApplicationRuntimeABC):
def __init__(self, config: ConfigurationABC): def __init__(self, config: ConfigurationABC):
"""
Representation of the application runtime
:param config:
"""
ApplicationRuntimeABC.__init__(self) ApplicationRuntimeABC.__init__(self)
self._app_configuration = config self._app_configuration = config

View File

@ -7,7 +7,11 @@ from cpl.configuration.configuration_abc import ConfigurationABC
class ApplicationRuntimeABC(ABC): class ApplicationRuntimeABC(ABC):
@abstractmethod @abstractmethod
def __init__(self): pass def __init__(self):
"""
ABC for application runtime
"""
pass
@property @property
@abstractmethod @abstractmethod
@ -42,4 +46,10 @@ class ApplicationRuntimeABC(ABC):
def runtime_directory(self) -> str: pass def runtime_directory(self) -> str: pass
@abstractmethod @abstractmethod
def set_runtime_directory(self, runtime_directory: str): pass def set_runtime_directory(self, runtime_directory: str):
"""
Sets the current runtime directory
:param runtime_directory:
:return:
"""
pass

View File

@ -8,13 +8,32 @@ from cpl.dependency_injection.service_provider_abc import ServiceProviderABC
class StartupABC(ABC): class StartupABC(ABC):
@abstractmethod @abstractmethod
def __init__(self): pass def __init__(self):
"""
ABC for a startup class
"""
pass
@abstractmethod @abstractmethod
def create_application_host(self) -> ApplicationHostABC: pass def create_application_host(self) -> ApplicationHostABC:
"""
Creates application host with specific attributes
:return: application host
"""
pass
@abstractmethod @abstractmethod
def create_configuration(self) -> ConfigurationABC: pass def create_configuration(self) -> ConfigurationABC:
"""
Creates configuration of application
:return: configuration
"""
pass
@abstractmethod @abstractmethod
def create_services(self) -> ServiceProviderABC: pass def create_services(self) -> ServiceProviderABC:
"""
Creates service provider
:return: service provider
"""
pass