From 6977b9ae05d6b7a8eca8aa7d88c35c5de5bc7817 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Sun, 6 Dec 2020 21:14:57 +0100 Subject: [PATCH] Improved database module structure --- src/sh_edraft/hosting/application_host.py | 4 ++-- .../hosting/base/application_host_base.py | 2 +- src/sh_edraft/logging/logger.py | 2 +- src/sh_edraft/service/__init__.py | 1 + src/sh_edraft/service/base/__init__.py | 1 + src/sh_edraft/service/model/__init__.py | 1 + src/sh_edraft/utils/__init__.py | 1 - src/tests_dev/appsettings.development.json | 6 ------ src/tests_dev/program.py | 15 +++------------ 9 files changed, 10 insertions(+), 23 deletions(-) diff --git a/src/sh_edraft/hosting/application_host.py b/src/sh_edraft/hosting/application_host.py index d86283d0..e5e6b362 100644 --- a/src/sh_edraft/hosting/application_host.py +++ b/src/sh_edraft/hosting/application_host.py @@ -5,8 +5,8 @@ from sh_edraft.configuration.base.configuration_base import ConfigurationBase from sh_edraft.hosting.base.application_runtime_base import ApplicationRuntimeBase from sh_edraft.hosting.application_runtime import ApplicationRuntime from sh_edraft.hosting.base.application_host_base import ApplicationHostBase -from sh_edraft.service.providing.service_provider import ServiceProvider -from sh_edraft.service.providing.base.service_provider_base import ServiceProviderBase +from sh_edraft.service.service_provider import ServiceProvider +from sh_edraft.service.base.service_provider_base import ServiceProviderBase class ApplicationHost(ApplicationHostBase): diff --git a/src/sh_edraft/hosting/base/application_host_base.py b/src/sh_edraft/hosting/base/application_host_base.py index fb816ccb..4ee8c0f5 100644 --- a/src/sh_edraft/hosting/base/application_host_base.py +++ b/src/sh_edraft/hosting/base/application_host_base.py @@ -2,7 +2,7 @@ from abc import ABC, abstractmethod from sh_edraft.configuration.base.configuration_base import ConfigurationBase from sh_edraft.hosting.base.application_runtime_base import ApplicationRuntimeBase -from sh_edraft.service.providing.base.service_provider_base import ServiceProviderBase +from sh_edraft.service.base.service_provider_base import ServiceProviderBase class ApplicationHostBase(ABC): diff --git a/src/sh_edraft/logging/logger.py b/src/sh_edraft/logging/logger.py index dbc54740..f2159ad2 100644 --- a/src/sh_edraft/logging/logger.py +++ b/src/sh_edraft/logging/logger.py @@ -54,7 +54,7 @@ class Logger(LoggerBase): # open log file, create if not exists path = f'{self._path}{self._log}' f = open(path, "w+") - Console.write_line(f'[{__name__}]: Using log file: {path}', 'green') + Console.write_line(f'[{__name__}]: Using log file: {path}') f.close() except Exception as e: self._fatal_console(__name__, 'Cannot open log file', ex=e) diff --git a/src/sh_edraft/service/__init__.py b/src/sh_edraft/service/__init__.py index abfc6044..52003f0b 100644 --- a/src/sh_edraft/service/__init__.py +++ b/src/sh_edraft/service/__init__.py @@ -20,6 +20,7 @@ __version__ = '2020.12.5' from collections import namedtuple # imports: +from .service_provider import ServiceProvider VersionInfo = namedtuple('VersionInfo', 'major minor micro') version_info = VersionInfo(major=2020, minor=12, micro=5) diff --git a/src/sh_edraft/service/base/__init__.py b/src/sh_edraft/service/base/__init__.py index d3d865d7..6ce7f45b 100644 --- a/src/sh_edraft/service/base/__init__.py +++ b/src/sh_edraft/service/base/__init__.py @@ -21,6 +21,7 @@ from collections import namedtuple # imports: from .service_base import ServiceBase +from .service_provider_base import ServiceProviderBase VersionInfo = namedtuple('VersionInfo', 'major minor micro') version_info = VersionInfo(major=2020, minor=12, micro=5) diff --git a/src/sh_edraft/service/model/__init__.py b/src/sh_edraft/service/model/__init__.py index 05760565..b95fe3c2 100644 --- a/src/sh_edraft/service/model/__init__.py +++ b/src/sh_edraft/service/model/__init__.py @@ -20,6 +20,7 @@ __version__ = '2020.12.5' from collections import namedtuple # imports: +from .provide_state import ProvideState VersionInfo = namedtuple('VersionInfo', 'major minor micro') version_info = VersionInfo(major=2020, minor=12, micro=5) diff --git a/src/sh_edraft/utils/__init__.py b/src/sh_edraft/utils/__init__.py index 10d2e9e5..4130c05d 100644 --- a/src/sh_edraft/utils/__init__.py +++ b/src/sh_edraft/utils/__init__.py @@ -21,7 +21,6 @@ from collections import namedtuple # imports: from .console import Console -from .credential_manager import CredentialManager VersionInfo = namedtuple('VersionInfo', 'major minor micro') version_info = VersionInfo(major=2020, minor=12, micro=5) diff --git a/src/tests_dev/appsettings.development.json b/src/tests_dev/appsettings.development.json index aa370960..62ec6c61 100644 --- a/src/tests_dev/appsettings.development.json +++ b/src/tests_dev/appsettings.development.json @@ -4,11 +4,5 @@ "Filename": "log_$start_time.log", "ConsoleLogLevel": "TRACE", "FileLogLevel": "TRACE" - }, - - "DatabaseSettings": { - "ConnectionString": "mysql+mysqlconnector://sh_messenger_server:$credentials@localhost/sh_messenger_server", - "Credentials": "ZkM1U1dyU0hXM3oyI3BfXg==", - "Encoding": "utf8mb4" } } \ No newline at end of file diff --git a/src/tests_dev/program.py b/src/tests_dev/program.py index e17733be..2ee1b09b 100644 --- a/src/tests_dev/program.py +++ b/src/tests_dev/program.py @@ -1,13 +1,11 @@ from typing import Optional from sh_edraft.configuration.base import ConfigurationBase -from sh_edraft.database import DatabaseConnection -from sh_edraft.database.base import DatabaseConnectionBase 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 +from sh_edraft.service.base import ServiceProviderBase class Program(ApplicationBase): @@ -19,7 +17,6 @@ class Program(ApplicationBase): self._services: Optional[ServiceProviderBase] = None self._configuration: Optional[ConfigurationBase] = None self._logger: Optional[LoggerBase] = None - self._db_connection: Optional[DatabaseConnectionBase] = None def create_application_host(self): self._app_host = ApplicationHost() @@ -33,19 +30,13 @@ class Program(ApplicationBase): 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 - ) + self._configuration.add_json_file(f'appsettings.{self._configuration.environment.host_name}.json', optional=True) 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) + self._logger = self._services.get_service(LoggerBase) self._logger.create() - self._db_connection: DatabaseConnection = self._services.get_service(DatabaseConnectionBase) - self._db_connection.create() def main(self): self._logger.header(f'{self._configuration.environment.application_name}:')