Improved hosting

This commit is contained in:
Sven Heidemann 2020-11-26 11:20:21 +01:00
parent 5faac76c32
commit ead0eae5f0
19 changed files with 124 additions and 37 deletions

View File

@ -10,7 +10,6 @@ class ConfigurationBase(ServiceBase):
@abstractmethod @abstractmethod
def __init__(self): def __init__(self):
ServiceBase.__init__(self) ServiceBase.__init__(self)
self._config: dict[type, object] = {}
@property @property
@abstractmethod @abstractmethod

View File

@ -9,6 +9,8 @@ class Configuration(ConfigurationBase):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self._config: dict[type, object] = {}
@property @property
def config(self): def config(self):
return self._config return self._config

View File

@ -1,3 +1,4 @@
# imports: # imports:
from .application_host import ApplicationHost from .application_host import ApplicationHost
from .hosting_environment import HostingEnvironment

View File

@ -1,17 +1,29 @@
from datetime import datetime from datetime import datetime
from sh_edraft.hosting.base.application_host_base import ApplicationHostBase from sh_edraft.hosting.base.application_host_base import ApplicationHostBase
from sh_edraft.hosting.base.environment_base import EnvironmentBase
from sh_edraft.service.service_provider import ServiceProvider from sh_edraft.service.service_provider import ServiceProvider
class ApplicationHost(ApplicationHostBase): class ApplicationHost(ApplicationHostBase):
def __init__(self): def __init__(self, name: str, env: EnvironmentBase):
ApplicationHostBase.__init__(self) ApplicationHostBase.__init__(self)
self._services = ServiceProvider() self._name: str = name
self._environment: EnvironmentBase = env
self._services = ServiceProvider(self)
self._start_time: datetime = datetime.now() self._start_time: datetime = datetime.now()
self._end_time: datetime = datetime.now() self._end_time: datetime = datetime.now()
@property
def name(self) -> str:
return self._name
@property
def environment(self) -> EnvironmentBase:
return self._environment
@property @property
def services(self): def services(self):
return self._services return self._services

View File

@ -1,2 +1,3 @@
# imports: # imports:
from .application_host_base import ApplicationHostBase from .application_host_base import ApplicationHostBase
from .environment_base import EnvironmentBase

View File

@ -1,17 +1,28 @@
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from datetime import datetime from datetime import datetime
from sh_edraft.hosting.base.environment_base import EnvironmentBase
class ApplicationHostBase(ABC): class ApplicationHostBase(ABC):
@abstractmethod @abstractmethod
def __init__(self): pass def __init__(self): pass
@property
@abstractmethod
def name(self) -> str: pass
@property
@abstractmethod
def environment(self) -> EnvironmentBase: pass
@property @property
@abstractmethod @abstractmethod
def start_time(self) -> datetime: pass def start_time(self) -> datetime: pass
@start_time.setter @start_time.setter
@abstractmethod
def start_time(self, start_time: datetime): pass def start_time(self, start_time: datetime): pass
@property @property
@ -19,4 +30,9 @@ class ApplicationHostBase(ABC):
def end_time(self): pass def end_time(self): pass
@end_time.setter @end_time.setter
@abstractmethod
def end_time(self, end_time: datetime): pass def end_time(self, end_time: datetime): pass
@property
@abstractmethod
def date_time_now(self) -> datetime: pass

View File

@ -0,0 +1,25 @@
from abc import ABC, abstractmethod
from sh_edraft.hosting.model.environment_name import EnvironmentName
class EnvironmentBase(ABC):
@abstractmethod
def __init__(self): pass
@property
@abstractmethod
def name(self) -> EnvironmentName: pass
@name.setter
@abstractmethod
def name(self, name: EnvironmentName): pass
@property
@abstractmethod
def content_root_path(self) -> str: pass
@content_root_path.setter
@abstractmethod
def content_root_path(self, content_root_path: str): pass

View File

@ -0,0 +1,20 @@
from sh_edraft.hosting.base.environment_base import EnvironmentBase
from sh_edraft.hosting.model.environment_name import EnvironmentName
class HostingEnvironment(EnvironmentBase):
def __init__(self, name: EnvironmentName, crp: str):
EnvironmentBase.__init__(self)
self._name = name
self._content_root_path = crp
@property
def name(self) -> EnvironmentName:
return self._name
@property
def content_root_path(self) -> str:
return self._content_root_path

View File

@ -0,0 +1,2 @@
# imports:
from .environment_name import EnvironmentName

View File

@ -0,0 +1,9 @@
from enum import Enum
class EnvironmentName(Enum):
production = 'production'
staging = 'staging'
testing = 'testing'
development = 'development'

View File

@ -1,20 +1,14 @@
from abc import abstractmethod from abc import abstractmethod
from sh_edraft.hosting.application_host import ApplicationHost
from sh_edraft.logging.model.logging_settings import LoggingSettings
from sh_edraft.service.base.service_base import ServiceBase from sh_edraft.service.base.service_base import ServiceBase
from sh_edraft.time.model.time_format_settings import TimeFormatSettings
class LoggerBase(ServiceBase): class LoggerBase(ServiceBase):
@abstractmethod @abstractmethod
def __init__(self, logging_settings: LoggingSettings, time_format: TimeFormatSettings): def __init__(self):
ServiceBase.__init__(self) ServiceBase.__init__(self)
self._log_settings: LoggingSettings = logging_settings
self._time_format_settings: TimeFormatSettings = time_format
@abstractmethod @abstractmethod
def header(self, string: str): pass def header(self, string: str): pass

View File

@ -1,10 +1,9 @@
import datetime import datetime
import os import os
import traceback import traceback
from collections import Callable
from string import Template from string import Template
from sh_edraft.hosting.application_host import ApplicationHost from sh_edraft.hosting.base import ApplicationHostBase
from sh_edraft.logging.base.logger_base import LoggerBase from sh_edraft.logging.base.logger_base import LoggerBase
from sh_edraft.logging.model import LoggingSettings from sh_edraft.logging.model import LoggingSettings
from sh_edraft.logging.model.logging_level import LoggingLevel from sh_edraft.logging.model.logging_level import LoggingLevel
@ -14,10 +13,12 @@ from sh_edraft.utils.console import Console
class Logger(LoggerBase): class Logger(LoggerBase):
def __init__(self, logging_settings: LoggingSettings, time_format: TimeFormatSettings, app_host: ApplicationHost): def __init__(self, logging_settings: LoggingSettings, time_format: TimeFormatSettings, app_host: ApplicationHostBase):
LoggerBase.__init__(self, logging_settings, time_format) LoggerBase.__init__(self)
self._app_host: ApplicationHost = app_host self._log_settings: LoggingSettings = logging_settings
self._time_format_settings: TimeFormatSettings = time_format
self._app_host = app_host
self._log = Template(self._log_settings.filename).substitute( self._log = Template(self._log_settings.filename).substitute(
date_time_now=self._app_host.date_time_now.strftime(self._time_format_settings.date_time_format), date_time_now=self._app_host.date_time_now.strftime(self._time_format_settings.date_time_format),

View File

@ -1,19 +1,14 @@
from abc import abstractmethod from abc import abstractmethod
from sh_edraft.logging.base.logger_base import LoggerBase
from sh_edraft.publishing.model.publish_settings_model import PublishSettingsModel
from sh_edraft.service.base.service_base import ServiceBase from sh_edraft.service.base.service_base import ServiceBase
class PublisherBase(ServiceBase): class PublisherBase(ServiceBase):
@abstractmethod @abstractmethod
def __init__(self, logger: LoggerBase, publish_settings: PublishSettingsModel): def __init__(self):
ServiceBase.__init__(self) ServiceBase.__init__(self)
self._logger: LoggerBase = logger
self._publish_settings: PublishSettingsModel = publish_settings
@property @property
@abstractmethod @abstractmethod
def source_path(self) -> str: pass def source_path(self) -> str: pass

View File

@ -22,6 +22,8 @@ from collections import namedtuple
# imports: # imports:
from .template import Template from .template import Template
from .template_enum import TemplateEnum from .template_enum import TemplateEnum
from .publish_settings_model import PublishSettingsModel
from .publish_settings_name import PublishSettingsName
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major=2020, minor=12, micro=5) version_info = VersionInfo(major=2020, minor=12, micro=5)

View File

@ -11,7 +11,10 @@ from sh_edraft.publishing.model.template import Template
class Publisher(PublisherBase): class Publisher(PublisherBase):
def __init__(self, logger: LoggerBase, publish_settings: PublishSettingsModel): def __init__(self, logger: LoggerBase, publish_settings: PublishSettingsModel):
super().__init__(logger, publish_settings) PublisherBase.__init__(self)
self._logger: LoggerBase = logger
self._publish_settings: PublishSettingsModel = publish_settings
@property @property
def source_path(self) -> str: def source_path(self) -> str:

View File

@ -11,8 +11,9 @@ from sh_edraft.service.base.service_base import ServiceBase
class ServiceProvider(ServiceProviderBase): class ServiceProvider(ServiceProviderBase):
def __init__(self): def __init__(self, app_host: ApplicationHostBase):
super().__init__() super().__init__()
self._app_host: ApplicationHostBase = app_host
self._config = Configuration() self._config = Configuration()
@property @property
@ -27,10 +28,13 @@ class ServiceProvider(ServiceProviderBase):
for param in sig.parameters.items(): for param in sig.parameters.items():
parameter = param[1] parameter = param[1]
if parameter.name != 'self' and parameter.annotation != Parameter.empty: if parameter.name != 'self' and parameter.annotation != Parameter.empty:
if issubclass(parameter.annotation, ServiceBase): if issubclass(parameter.annotation, ApplicationHostBase):
params.append(self._app_host)
elif issubclass(parameter.annotation, ServiceBase):
params.append(self.get_service(parameter.annotation)) params.append(self.get_service(parameter.annotation))
elif issubclass(parameter.annotation, ConfigurationModelBase) or issubclass(parameter.annotation, ApplicationHostBase): elif issubclass(parameter.annotation, ConfigurationModelBase):
params.append(self._config.get_config_by_type(parameter.annotation)) params.append(self._config.get_config_by_type(parameter.annotation))
return service(*params) return service(*params)

View File

@ -1,10 +1,10 @@
import os import os
import shutil import shutil
import unittest import unittest
from datetime import datetime
from string import Template from string import Template
from sh_edraft.hosting import ApplicationHost from sh_edraft.hosting import ApplicationHost, HostingEnvironment
from sh_edraft.hosting.model import EnvironmentName
from sh_edraft.logging import Logger from sh_edraft.logging import Logger
from sh_edraft.logging.model import LoggingSettings from sh_edraft.logging.model import LoggingSettings
from sh_edraft.time.model import TimeFormatSettings from sh_edraft.time.model import TimeFormatSettings
@ -13,7 +13,7 @@ from sh_edraft.time.model import TimeFormatSettings
class LoggerTest(unittest.TestCase): class LoggerTest(unittest.TestCase):
def setUp(self): def setUp(self):
self._app_host = ApplicationHost() self._app_host = ApplicationHost('CPL_Test', HostingEnvironment(EnvironmentName.testing, './'))
self._services = self._app_host.services self._services = self._app_host.services
self._services.create() self._services.create()

View File

@ -2,14 +2,13 @@ import os
import shutil import shutil
import unittest import unittest
from sh_edraft.hosting import ApplicationHost from sh_edraft.hosting import ApplicationHost, HostingEnvironment
from sh_edraft.hosting.model import EnvironmentName
from sh_edraft.logging import Logger from sh_edraft.logging import Logger
from sh_edraft.logging.base import LoggerBase
from sh_edraft.logging.model import LoggingSettings from sh_edraft.logging.model import LoggingSettings
from sh_edraft.publishing import Publisher from sh_edraft.publishing import Publisher
from sh_edraft.publishing.base import PublisherBase
from sh_edraft.publishing.model import Template from sh_edraft.publishing.model import Template
from sh_edraft.publishing.model.publish_settings_model import PublishSettingsModel from sh_edraft.publishing.model import PublishSettingsModel
from sh_edraft.coding.model import Version from sh_edraft.coding.model import Version
from sh_edraft.time.model import TimeFormatSettings from sh_edraft.time.model import TimeFormatSettings
@ -79,7 +78,7 @@ class PublisherTest(unittest.TestCase):
def setUp(self): def setUp(self):
self._config() self._config()
self._app_host = ApplicationHost() self._app_host = ApplicationHost('CPL_Test', HostingEnvironment(EnvironmentName.testing, './'))
self._logger = Logger(self._log_settings, self._time_format_settings, self._app_host) self._logger = Logger(self._log_settings, self._time_format_settings, self._app_host)
self._logger.create() self._logger.create()

View File

@ -1,12 +1,14 @@
import unittest import unittest
from sh_edraft.hosting import ApplicationHost from sh_edraft.hosting import ApplicationHost
from sh_edraft.hosting import HostingEnvironment
from sh_edraft.hosting.model import EnvironmentName
from sh_edraft.logging import Logger from sh_edraft.logging import Logger
from sh_edraft.logging.base import LoggerBase from sh_edraft.logging.base import LoggerBase
from sh_edraft.logging.model import LoggingSettings from sh_edraft.logging.model import LoggingSettings
from sh_edraft.publishing import Publisher from sh_edraft.publishing import Publisher
from sh_edraft.publishing.base import PublisherBase from sh_edraft.publishing.base import PublisherBase
from sh_edraft.publishing.model.publish_settings_model import PublishSettingsModel from sh_edraft.publishing.model import PublishSettingsModel
from sh_edraft.service import ServiceProvider from sh_edraft.service import ServiceProvider
from sh_edraft.service.base import ServiceBase from sh_edraft.service.base import ServiceBase
from sh_edraft.time.model import TimeFormatSettings from sh_edraft.time.model import TimeFormatSettings
@ -15,7 +17,7 @@ from sh_edraft.time.model import TimeFormatSettings
class ServiceProviderTest(unittest.TestCase): class ServiceProviderTest(unittest.TestCase):
def setUp(self): def setUp(self):
self._app_host = ApplicationHost() self._app_host = ApplicationHost('CPL_Test', HostingEnvironment(EnvironmentName.testing, './'))
self._services = self._app_host.services self._services = self._app_host.services
self._services.create() self._services.create()
@ -59,7 +61,7 @@ class ServiceProviderTest(unittest.TestCase):
def test_create(self): def test_create(self):
print(f'{__name__}.test_create:') print(f'{__name__}.test_create:')
provider = ServiceProvider() provider = ServiceProvider(self._app_host)
self.assertIsNotNone(provider) self.assertIsNotNone(provider)
provider.create() provider.create()
self.assertIsNotNone(provider) self.assertIsNotNone(provider)