Merge pull request '2020.12.5' (#2) from 2020.12.5 into 2020.12
Reviewed-on: http://git.sh-edraft.de/sh-edraft.de/sh_common_py_lib/pulls/2
This commit is contained in:
commit
dd65bbb182
@ -15,11 +15,11 @@ __title__ = 'sh_edraft'
|
|||||||
__author__ = 'Sven Heidemann'
|
__author__ = 'Sven Heidemann'
|
||||||
__license__ = 'MIT'
|
__license__ = 'MIT'
|
||||||
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
||||||
__version__ = '2020.12.0.1'
|
__version__ = '2020.12.5'
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
|
# imports:
|
||||||
|
|
||||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||||
version_info = VersionInfo(major=2020, minor=12, micro=0.1)
|
version_info = VersionInfo(major=2020, minor=12, micro=5)
|
||||||
|
@ -15,11 +15,12 @@ __title__ = 'sh_edraft.configuration'
|
|||||||
__author__ = 'Sven Heidemann'
|
__author__ = 'Sven Heidemann'
|
||||||
__license__ = 'MIT'
|
__license__ = 'MIT'
|
||||||
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
||||||
__version__ = '2020.12.0.1'
|
__version__ = '2020.12.5'
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
|
# imports:
|
||||||
|
from .application_host import ApplicationHost
|
||||||
|
|
||||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||||
version_info = VersionInfo(major=2020, minor=12, micro=0.1)
|
version_info = VersionInfo(major=2020, minor=12, micro=5)
|
||||||
|
35
src/sh_edraft/configuration/application_host.py
Normal file
35
src/sh_edraft/configuration/application_host.py
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
from sh_edraft.service import ServiceProvider
|
||||||
|
|
||||||
|
|
||||||
|
class ApplicationHost:
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self._services = ServiceProvider()
|
||||||
|
self._end_time: datetime = datetime.now()
|
||||||
|
self._start_time: datetime = datetime.now()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def services(self):
|
||||||
|
return self._services
|
||||||
|
|
||||||
|
@property
|
||||||
|
def end_time(self) -> datetime:
|
||||||
|
return self._end_time
|
||||||
|
|
||||||
|
@end_time.setter
|
||||||
|
def end_time(self, end_time: datetime) -> None:
|
||||||
|
self._end_time = end_time
|
||||||
|
|
||||||
|
@property
|
||||||
|
def start_time(self) -> datetime:
|
||||||
|
return self._start_time
|
||||||
|
|
||||||
|
@start_time.setter
|
||||||
|
def start_time(self, start_time: datetime) -> None:
|
||||||
|
self._start_time = start_time
|
||||||
|
|
||||||
|
@property
|
||||||
|
def date_time_now(self) -> datetime:
|
||||||
|
return datetime.now()
|
@ -15,12 +15,12 @@ __title__ = 'sh_edraft.configuration.model'
|
|||||||
__author__ = 'Sven Heidemann'
|
__author__ = 'Sven Heidemann'
|
||||||
__license__ = 'MIT'
|
__license__ = 'MIT'
|
||||||
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
||||||
__version__ = '2020.12.0.1'
|
__version__ = '2020.12.5'
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
# imports:
|
# imports:
|
||||||
from sh_edraft.configuration.model.configuration_model_base import ConfigurationModelBase
|
from .configuration_model_base import ConfigurationModelBase
|
||||||
|
|
||||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||||
version_info = VersionInfo(major=2020, minor=12, micro=0.1)
|
version_info = VersionInfo(major=2020, minor=12, micro=5)
|
||||||
|
@ -5,6 +5,3 @@ class ConfigurationModelBase(ABC):
|
|||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def from_dict(self, settings: dict): pass
|
def from_dict(self, settings: dict): pass
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def to_dict(self) -> dict: pass
|
|
||||||
|
@ -15,11 +15,11 @@ __title__ = 'sh_edraft.discord'
|
|||||||
__author__ = 'Sven Heidemann'
|
__author__ = 'Sven Heidemann'
|
||||||
__license__ = 'MIT'
|
__license__ = 'MIT'
|
||||||
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
||||||
__version__ = '2020.12.0.1'
|
__version__ = '2020.12.5'
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||||
version_info = VersionInfo(major=2020, minor=12, micro=0.1)
|
version_info = VersionInfo(major=2020, minor=12, micro=5)
|
||||||
|
@ -15,11 +15,12 @@ __title__ = 'sh_edraft.logging'
|
|||||||
__author__ = 'Sven Heidemann'
|
__author__ = 'Sven Heidemann'
|
||||||
__license__ = 'MIT'
|
__license__ = 'MIT'
|
||||||
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
||||||
__version__ = '2020.12.0.1'
|
__version__ = '2020.12.5'
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
|
# imports:
|
||||||
|
from .logger import Logger
|
||||||
|
|
||||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||||
version_info = VersionInfo(major=2020, minor=12, micro=0.1)
|
version_info = VersionInfo(major=2020, minor=12, micro=5)
|
||||||
|
26
src/sh_edraft/logging/base/__init__.py
Normal file
26
src/sh_edraft/logging/base/__init__.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
"""
|
||||||
|
sh_edraft.logging.base
|
||||||
|
~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
:copyright: (c) 2020 sh-edraft.de
|
||||||
|
:license: MIT, see LICENSE for more details.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
__title__ = 'sh_edraft.logging.base'
|
||||||
|
__author__ = 'Sven Heidemann'
|
||||||
|
__license__ = 'MIT'
|
||||||
|
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
||||||
|
__version__ = '2020.12.5'
|
||||||
|
|
||||||
|
from collections import namedtuple
|
||||||
|
|
||||||
|
# imports:
|
||||||
|
from .logger_base import LoggerBase
|
||||||
|
|
||||||
|
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||||
|
version_info = VersionInfo(major=2020, minor=12, micro=5)
|
31
src/sh_edraft/logging/base/logger_base.py
Normal file
31
src/sh_edraft/logging/base/logger_base.py
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
from abc import abstractmethod
|
||||||
|
|
||||||
|
from sh_edraft.service.base import ServiceBase
|
||||||
|
|
||||||
|
|
||||||
|
class LoggerBase(ServiceBase):
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def __init__(self):
|
||||||
|
ServiceBase.__init__(self)
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def header(self, string: str): pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def trace(self, name: str, message: str): pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def debug(self, name: str, message: str): pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def info(self, name: str, message: str): pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def warn(self, name: str, message: str): pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def error(self, name: str, message: str, ex: Exception = None): pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def fatal(self, name: str, message: str, ex: Exception = None): pass
|
169
src/sh_edraft/logging/logger.py
Normal file
169
src/sh_edraft/logging/logger.py
Normal file
@ -0,0 +1,169 @@
|
|||||||
|
import datetime
|
||||||
|
import os
|
||||||
|
import traceback
|
||||||
|
from string import Template
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
from sh_edraft.configuration.application_host import ApplicationHost
|
||||||
|
from sh_edraft.logging.base.logger_base import LoggerBase
|
||||||
|
from sh_edraft.logging.model.log_level import LoggingLevel
|
||||||
|
from sh_edraft.logging.model.log_settings import LoggingSettings
|
||||||
|
from sh_edraft.time.model.time_format_settings import TimeFormatSettings
|
||||||
|
from sh_edraft.utils.console import Console
|
||||||
|
|
||||||
|
|
||||||
|
class Logger(LoggerBase):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
LoggerBase.__init__(self)
|
||||||
|
|
||||||
|
self._log_settings: Optional[LoggingSettings] = None
|
||||||
|
self._time_format_settings: Optional[TimeFormatSettings] = None
|
||||||
|
self._app_host: Optional[ApplicationHost] = None
|
||||||
|
|
||||||
|
self._log: Optional[str] = None
|
||||||
|
self._path: Optional[str] = None
|
||||||
|
self._level: Optional[LoggingLevel] = None
|
||||||
|
self._console: Optional[LoggingLevel] = None
|
||||||
|
|
||||||
|
def init(self, args: tuple):
|
||||||
|
self._log_settings = args[0]
|
||||||
|
self._time_format_settings = args[1]
|
||||||
|
self._app_host = args[2]
|
||||||
|
|
||||||
|
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),
|
||||||
|
start_time=self._app_host.start_time.strftime(self._time_format_settings.date_time_log_format)
|
||||||
|
)
|
||||||
|
self._path = self._log_settings.path
|
||||||
|
self._level = self._log_settings.level
|
||||||
|
self._console = self._log_settings.console
|
||||||
|
|
||||||
|
def _get_datetime_now(self) -> str:
|
||||||
|
try:
|
||||||
|
return datetime.datetime.now().strftime(self._time_format_settings.date_time_format)
|
||||||
|
except Exception as e:
|
||||||
|
self.error(__name__, 'Cannot get time', ex=e)
|
||||||
|
|
||||||
|
def _get_date(self) -> str:
|
||||||
|
try:
|
||||||
|
return datetime.datetime.now().strftime(self._time_format_settings.date_format)
|
||||||
|
except Exception as e:
|
||||||
|
self.error(__name__, 'Cannot get date', ex=e)
|
||||||
|
|
||||||
|
def create(self) -> None:
|
||||||
|
""" path """
|
||||||
|
try:
|
||||||
|
# check if log file path exists
|
||||||
|
if not os.path.exists(self._path):
|
||||||
|
os.mkdir(self._path)
|
||||||
|
except Exception as e:
|
||||||
|
self.fatal(__name__, 'Cannot create log dir', ex=e)
|
||||||
|
|
||||||
|
""" create new log file """
|
||||||
|
try:
|
||||||
|
# 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}')
|
||||||
|
f.close()
|
||||||
|
except Exception as e:
|
||||||
|
self.fatal(__name__, 'Cannot open log file', ex=e)
|
||||||
|
|
||||||
|
def _append_log(self, string):
|
||||||
|
try:
|
||||||
|
# open log file and append always
|
||||||
|
with open(self._path + self._log, "a+", encoding="utf-8") as f:
|
||||||
|
f.write(string + '\n')
|
||||||
|
f.close()
|
||||||
|
except Exception as e:
|
||||||
|
self.error(__name__, f'Cannot append log file, message: {string}', ex=e)
|
||||||
|
|
||||||
|
def _get_string(self, name: str, level: LoggingLevel, message: str) -> str:
|
||||||
|
log_level = level.name
|
||||||
|
return f'<{self._get_datetime_now()}> [ {log_level} ] [ {name} ]: {message}'
|
||||||
|
|
||||||
|
def header(self, string: str):
|
||||||
|
# append log and print message
|
||||||
|
self._append_log(string)
|
||||||
|
Console.write_line(string, 'white')
|
||||||
|
|
||||||
|
def trace(self, name: str, message: str):
|
||||||
|
output = self._get_string(name, LoggingLevel.TRACE, message)
|
||||||
|
|
||||||
|
# check if message can be written to log
|
||||||
|
if self._level.value >= LoggingLevel.TRACE.value:
|
||||||
|
self._append_log(output)
|
||||||
|
|
||||||
|
# check if message can be shown in console
|
||||||
|
if self._console.value >= LoggingLevel.TRACE.value:
|
||||||
|
Console.write_line(output, 'green')
|
||||||
|
|
||||||
|
def debug(self, name: str, message: str):
|
||||||
|
output = self._get_string(name, LoggingLevel.DEBUG, message)
|
||||||
|
|
||||||
|
# check if message can be written to log
|
||||||
|
if self._level.value >= LoggingLevel.DEBUG.value:
|
||||||
|
self._append_log(output)
|
||||||
|
|
||||||
|
# check if message can be shown in console
|
||||||
|
if self._console.value >= LoggingLevel.DEBUG.value:
|
||||||
|
Console.write_line(output, 'green')
|
||||||
|
|
||||||
|
def info(self, name: str, message: str):
|
||||||
|
output = self._get_string(name, LoggingLevel.INFO, message)
|
||||||
|
|
||||||
|
# check if message can be written to log
|
||||||
|
if self._level.value >= LoggingLevel.INFO.value:
|
||||||
|
self._append_log(output)
|
||||||
|
|
||||||
|
# check if message can be shown in console
|
||||||
|
if self._console.value >= LoggingLevel.INFO.value:
|
||||||
|
Console.write_line(output, 'green')
|
||||||
|
|
||||||
|
def warn(self, name: str, message: str):
|
||||||
|
output = self._get_string(name, LoggingLevel.WARN, message)
|
||||||
|
|
||||||
|
# check if message can be written to log
|
||||||
|
if self._level.value >= LoggingLevel.WARN.value:
|
||||||
|
self._append_log(output)
|
||||||
|
|
||||||
|
# check if message can be shown in console
|
||||||
|
if self._console.value >= LoggingLevel.WARN.value:
|
||||||
|
Console.write_line(output, 'yellow')
|
||||||
|
|
||||||
|
def error(self, name: str, message: str, ex: Exception = None):
|
||||||
|
output = ''
|
||||||
|
if ex is not None:
|
||||||
|
tb = traceback.format_exc()
|
||||||
|
self.error(name, message)
|
||||||
|
output = self._get_string(name, LoggingLevel.ERROR, f'{ex} -> {tb}')
|
||||||
|
else:
|
||||||
|
output = self._get_string(name, LoggingLevel.ERROR, message)
|
||||||
|
|
||||||
|
# check if message can be written to log
|
||||||
|
if self._level.value >= LoggingLevel.ERROR.value:
|
||||||
|
self._append_log(output)
|
||||||
|
|
||||||
|
# check if message can be shown in console
|
||||||
|
if self._console.value >= LoggingLevel.ERROR.value:
|
||||||
|
Console.write_line(output, 'red')
|
||||||
|
|
||||||
|
def fatal(self, name: str, message: str, ex: Exception = None):
|
||||||
|
output = ''
|
||||||
|
if ex is not None:
|
||||||
|
tb = traceback.format_exc()
|
||||||
|
self.error(name, message)
|
||||||
|
output = self._get_string(name, LoggingLevel.ERROR, f'{ex} -> {tb}')
|
||||||
|
else:
|
||||||
|
output = self._get_string(name, LoggingLevel.ERROR, message)
|
||||||
|
|
||||||
|
# check if message can be written to log
|
||||||
|
if self._level.value >= LoggingLevel.FATAL.value:
|
||||||
|
self._append_log(output)
|
||||||
|
|
||||||
|
# check if message can be shown in console
|
||||||
|
if self._console.value >= LoggingLevel.FATAL.value:
|
||||||
|
Console.write_line(output, 'red')
|
||||||
|
|
||||||
|
exit()
|
27
src/sh_edraft/logging/model/__init__.py
Normal file
27
src/sh_edraft/logging/model/__init__.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
"""
|
||||||
|
sh_edraft.logging.model
|
||||||
|
~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
:copyright: (c) 2020 sh-edraft.de
|
||||||
|
:license: MIT, see LICENSE for more details.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
__title__ = 'sh_edraft.logging.model'
|
||||||
|
__author__ = 'Sven Heidemann'
|
||||||
|
__license__ = 'MIT'
|
||||||
|
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
||||||
|
__version__ = '2020.12.5'
|
||||||
|
|
||||||
|
from collections import namedtuple
|
||||||
|
|
||||||
|
# imports:
|
||||||
|
from .log_level import LoggingLevel
|
||||||
|
from .log_settings import LoggingSettings
|
||||||
|
|
||||||
|
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||||
|
version_info = VersionInfo(major=2020, minor=12, micro=5)
|
12
src/sh_edraft/logging/model/log_level.py
Normal file
12
src/sh_edraft/logging/model/log_level.py
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
from enum import Enum
|
||||||
|
|
||||||
|
|
||||||
|
class LoggingLevel(Enum):
|
||||||
|
|
||||||
|
OFF = 0 # Nothing
|
||||||
|
FATAL = 1 # Error that cause exit
|
||||||
|
ERROR = 2 # Non fatal error
|
||||||
|
WARN = 3 # Error that can later be fatal
|
||||||
|
INFO = 4 # Normal information's
|
||||||
|
DEBUG = 5 # Detailed app state
|
||||||
|
TRACE = 6 # Detailed app information's
|
60
src/sh_edraft/logging/model/log_settings.py
Normal file
60
src/sh_edraft/logging/model/log_settings.py
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
import traceback
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
from sh_edraft.configuration.model.configuration_model_base import ConfigurationModelBase
|
||||||
|
from sh_edraft.logging.model.log_settings_name import LogSettingsName
|
||||||
|
from sh_edraft.utils.console import Console
|
||||||
|
from sh_edraft.logging.model.log_level import LoggingLevel
|
||||||
|
|
||||||
|
|
||||||
|
class LoggingSettings(ConfigurationModelBase):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
ConfigurationModelBase.__init__(self)
|
||||||
|
|
||||||
|
self._path: Optional[str] = None
|
||||||
|
self._filename: Optional[str] = None
|
||||||
|
self._console: Optional[LoggingLevel] = None
|
||||||
|
self._level: Optional[LoggingLevel] = None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def path(self) -> str:
|
||||||
|
return self._path
|
||||||
|
|
||||||
|
@path.setter
|
||||||
|
def path(self, path: str) -> None:
|
||||||
|
self._path = path
|
||||||
|
|
||||||
|
@property
|
||||||
|
def filename(self) -> str:
|
||||||
|
return self._filename
|
||||||
|
|
||||||
|
@filename.setter
|
||||||
|
def filename(self, filename: str) -> None:
|
||||||
|
self._filename = filename
|
||||||
|
|
||||||
|
@property
|
||||||
|
def console(self) -> LoggingLevel:
|
||||||
|
return self._console
|
||||||
|
|
||||||
|
@console.setter
|
||||||
|
def console(self, console: LoggingLevel) -> None:
|
||||||
|
self._console = console
|
||||||
|
|
||||||
|
@property
|
||||||
|
def level(self) -> LoggingLevel:
|
||||||
|
return self._level
|
||||||
|
|
||||||
|
@level.setter
|
||||||
|
def level(self, level: LoggingLevel) -> None:
|
||||||
|
self._level = level
|
||||||
|
|
||||||
|
def from_dict(self, settings: dict):
|
||||||
|
try:
|
||||||
|
self._path = settings[LogSettingsName.path.value]
|
||||||
|
self._filename = settings[LogSettingsName.filename.value]
|
||||||
|
self._console = LoggingLevel[settings[LogSettingsName.console_level.value]]
|
||||||
|
self._level = LoggingLevel[settings[LogSettingsName.file_level.value]]
|
||||||
|
except Exception as e:
|
||||||
|
Console.write_line(f'[ ERROR ] [ {__name__} ]: Reading error in {LogSettingsName.log.value} settings', 'red')
|
||||||
|
Console.write_line(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}', 'red')
|
10
src/sh_edraft/logging/model/log_settings_name.py
Normal file
10
src/sh_edraft/logging/model/log_settings_name.py
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
from enum import Enum
|
||||||
|
|
||||||
|
|
||||||
|
class LogSettingsName(Enum):
|
||||||
|
|
||||||
|
log = 'Log'
|
||||||
|
path = 'Path'
|
||||||
|
filename = 'Filename'
|
||||||
|
console_level = 'ConsoleLogLevel'
|
||||||
|
file_level = 'FileLogLevel'
|
@ -15,11 +15,11 @@ __title__ = 'sh_edraft.mailing'
|
|||||||
__author__ = 'Sven Heidemann'
|
__author__ = 'Sven Heidemann'
|
||||||
__license__ = 'MIT'
|
__license__ = 'MIT'
|
||||||
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
||||||
__version__ = '2020.12.0.1'
|
__version__ = '2020.12.5'
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||||
version_info = VersionInfo(major=2020, minor=12, micro=0.1)
|
version_info = VersionInfo(major=2020, minor=12, micro=5)
|
||||||
|
@ -15,11 +15,11 @@ __title__ = 'sh_edraft.messenger'
|
|||||||
__author__ = 'Sven Heidemann'
|
__author__ = 'Sven Heidemann'
|
||||||
__license__ = 'MIT'
|
__license__ = 'MIT'
|
||||||
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
||||||
__version__ = '2020.12.0.1'
|
__version__ = '2020.12.5'
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
# imports:
|
# imports:
|
||||||
|
|
||||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||||
version_info = VersionInfo(major=2020, minor=12, micro=0.1)
|
version_info = VersionInfo(major=2020, minor=12, micro=5)
|
||||||
|
@ -15,12 +15,12 @@ __title__ = 'sh_edraft.publish'
|
|||||||
__author__ = 'Sven Heidemann'
|
__author__ = 'Sven Heidemann'
|
||||||
__license__ = 'MIT'
|
__license__ = 'MIT'
|
||||||
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
||||||
__version__ = '2020.12.0.1'
|
__version__ = '2020.12.5'
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
# imports:
|
# imports:
|
||||||
from sh_edraft.publish.publisher import Publisher
|
from .publisher import Publisher
|
||||||
|
|
||||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||||
version_info = VersionInfo(major=2020, minor=12, micro=0.1)
|
version_info = VersionInfo(major=2020, minor=12, micro=5)
|
||||||
|
@ -15,12 +15,12 @@ __title__ = 'sh_edraft.publish.base'
|
|||||||
__author__ = 'Sven Heidemann'
|
__author__ = 'Sven Heidemann'
|
||||||
__license__ = 'MIT'
|
__license__ = 'MIT'
|
||||||
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
||||||
__version__ = '2020.12.0.1'
|
__version__ = '2020.12.5'
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
# imports:
|
# imports:
|
||||||
from sh_edraft.publish.base.publisher_base import PublisherBase
|
from .publisher_base import PublisherBase
|
||||||
|
|
||||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||||
version_info = VersionInfo(major=2020, minor=12, micro=0.1)
|
version_info = VersionInfo(major=2020, minor=12, micro=5)
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
from abc import ABC, abstractmethod
|
from abc import abstractmethod
|
||||||
|
|
||||||
|
from sh_edraft.service.base import ServiceBase
|
||||||
|
|
||||||
|
|
||||||
class PublisherBase(ABC):
|
class PublisherBase(ServiceBase):
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def __init__(self): pass
|
def __init__(self):
|
||||||
|
ServiceBase.__init__(self)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
|
@ -15,13 +15,13 @@ __title__ = 'sh_edraft.publish.model'
|
|||||||
__author__ = 'Sven Heidemann'
|
__author__ = 'Sven Heidemann'
|
||||||
__license__ = 'MIT'
|
__license__ = 'MIT'
|
||||||
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
||||||
__version__ = '2020.12.0.1'
|
__version__ = '2020.12.5'
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
# imports:
|
# imports:
|
||||||
from sh_edraft.publish.model.template import Template
|
from .template import Template
|
||||||
from sh_edraft.publish.model.template_enum import TemplateEnum
|
from .template_enum import TemplateEnum
|
||||||
|
|
||||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||||
version_info = VersionInfo(major=2020, minor=12, micro=0.1)
|
version_info = VersionInfo(major=2020, minor=12, micro=5)
|
||||||
|
@ -3,18 +3,17 @@ import shutil
|
|||||||
from string import Template as stringTemplate
|
from string import Template as stringTemplate
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
|
from sh_edraft.logging.base.logger_base import LoggerBase
|
||||||
from sh_edraft.publish.base.publisher_base import PublisherBase
|
from sh_edraft.publish.base.publisher_base import PublisherBase
|
||||||
from sh_edraft.publish.model.template import Template
|
from sh_edraft.publish.model.template import Template
|
||||||
from sh_edraft.service.base import ServiceBase
|
|
||||||
|
|
||||||
|
|
||||||
class Publisher(ServiceBase, PublisherBase):
|
class Publisher(PublisherBase):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
ServiceBase.__init__(self)
|
super().__init__()
|
||||||
PublisherBase.__init__(self)
|
|
||||||
|
|
||||||
self._logger: Optional[None] = None
|
self._logger: Optional[LoggerBase] = None
|
||||||
self._source_path: Optional[str] = None
|
self._source_path: Optional[str] = None
|
||||||
self._dist_path: Optional[str] = None
|
self._dist_path: Optional[str] = None
|
||||||
self._settings: Optional[list[Template]] = None
|
self._settings: Optional[list[Template]] = None
|
||||||
@ -32,12 +31,13 @@ class Publisher(ServiceBase, PublisherBase):
|
|||||||
def dist_path(self):
|
def dist_path(self):
|
||||||
return self._dist_path
|
return self._dist_path
|
||||||
|
|
||||||
@staticmethod
|
def _get_template_output(self, t: Template, name: str, imports: str) -> str:
|
||||||
def _get_template_output(t: Template, name: str, imports: str) -> str:
|
self._logger.trace(__name__, f'Started {__name__}._get_template_output')
|
||||||
try:
|
try:
|
||||||
if t.file_content == '':
|
if t.file_content == '':
|
||||||
raise Exception(f'Template is empty: {t.template_path}')
|
raise Exception(f'Template is empty: {t.template_path}')
|
||||||
|
|
||||||
|
self._logger.trace(__name__, f'Stopped {__name__}._get_template_output')
|
||||||
return stringTemplate(t.file_content).substitute(
|
return stringTemplate(t.file_content).substitute(
|
||||||
Name=name,
|
Name=name,
|
||||||
Description=t.description,
|
Description=t.description,
|
||||||
@ -55,16 +55,20 @@ class Publisher(ServiceBase, PublisherBase):
|
|||||||
Imports=imports
|
Imports=imports
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(1, e)
|
self._logger.fatal(__name__, f'Cannot read Template: {t.template_path}', e)
|
||||||
# todo: better logging
|
self._logger.trace(__name__, f'Stopped {__name__}._get_template_output')
|
||||||
|
|
||||||
def _read_source_path(self):
|
def _read_source_path(self):
|
||||||
|
self._logger.trace(__name__, f'Started {__name__}._read_source_path')
|
||||||
for r, d, f in os.walk(self._source_path):
|
for r, d, f in os.walk(self._source_path):
|
||||||
for file in f:
|
for file in f:
|
||||||
if file.endswith('.py') or file in self._included_files:
|
if file.endswith('.py') or file in self._included_files:
|
||||||
self._included_files.append(os.path.join(r, file))
|
self._included_files.append(os.path.join(r, file))
|
||||||
|
|
||||||
|
self._logger.trace(__name__, f'Stopped {__name__}._read_source_path')
|
||||||
|
|
||||||
def _read_templates(self):
|
def _read_templates(self):
|
||||||
|
self._logger.trace(__name__, f'Started {__name__}._read_templates')
|
||||||
for t in self._settings:
|
for t in self._settings:
|
||||||
output_template: str = ''
|
output_template: str = ''
|
||||||
if not os.path.isfile(t.template_path):
|
if not os.path.isfile(t.template_path):
|
||||||
@ -76,22 +80,26 @@ class Publisher(ServiceBase, PublisherBase):
|
|||||||
if t.file_content == '':
|
if t.file_content == '':
|
||||||
raise Exception(f'Template is empty: {t.template_path}')
|
raise Exception(f'Template is empty: {t.template_path}')
|
||||||
|
|
||||||
|
self._logger.trace(__name__, f'Stopped {__name__}._read_templates')
|
||||||
|
|
||||||
def _create_dist_path(self):
|
def _create_dist_path(self):
|
||||||
|
self._logger.trace(__name__, f'Started {__name__}._create_dist_path')
|
||||||
if os.path.isdir(self._dist_path):
|
if os.path.isdir(self._dist_path):
|
||||||
try:
|
try:
|
||||||
shutil.rmtree(self._dist_path)
|
shutil.rmtree(self._dist_path)
|
||||||
print(f'Deleted {self._dist_path}')
|
self._logger.info(__name__, f'Deleted {self._dist_path}')
|
||||||
# todo: better logging
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
self._logger.fatal(__name__, f'Cannot delete old dist directory', e)
|
||||||
# todo: log error
|
|
||||||
|
|
||||||
if not os.path.isdir(self._dist_path):
|
if not os.path.isdir(self._dist_path):
|
||||||
try:
|
try:
|
||||||
os.makedirs(self._dist_path)
|
os.makedirs(self._dist_path)
|
||||||
|
self._logger.debug(__name__, f'Created directories: {self._dist_path}')
|
||||||
|
self._logger.info(__name__, f'Created dist directory')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
self._logger.fatal(__name__, f'Cannot create dist directory', e)
|
||||||
# todo: log error
|
|
||||||
|
self._logger.trace(__name__, f'Stopped {__name__}._create_dist_path')
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _get_template_name_from_dirs(file: str) -> str:
|
def _get_template_name_from_dirs(file: str) -> str:
|
||||||
@ -106,6 +114,7 @@ class Publisher(ServiceBase, PublisherBase):
|
|||||||
return '.'.join(dirs)
|
return '.'.join(dirs)
|
||||||
|
|
||||||
def _write_templates(self):
|
def _write_templates(self):
|
||||||
|
self._logger.trace(__name__, f'Started {__name__}._write_templates')
|
||||||
for template in self._settings:
|
for template in self._settings:
|
||||||
for file in self._included_files:
|
for file in self._included_files:
|
||||||
if os.path.basename(file) == '__init__.py' and file not in self._excluded_files:
|
if os.path.basename(file) == '__init__.py' and file not in self._excluded_files:
|
||||||
@ -135,7 +144,7 @@ class Publisher(ServiceBase, PublisherBase):
|
|||||||
with open(file, 'w+') as py_file:
|
with open(file, 'w+') as py_file:
|
||||||
py_file.write(self._get_template_output(template, template_name, '# imports:'))
|
py_file.write(self._get_template_output(template, template_name, '# imports:'))
|
||||||
py_file.close()
|
py_file.close()
|
||||||
print(f'Written to {file}')
|
self._logger.debug(__name__, f'Written to {file}')
|
||||||
else:
|
else:
|
||||||
is_started = False
|
is_started = False
|
||||||
for line in module_file_lines:
|
for line in module_file_lines:
|
||||||
@ -151,73 +160,86 @@ class Publisher(ServiceBase, PublisherBase):
|
|||||||
with open(file, 'w+') as py_file:
|
with open(file, 'w+') as py_file:
|
||||||
py_file.write(self._get_template_output(template, template_name, imports))
|
py_file.write(self._get_template_output(template, template_name, imports))
|
||||||
py_file.close()
|
py_file.close()
|
||||||
print(f'Written to {file}')
|
self._logger.debug(__name__, f'Written to {file}')
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
self._logger.error(__name__, f'Cannot write to file: {file}', e)
|
||||||
# todo: better logging
|
|
||||||
|
self._logger.info(__name__, f'Written to all included modules')
|
||||||
|
self._logger.trace(__name__, f'Stopped {__name__}._write_templates')
|
||||||
|
|
||||||
def _copy_all_included_files(self):
|
def _copy_all_included_files(self):
|
||||||
|
self._logger.trace(__name__, f'Started {__name__}._copy_all_included_files')
|
||||||
dist_path = self._dist_path
|
dist_path = self._dist_path
|
||||||
if self._dist_path.endswith('/'):
|
if self._dist_path.endswith('/'):
|
||||||
dist_path = dist_path[:len(dist_path) - 1]
|
dist_path = dist_path[:len(dist_path) - 1]
|
||||||
|
|
||||||
for file in self._included_files:
|
for file in self._included_files:
|
||||||
is_file_excluded = False
|
is_file_excluded = False
|
||||||
if file in self._excluded_files:
|
if file in self._excluded_files:
|
||||||
is_file_excluded = True
|
is_file_excluded = True
|
||||||
else:
|
else:
|
||||||
for excluded in self._excluded_files:
|
for excluded in self._excluded_files:
|
||||||
if file.__contains__(excluded):
|
if file.__contains__(excluded):
|
||||||
is_file_excluded = True
|
is_file_excluded = True
|
||||||
|
|
||||||
if not is_file_excluded:
|
if not is_file_excluded:
|
||||||
output_file = ''
|
output_file = ''
|
||||||
if file.startswith('..'):
|
|
||||||
output_file = file.replace('..', '')
|
|
||||||
|
|
||||||
elif file.startswith('.'):
|
if file.startswith('..'):
|
||||||
output_file = file.replace('.', '', 1)
|
output_file = file.replace('..', '')
|
||||||
|
elif file.startswith('.'):
|
||||||
|
output_file = file.replace('.', '', 1)
|
||||||
|
|
||||||
output_file = f'{dist_path}{output_file}'
|
output_file = f'{dist_path}{output_file}'
|
||||||
output_path = os.path.dirname(output_file)
|
output_path = os.path.dirname(output_file)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if not os.path.isdir(output_path):
|
if not os.path.isdir(output_path):
|
||||||
os.makedirs(output_path)
|
os.makedirs(output_path)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
self._logger.error(__name__, f'Cannot create directories: {output_path}', e)
|
||||||
# todo: better logging
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
shutil.copy(file, output_file)
|
shutil.copy(file, output_file)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
self._logger.error(__name__, f'Cannot copy file: {file} to {output_path}', e)
|
||||||
# todo: better logging
|
|
||||||
|
|
||||||
print(f'Copied {file} to {output_path}')
|
self._logger.debug(__name__, f'Copied {file} to {output_path}')
|
||||||
# todo: better logging
|
|
||||||
|
self._logger.info(__name__, f'Copied all included files')
|
||||||
|
self._logger.trace(__name__, f'Stopped {__name__}._copy_all_included_files')
|
||||||
|
|
||||||
def include(self, path: str):
|
def include(self, path: str):
|
||||||
|
self._logger.trace(__name__, f'Started {__name__}.include')
|
||||||
self._included_files.append(path)
|
self._included_files.append(path)
|
||||||
|
self._logger.trace(__name__, f'Stopped {__name__}.include')
|
||||||
|
|
||||||
def exclude(self, path: str):
|
def exclude(self, path: str):
|
||||||
|
self._logger.trace(__name__, f'Started {__name__}.exclude')
|
||||||
self._excluded_files.append(path)
|
self._excluded_files.append(path)
|
||||||
|
self._logger.trace(__name__, f'Stopped {__name__}.exclude')
|
||||||
|
|
||||||
def init(self, args: tuple):
|
def init(self, args: tuple):
|
||||||
self._logger = args[0]
|
self._logger: LoggerBase = args[0]
|
||||||
self._source_path = args[1]
|
self._source_path: str = args[1]
|
||||||
self._dist_path = args[2]
|
self._dist_path: str = args[2]
|
||||||
self._settings = args[3]
|
self._settings: list[Template] = args[3]
|
||||||
|
|
||||||
|
self._logger.header(f'{__name__}:')
|
||||||
|
|
||||||
def create(self):
|
def create(self):
|
||||||
|
self._logger.trace(__name__, f'Started {__name__}.create')
|
||||||
if not self._dist_path.endswith('/'):
|
if not self._dist_path.endswith('/'):
|
||||||
self._dist_path += '/'
|
self._dist_path += '/'
|
||||||
|
|
||||||
self._read_source_path()
|
self._read_source_path()
|
||||||
self._read_templates()
|
self._read_templates()
|
||||||
self._create_dist_path()
|
self._create_dist_path()
|
||||||
|
self._logger.trace(__name__, f'Stopped {__name__}.create')
|
||||||
|
|
||||||
def publish(self):
|
def publish(self):
|
||||||
|
self._logger.trace(__name__, f'Started {__name__}.publish')
|
||||||
self._write_templates()
|
self._write_templates()
|
||||||
self._copy_all_included_files()
|
self._copy_all_included_files()
|
||||||
|
self._logger.trace(__name__, f'Stopped {__name__}.publish')
|
||||||
|
@ -15,12 +15,12 @@ __title__ = 'sh_edraft.service'
|
|||||||
__author__ = 'Sven Heidemann'
|
__author__ = 'Sven Heidemann'
|
||||||
__license__ = 'MIT'
|
__license__ = 'MIT'
|
||||||
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
||||||
__version__ = '2020.12.0.1'
|
__version__ = '2020.12.5'
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
# imports:
|
# imports:
|
||||||
from sh_edraft.service.service_provider import ServiceProvider
|
from .service_provider import ServiceProvider
|
||||||
|
|
||||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||||
version_info = VersionInfo(major=2020, minor=12, micro=0.1)
|
version_info = VersionInfo(major=2020, minor=12, micro=5)
|
||||||
|
@ -15,13 +15,13 @@ __title__ = 'sh_edraft.service.base'
|
|||||||
__author__ = 'Sven Heidemann'
|
__author__ = 'Sven Heidemann'
|
||||||
__license__ = 'MIT'
|
__license__ = 'MIT'
|
||||||
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
||||||
__version__ = '2020.12.0.1'
|
__version__ = '2020.12.5'
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
# imports:
|
# imports:
|
||||||
from sh_edraft.service.base.service_base import ServiceBase
|
from .service_base import ServiceBase
|
||||||
from sh_edraft.service.base.provider_base import ProviderBase
|
from .service_provider_base import ServiceProviderBase
|
||||||
|
|
||||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||||
version_info = VersionInfo(major=2020, minor=12, micro=0.1)
|
version_info = VersionInfo(major=2020, minor=12, micro=5)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
from abc import ABC, abstractmethod
|
from abc import abstractmethod
|
||||||
from collections import Callable
|
from collections import Callable
|
||||||
from typing import Type
|
from typing import Type
|
||||||
|
|
||||||
@ -6,10 +6,11 @@ from sh_edraft.service.base.service_base import ServiceBase
|
|||||||
from sh_edraft.service.model.provide_state import ProvideState
|
from sh_edraft.service.model.provide_state import ProvideState
|
||||||
|
|
||||||
|
|
||||||
class ProviderBase(ABC):
|
class ServiceProviderBase(ServiceBase):
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
ServiceBase.__init__(self)
|
||||||
self._transient_services: list[ProvideState] = []
|
self._transient_services: list[ProvideState] = []
|
||||||
self._scoped_services: list[ProvideState] = []
|
self._scoped_services: list[ProvideState] = []
|
||||||
self._singleton_services: list[ServiceBase] = []
|
self._singleton_services: list[ServiceBase] = []
|
||||||
@ -24,7 +25,7 @@ class ProviderBase(ABC):
|
|||||||
def add_singleton(self, service: Type[ServiceBase], *args): pass
|
def add_singleton(self, service: Type[ServiceBase], *args): pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def get_service(self, instance_type: type) -> Callable[ServiceBase]: pass
|
def get_service(self, instance_type: Type[ServiceBase]) -> Callable[ServiceBase]: pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def remove_service(self, instance_type: type): pass
|
def remove_service(self, instance_type: type): pass
|
@ -15,11 +15,12 @@ __title__ = 'sh_edraft.service.model'
|
|||||||
__author__ = 'Sven Heidemann'
|
__author__ = 'Sven Heidemann'
|
||||||
__license__ = 'MIT'
|
__license__ = 'MIT'
|
||||||
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
||||||
__version__ = '2020.12.0.1'
|
__version__ = '2020.12.5'
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
# imports:
|
# imports:
|
||||||
|
from .provide_state import ProvideState
|
||||||
|
|
||||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||||
version_info = VersionInfo(major=2020, minor=12, micro=0.1)
|
version_info = VersionInfo(major=2020, minor=12, micro=5)
|
||||||
|
@ -3,18 +3,19 @@ from typing import Type
|
|||||||
|
|
||||||
from termcolor import colored
|
from termcolor import colored
|
||||||
|
|
||||||
from sh_edraft.service.base.provider_base import ProviderBase
|
from sh_edraft.service.base.service_provider_base import ServiceProviderBase
|
||||||
from sh_edraft.service.base.service_base import ServiceBase
|
from sh_edraft.service.base.service_base import ServiceBase
|
||||||
from sh_edraft.service.model.provide_state import ProvideState
|
from sh_edraft.service.model.provide_state import ProvideState
|
||||||
|
|
||||||
|
|
||||||
class ServiceProvider(ProviderBase):
|
class ServiceProvider(ServiceProviderBase):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
ProviderBase.__init__(self)
|
super().__init__()
|
||||||
|
|
||||||
def create(self):
|
def init(self, args: tuple): pass
|
||||||
pass
|
|
||||||
|
def create(self): pass
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _create_instance(service: type[ServiceBase], args: tuple) -> ServiceBase:
|
def _create_instance(service: type[ServiceBase], args: tuple) -> ServiceBase:
|
||||||
@ -38,31 +39,31 @@ class ServiceProvider(ProviderBase):
|
|||||||
|
|
||||||
self._singleton_services.append(self._create_instance(service, args))
|
self._singleton_services.append(self._create_instance(service, args))
|
||||||
|
|
||||||
def get_service(self, instance_type: type) -> Callable[ServiceBase]:
|
def get_service(self, instance_type: Type[ServiceBase]) -> Callable[ServiceBase]:
|
||||||
for state in self._transient_services:
|
for state in self._transient_services:
|
||||||
if state.service == instance_type:
|
if isinstance(state.service, type(instance_type)):
|
||||||
return self._create_instance(state.service, state.args)
|
return self._create_instance(state.service, state.args)
|
||||||
|
|
||||||
for state in self._scoped_services:
|
for state in self._scoped_services:
|
||||||
if type(state.service) == instance_type:
|
if isinstance(state.service, type(instance_type)):
|
||||||
return self._create_instance(state.service, state.args)
|
return self._create_instance(state.service, state.args)
|
||||||
|
|
||||||
for service in self._singleton_services:
|
for service in self._singleton_services:
|
||||||
if type(service) == instance_type:
|
if isinstance(service, instance_type):
|
||||||
return service
|
return service
|
||||||
|
|
||||||
def remove_service(self, instance_type: type):
|
def remove_service(self, instance_type: type):
|
||||||
for state in self._transient_services:
|
for state in self._transient_services:
|
||||||
if state.service == instance_type:
|
if isinstance(state.service, type(instance_type)):
|
||||||
self._transient_services.remove(state)
|
self._transient_services.remove(state)
|
||||||
return
|
return
|
||||||
|
|
||||||
for state in self._scoped_services:
|
for state in self._scoped_services:
|
||||||
if type(state.service) == instance_type:
|
if isinstance(state.service, type(instance_type)):
|
||||||
self._scoped_services.remove(state)
|
self._scoped_services.remove(state)
|
||||||
return
|
return
|
||||||
|
|
||||||
for service in self._singleton_services:
|
for service in self._singleton_services:
|
||||||
if type(service) == instance_type:
|
if isinstance(service, instance_type):
|
||||||
self._singleton_services.remove(service)
|
self._singleton_services.remove(service)
|
||||||
return
|
return
|
||||||
|
@ -15,11 +15,11 @@ __title__ = 'sh_edraft.source_code'
|
|||||||
__author__ = 'Sven Heidemann'
|
__author__ = 'Sven Heidemann'
|
||||||
__license__ = 'MIT'
|
__license__ = 'MIT'
|
||||||
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
||||||
__version__ = '2020.12.0.1'
|
__version__ = '2020.12.5'
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||||
version_info = VersionInfo(major=2020, minor=12, micro=0.1)
|
version_info = VersionInfo(major=2020, minor=12, micro=5)
|
||||||
|
@ -15,13 +15,13 @@ __title__ = 'sh_edraft.source_code.model'
|
|||||||
__author__ = 'Sven Heidemann'
|
__author__ = 'Sven Heidemann'
|
||||||
__license__ = 'MIT'
|
__license__ = 'MIT'
|
||||||
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
||||||
__version__ = '2020.12.0.1'
|
__version__ = '2020.12.5'
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
# imports:
|
# imports:
|
||||||
from sh_edraft.source_code.model.version import Version
|
from .version import Version
|
||||||
from sh_edraft.source_code.model.version_enum import VersionEnum
|
from .version_enum import VersionEnum
|
||||||
|
|
||||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||||
version_info = VersionInfo(major=2020, minor=12, micro=0.1)
|
version_info = VersionInfo(major=2020, minor=12, micro=5)
|
||||||
|
@ -14,7 +14,7 @@ class Version(ConfigurationModelBase):
|
|||||||
):
|
):
|
||||||
self._major: Optional[int] = major
|
self._major: Optional[int] = major
|
||||||
self._minor: Optional[int] = minor
|
self._minor: Optional[int] = minor
|
||||||
self._micro: Optional[float] = micro
|
self._micro: Optional[int] = micro
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def major(self) -> int:
|
def major(self) -> int:
|
||||||
@ -34,7 +34,7 @@ class Version(ConfigurationModelBase):
|
|||||||
def from_dict(self, settings: dict):
|
def from_dict(self, settings: dict):
|
||||||
self._major = int(settings[VersionEnum.Major.value])
|
self._major = int(settings[VersionEnum.Major.value])
|
||||||
self._minor = int(settings[VersionEnum.Minor.value])
|
self._minor = int(settings[VersionEnum.Minor.value])
|
||||||
self._micro = float(settings[VersionEnum.Micro.value])
|
self._micro = int(settings[VersionEnum.Micro.value])
|
||||||
|
|
||||||
def to_dict(self) -> dict:
|
def to_dict(self) -> dict:
|
||||||
return {
|
return {
|
||||||
|
25
src/sh_edraft/time/__init__.py
Normal file
25
src/sh_edraft/time/__init__.py
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
"""
|
||||||
|
sh_edraft.time
|
||||||
|
~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
:copyright: (c) 2020 sh-edraft.de
|
||||||
|
:license: MIT, see LICENSE for more details.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
__title__ = 'sh_edraft.time'
|
||||||
|
__author__ = 'Sven Heidemann'
|
||||||
|
__license__ = 'MIT'
|
||||||
|
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
||||||
|
__version__ = '2020.12.5'
|
||||||
|
|
||||||
|
from collections import namedtuple
|
||||||
|
|
||||||
|
# imports:
|
||||||
|
|
||||||
|
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||||
|
version_info = VersionInfo(major=2020, minor=12, micro=5)
|
27
src/sh_edraft/time/model/__init__.py
Normal file
27
src/sh_edraft/time/model/__init__.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
"""
|
||||||
|
sh_edraft.time.model
|
||||||
|
~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
:copyright: (c) 2020 sh-edraft.de
|
||||||
|
:license: MIT, see LICENSE for more details.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
__title__ = 'sh_edraft.time.model'
|
||||||
|
__author__ = 'Sven Heidemann'
|
||||||
|
__license__ = 'MIT'
|
||||||
|
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
||||||
|
__version__ = '2020.12.5'
|
||||||
|
|
||||||
|
from collections import namedtuple
|
||||||
|
|
||||||
|
# imports:
|
||||||
|
from .time_format_settings import TimeFormatSettings
|
||||||
|
from .time_format_settings_names import TimeFormatSettingsNames
|
||||||
|
|
||||||
|
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||||
|
version_info = VersionInfo(major=2020, minor=12, micro=5)
|
59
src/sh_edraft/time/model/time_format_settings.py
Normal file
59
src/sh_edraft/time/model/time_format_settings.py
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
import traceback
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
from sh_edraft.configuration.model import ConfigurationModelBase
|
||||||
|
from sh_edraft.time.model.time_format_settings_names import TimeFormatSettingsNames
|
||||||
|
from sh_edraft.utils.console import Console
|
||||||
|
|
||||||
|
|
||||||
|
class TimeFormatSettings(ConfigurationModelBase):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self._date_format: Optional[str] = None
|
||||||
|
self._time_format: Optional[str] = None
|
||||||
|
self._date_time_format: Optional[str] = None
|
||||||
|
self._date_time_log_format: Optional[str] = None
|
||||||
|
self._os_name: Optional[str] = None
|
||||||
|
self._hostname: Optional[str] = None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def date_format(self) -> str:
|
||||||
|
return self._date_format
|
||||||
|
|
||||||
|
@date_format.setter
|
||||||
|
def date_format(self, date_format: str) -> None:
|
||||||
|
self._date_format = date_format
|
||||||
|
|
||||||
|
@property
|
||||||
|
def time_format(self) -> str:
|
||||||
|
return self._time_format
|
||||||
|
|
||||||
|
@time_format.setter
|
||||||
|
def time_format(self, time_format: str):
|
||||||
|
self._time_format = time_format
|
||||||
|
|
||||||
|
@property
|
||||||
|
def date_time_format(self) -> str:
|
||||||
|
return self._date_time_format
|
||||||
|
|
||||||
|
@date_time_format.setter
|
||||||
|
def date_time_format(self, date_time_format: str) -> None:
|
||||||
|
self._date_time_format = date_time_format
|
||||||
|
|
||||||
|
@property
|
||||||
|
def date_time_log_format(self):
|
||||||
|
return self._date_time_log_format
|
||||||
|
|
||||||
|
@date_time_log_format.setter
|
||||||
|
def date_time_log_format(self, date_time_now_format: str) -> None:
|
||||||
|
self._date_time_log_format = date_time_now_format
|
||||||
|
|
||||||
|
def from_dict(self, settings: dict):
|
||||||
|
try:
|
||||||
|
self._date_format = settings[TimeFormatSettingsNames.date_format.value]
|
||||||
|
self._time_format = settings[TimeFormatSettingsNames.time_format.value]
|
||||||
|
self._date_time_format = settings[TimeFormatSettingsNames.date_time_format.value]
|
||||||
|
self._date_time_log_format = settings[TimeFormatSettingsNames.date_time_log_format.value]
|
||||||
|
except Exception as e:
|
||||||
|
Console.write_line(f'[ ERROR ] [ {__name__} ]: Reading error in {TimeFormatSettingsNames.formats.value} settings')
|
||||||
|
Console.write_line(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}', 'red')
|
10
src/sh_edraft/time/model/time_format_settings_names.py
Normal file
10
src/sh_edraft/time/model/time_format_settings_names.py
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
from enum import Enum
|
||||||
|
|
||||||
|
|
||||||
|
class TimeFormatSettingsNames(Enum):
|
||||||
|
|
||||||
|
formats = 'TimeFormats'
|
||||||
|
date_format = 'DateFormat'
|
||||||
|
time_format = 'TimeFormat'
|
||||||
|
date_time_format = 'DateTimeFormat'
|
||||||
|
date_time_log_format = 'DateTimeLogFormat'
|
26
src/sh_edraft/utils/__init__.py
Normal file
26
src/sh_edraft/utils/__init__.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
"""
|
||||||
|
sh_edraft.utils
|
||||||
|
~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
:copyright: (c) 2020 sh-edraft.de
|
||||||
|
:license: MIT, see LICENSE for more details.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
__title__ = 'sh_edraft.utils'
|
||||||
|
__author__ = 'Sven Heidemann'
|
||||||
|
__license__ = 'MIT'
|
||||||
|
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
||||||
|
__version__ = '2020.12.5'
|
||||||
|
|
||||||
|
from collections import namedtuple
|
||||||
|
|
||||||
|
# imports:
|
||||||
|
from .console import Console
|
||||||
|
|
||||||
|
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||||
|
version_info = VersionInfo(major=2020, minor=12, micro=5)
|
11
src/sh_edraft/utils/console.py
Normal file
11
src/sh_edraft/utils/console.py
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
from termcolor import colored
|
||||||
|
|
||||||
|
|
||||||
|
class Console:
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def write_line(string: str, color: str = None):
|
||||||
|
if color is not None:
|
||||||
|
print(colored(string, color))
|
||||||
|
else:
|
||||||
|
print(string)
|
@ -15,11 +15,11 @@ __title__ = 'tests'
|
|||||||
__author__ = 'Sven Heidemann'
|
__author__ = 'Sven Heidemann'
|
||||||
__license__ = 'MIT'
|
__license__ = 'MIT'
|
||||||
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
||||||
__version__ = '2020.12.0.1'
|
__version__ = '2020.12.5'
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
# imports:
|
# imports:
|
||||||
|
|
||||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||||
version_info = VersionInfo(major=2020, minor=12, micro=0.1)
|
version_info = VersionInfo(major=2020, minor=12, micro=5)
|
||||||
|
50
src/tests/logger.py
Normal file
50
src/tests/logger.py
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
import os
|
||||||
|
from string import Template
|
||||||
|
|
||||||
|
from sh_edraft.configuration import ApplicationHost
|
||||||
|
from sh_edraft.logging.base.logger_base import LoggerBase
|
||||||
|
from sh_edraft.logging.logger import Logger
|
||||||
|
from sh_edraft.logging.model.log_settings import LoggingSettings
|
||||||
|
from sh_edraft.time.model.time_format_settings import TimeFormatSettings
|
||||||
|
|
||||||
|
|
||||||
|
class LoggerTest:
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def start(app_host: ApplicationHost):
|
||||||
|
services = app_host.services
|
||||||
|
|
||||||
|
log_settings = LoggingSettings()
|
||||||
|
log_settings.from_dict({
|
||||||
|
"Path": "logs/",
|
||||||
|
"Filename": "log_$start_time.log",
|
||||||
|
"ConsoleLogLevel": "TRACE",
|
||||||
|
"FileLogLevel": "TRACE"
|
||||||
|
})
|
||||||
|
|
||||||
|
time_format_settings = TimeFormatSettings()
|
||||||
|
time_format_settings.from_dict({
|
||||||
|
"DateFormat": "%Y-%m-%d",
|
||||||
|
"TimeFormat": "%H:%M:%S",
|
||||||
|
"DateTimeFormat": "%Y-%m-%d %H:%M:%S.%f",
|
||||||
|
"DateTimeLogFormat": "%Y-%m-%d_%H-%M-%S"
|
||||||
|
})
|
||||||
|
|
||||||
|
services.add_singleton(Logger, log_settings, time_format_settings, app_host)
|
||||||
|
logger: Logger = services.get_service(LoggerBase)
|
||||||
|
|
||||||
|
if logger is None:
|
||||||
|
raise Exception(f'{__name__}: Service is None')
|
||||||
|
|
||||||
|
logger.create()
|
||||||
|
logger.info(__name__, 'test')
|
||||||
|
|
||||||
|
if not os.path.isdir(log_settings.path):
|
||||||
|
raise Exception(f'{__name__}: Log path was not created')
|
||||||
|
|
||||||
|
log_file = Template(log_settings.filename).substitute(
|
||||||
|
date_time_now=app_host.date_time_now.strftime(time_format_settings.date_time_format),
|
||||||
|
start_time=app_host.start_time.strftime(time_format_settings.date_time_log_format)
|
||||||
|
)
|
||||||
|
if not os.path.isfile(log_settings.path + log_file):
|
||||||
|
raise Exception(f'{__name__}: Log file was not created')
|
@ -1,6 +1,8 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
from sh_edraft.service import ServiceProvider
|
from sh_edraft.logging.base.logger_base import LoggerBase
|
||||||
|
from sh_edraft.publish.base import PublisherBase
|
||||||
|
from sh_edraft.service.base import ServiceProviderBase
|
||||||
from sh_edraft.source_code.model import Version
|
from sh_edraft.source_code.model import Version
|
||||||
from sh_edraft.publish import Publisher
|
from sh_edraft.publish import Publisher
|
||||||
from sh_edraft.publish.model import Template
|
from sh_edraft.publish.model import Template
|
||||||
@ -9,7 +11,8 @@ from sh_edraft.publish.model import Template
|
|||||||
class PublisherTest:
|
class PublisherTest:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def start(services: ServiceProvider):
|
def start(services: ServiceProviderBase):
|
||||||
|
version = Version(2020, 12, 5).to_dict()
|
||||||
templates = [
|
templates = [
|
||||||
Template(
|
Template(
|
||||||
'../../publish_templates/*_template.txt',
|
'../../publish_templates/*_template.txt',
|
||||||
@ -22,7 +25,7 @@ class PublisherTest:
|
|||||||
', see LICENSE for more details.',
|
', see LICENSE for more details.',
|
||||||
'',
|
'',
|
||||||
'Sven Heidemann',
|
'Sven Heidemann',
|
||||||
Version(2020, 12, 0.1).to_dict()
|
version
|
||||||
),
|
),
|
||||||
Template(
|
Template(
|
||||||
'../../publish_templates/*_template.txt',
|
'../../publish_templates/*_template.txt',
|
||||||
@ -35,15 +38,15 @@ class PublisherTest:
|
|||||||
', see LICENSE for more details.',
|
', see LICENSE for more details.',
|
||||||
'',
|
'',
|
||||||
'Sven Heidemann',
|
'Sven Heidemann',
|
||||||
Version(2020, 12, 0.1).to_dict()
|
version
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
||||||
source = '../'
|
source = '../'
|
||||||
dist = '../../dist'
|
dist = '../../dist'
|
||||||
|
|
||||||
services.add_singleton(Publisher, None, source, dist, templates)
|
services.add_transient(Publisher, services.get_service(LoggerBase), source, dist, templates)
|
||||||
publisher: Publisher = services.get_service(Publisher)
|
publisher: Publisher = services.get_service(PublisherBase)
|
||||||
|
|
||||||
publisher.exclude('../tests/')
|
publisher.exclude('../tests/')
|
||||||
publisher.include('../../LICENSE')
|
publisher.include('../../LICENSE')
|
||||||
|
@ -1,23 +1,20 @@
|
|||||||
|
from sh_edraft.logging.base.logger_base import LoggerBase
|
||||||
from sh_edraft.publish import Publisher
|
from sh_edraft.publish import Publisher
|
||||||
from sh_edraft.service import ServiceProvider
|
from sh_edraft.publish.base import PublisherBase
|
||||||
|
from sh_edraft.service.base import ServiceProviderBase
|
||||||
|
|
||||||
|
|
||||||
class ServiceProviderTest:
|
class ServiceProviderTest:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def start() -> ServiceProvider:
|
def start(services: ServiceProviderBase):
|
||||||
provider = ServiceProvider()
|
services.add_transient(Publisher, services.get_service(LoggerBase), '../', '../../dist', [])
|
||||||
provider.create()
|
|
||||||
|
|
||||||
provider.add_transient(Publisher, None, '../', '../../dist', [])
|
publisher: Publisher = services.get_service(PublisherBase)
|
||||||
|
|
||||||
publisher: Publisher = provider.get_service(Publisher)
|
if publisher is None or publisher.source_path != '../' or publisher.dist_path != '../../dist':
|
||||||
|
|
||||||
if publisher.source_path != '../' or publisher.dist_path != '../../dist':
|
|
||||||
raise Exception(f'{__name__}: Invalid value in {Publisher.__name__}')
|
raise Exception(f'{__name__}: Invalid value in {Publisher.__name__}')
|
||||||
|
|
||||||
provider.remove_service(Publisher)
|
services.remove_service(PublisherBase)
|
||||||
if provider.get_service(Publisher) is not None:
|
if services.get_service(PublisherBase) is not None:
|
||||||
raise Exception(f'{__name__}: Service {Publisher.__name__} was not removed')
|
raise Exception(f'{__name__}: Service {Publisher.__name__} was not removed')
|
||||||
|
|
||||||
return provider
|
|
||||||
|
@ -1,28 +1,24 @@
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from typing import Optional
|
import traceback
|
||||||
|
|
||||||
from termcolor import colored
|
from termcolor import colored
|
||||||
|
|
||||||
from sh_edraft.service import ServiceProvider
|
from sh_edraft.configuration import ApplicationHost
|
||||||
|
from tests.logger import LoggerTest
|
||||||
from tests.publisher import PublisherTest
|
from tests.publisher import PublisherTest
|
||||||
from tests.service_provider import ServiceProviderTest
|
from tests.service_provider import ServiceProviderTest
|
||||||
|
|
||||||
|
|
||||||
class Test:
|
class Tester:
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._services: Optional[ServiceProvider] = None
|
self._app_host = ApplicationHost()
|
||||||
|
|
||||||
self._tests = [
|
|
||||||
ServiceProviderTest,
|
|
||||||
PublisherTest
|
|
||||||
]
|
|
||||||
|
|
||||||
self._error: bool = False
|
self._error: bool = False
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def block_print():
|
def disable_print():
|
||||||
sys.stdout = open(os.devnull, 'w')
|
sys.stdout = open(os.devnull, 'w')
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -32,36 +28,52 @@ class Test:
|
|||||||
def success(self, message: str):
|
def success(self, message: str):
|
||||||
self.enable_print()
|
self.enable_print()
|
||||||
print(colored(message, 'green'))
|
print(colored(message, 'green'))
|
||||||
self.block_print()
|
self.disable_print()
|
||||||
|
|
||||||
def failed(self, message: str):
|
def failed(self, message: str):
|
||||||
self.enable_print()
|
self.enable_print()
|
||||||
print(colored(message, 'red'))
|
print(colored(message, 'red'))
|
||||||
self.block_print()
|
self.disable_print()
|
||||||
|
|
||||||
|
def exception(self):
|
||||||
|
self.enable_print()
|
||||||
|
print(colored(traceback.format_exc(), 'red'))
|
||||||
|
self.disable_print()
|
||||||
|
|
||||||
def create(self): pass
|
def create(self): pass
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
self.block_print()
|
if not self._error:
|
||||||
|
try:
|
||||||
|
LoggerTest.start(self._app_host)
|
||||||
|
self.success(f'{LoggerTest.__name__} test succeeded.')
|
||||||
|
except Exception as e:
|
||||||
|
self._error = True
|
||||||
|
self.failed(f'{LoggerTest.__name__} test failed!\n{e}')
|
||||||
|
self.exception()
|
||||||
|
|
||||||
if not self._error:
|
if not self._error:
|
||||||
try:
|
try:
|
||||||
self._services = ServiceProviderTest.start()
|
ServiceProviderTest.start(self._app_host.services)
|
||||||
self.success(f'{ServiceProviderTest.__name__} test succeeded.')
|
self.success(f'{ServiceProviderTest.__name__} test succeeded.')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._error = True
|
self._error = True
|
||||||
self.failed(f'{ServiceProviderTest.__name__} test failed!\n{e}')
|
self.failed(f'{ServiceProviderTest.__name__} test failed!\n{e}')
|
||||||
|
self.exception()
|
||||||
|
|
||||||
if not self._error:
|
if not self._error:
|
||||||
try:
|
try:
|
||||||
PublisherTest.start(self._services)
|
PublisherTest.start(self._app_host.services)
|
||||||
self.success(f'{PublisherTest.__name__} test succeeded.')
|
self.success(f'{PublisherTest.__name__} test succeeded.')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._error = True
|
self._error = True
|
||||||
self.failed(f'{PublisherTest.__name__} test failed!\n{e}')
|
self.failed(f'{PublisherTest.__name__} test failed!\n{e}')
|
||||||
|
self.exception()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
test = Test()
|
tester = Tester()
|
||||||
test.create()
|
tester.create()
|
||||||
test.start()
|
tester.disable_print()
|
||||||
|
tester.start()
|
||||||
|
tester.enable_print()
|
Loading…
Reference in New Issue
Block a user