sh_cpl/src/tests_dev/program.py

55 lines
2.4 KiB
Python
Raw Normal View History

from typing import Optional
from sh_edraft.configuration.base import ConfigurationBase
from sh_edraft.database import DatabaseConnection
from sh_edraft.database.base import DatabaseConnectionBase
2020-11-26 17:57:51 +01:00
from sh_edraft.hosting import ApplicationHost
from sh_edraft.hosting.base import ApplicationBase
from sh_edraft.logging import Logger
from sh_edraft.logging.base import LoggerBase
from sh_edraft.service.providing.base import ServiceProviderBase
2020-11-26 17:57:51 +01:00
class Program(ApplicationBase):
def __init__(self):
ApplicationBase.__init__(self)
self._app_host: Optional[ApplicationHost] = None
self._services: Optional[ServiceProviderBase] = None
self._configuration: Optional[ConfigurationBase] = None
2020-11-29 17:29:16 +01:00
self._logger: Optional[LoggerBase] = None
self._db_connection: Optional[DatabaseConnectionBase] = None
def create_application_host(self):
self._app_host = ApplicationHost()
self._configuration = self._app_host.configuration
2020-11-29 17:29:16 +01:00
self._services = self._app_host.services
2020-11-26 17:57:51 +01:00
def create_configuration(self):
self._configuration.create()
self._configuration.add_environment_variables('PYTHON_')
self._configuration.add_environment_variables('CPL_')
self._configuration.add_argument_variables()
self._configuration.add_json_file(f'appsettings.json')
self._configuration.add_json_file(f'appsettings.{self._configuration.environment.environment_name}.json')
self._configuration.add_json_file(
f'appsettings.{self._configuration.environment.host_name}.json',
optional=True
)
2020-11-26 17:57:51 +01:00
def create_services(self):
self._services.create()
self._services.add_singleton(LoggerBase, Logger)
self._services.add_singleton(DatabaseConnectionBase, DatabaseConnection)
self._logger: Logger = self._services.get_service(LoggerBase)
2020-11-29 17:29:16 +01:00
self._logger.create()
self._db_connection: DatabaseConnection = self._services.get_service(DatabaseConnectionBase)
self._db_connection.create()
2020-11-26 17:57:51 +01:00
def main(self):
2020-11-29 17:29:16 +01:00
self._logger.header(f'{self._configuration.environment.application_name}:')
self._logger.debug(__name__, f'Host: {self._configuration.environment.host_name}')
self._logger.debug(__name__, f'Environment: {self._configuration.environment.environment_name}')
self._logger.debug(__name__, f'Customer: {self._configuration.environment.customer}')