Renamed by internal conventions

This commit is contained in:
Sven Heidemann 2021-03-12 16:06:30 +01:00
parent b3b65f3dd2
commit 2580d4b6cf
43 changed files with 202 additions and 202 deletions

View File

@ -9,10 +9,10 @@ from cpl.configuration.configuration_model_abc import ConfigurationModelABC
from cpl.configuration.configuration_variable_name_enum import ConfigurationVariableNameEnum
from cpl.configuration.console_argument import ConsoleArgument
from cpl.console.console import Console
from cpl.console.foreground_color_enum import ForegroundColor
from cpl.console.foreground_color_enum import ForegroundColorEnum
from cpl.environment.hosting_environment import HostingEnvironment
from cpl.environment.environment_abc import EnvironmentABC
from cpl.environment.environment_name_enum import EnvironmentName
from cpl.environment.environment_name_enum import EnvironmentNameEnum
class Configuration(ConfigurationABC):
@ -52,21 +52,21 @@ class Configuration(ConfigurationABC):
@staticmethod
def _print_info(name: str, message: str):
Console.set_foreground_color(ForegroundColor.green)
Console.set_foreground_color(ForegroundColorEnum.green)
Console.write_line(f'[{name}] {message}')
Console.set_foreground_color(ForegroundColor.default)
Console.set_foreground_color(ForegroundColorEnum.default)
@staticmethod
def _print_warn(name: str, message: str):
Console.set_foreground_color(ForegroundColor.yellow)
Console.set_foreground_color(ForegroundColorEnum.yellow)
Console.write_line(f'[{name}] {message}')
Console.set_foreground_color(ForegroundColor.default)
Console.set_foreground_color(ForegroundColorEnum.default)
@staticmethod
def _print_error(name: str, message: str):
Console.set_foreground_color(ForegroundColor.red)
Console.set_foreground_color(ForegroundColorEnum.red)
Console.write_line(f'[{name}] {message}')
Console.set_foreground_color(ForegroundColor.default)
Console.set_foreground_color(ForegroundColorEnum.default)
def _set_variable(self, name: str, value: str):
if name == ConfigurationVariableNameEnum.environment.value:

View File

@ -23,7 +23,7 @@ from collections import namedtuple
from .background_color_enum import BackgroundColorEnum
from .console import Console
from .console_call import ConsoleCall
from .foreground_color_enum import ForegroundColor
from .foreground_color_enum import ForegroundColorEnum
from .spinner_thread import SpinnerThread
VersionInfo = namedtuple('VersionInfo', 'major minor micro')

View File

@ -8,7 +8,7 @@ from termcolor import colored
from cpl.console.background_color_enum import BackgroundColorEnum
from cpl.console.console_call import ConsoleCall
from cpl.console.foreground_color_enum import ForegroundColor
from cpl.console.foreground_color_enum import ForegroundColorEnum
from cpl.console.spinner_thread import SpinnerThread
@ -16,7 +16,7 @@ class Console:
_is_first_write = True
_background_color: BackgroundColorEnum = BackgroundColorEnum.default
_foreground_color: ForegroundColor = ForegroundColor.default
_foreground_color: ForegroundColorEnum = ForegroundColorEnum.default
_x: Optional[int] = None
_y: Optional[int] = None
_disabled: bool = False
@ -54,10 +54,10 @@ class Console:
cls._background_color = color
@classmethod
def set_foreground_color(cls, color: Union[ForegroundColor, str]):
def set_foreground_color(cls, color: Union[ForegroundColorEnum, str]):
if type(color) is str:
cls._foreground_color = ForegroundColor[color]
cls._foreground_color = ForegroundColorEnum[color]
else:
cls._foreground_color = color
@ -88,11 +88,11 @@ class Console:
args.append(f'\033[{cls._y};{cls._x}H')
colored_args.append(string)
if cls._foreground_color != ForegroundColor.default and cls._background_color == BackgroundColorEnum.default:
if cls._foreground_color != ForegroundColorEnum.default and cls._background_color == BackgroundColorEnum.default:
colored_args.append(cls._foreground_color.value)
elif cls._foreground_color == ForegroundColor.default and cls._background_color != BackgroundColorEnum.default:
elif cls._foreground_color == ForegroundColorEnum.default and cls._background_color != BackgroundColorEnum.default:
colored_args.append(cls._background_color.value)
elif cls._foreground_color != ForegroundColor.default and cls._background_color != BackgroundColorEnum.default:
elif cls._foreground_color != ForegroundColorEnum.default and cls._background_color != BackgroundColorEnum.default:
colored_args.append(cls._foreground_color.value)
colored_args.append(cls._background_color.value)
@ -183,7 +183,7 @@ class Console:
@classmethod
def reset(cls):
cls._background_color = BackgroundColorEnum.default
cls._foreground_color = ForegroundColor.default
cls._foreground_color = ForegroundColorEnum.default
@classmethod
def table(cls, header: list[str], values: list[list[str]]):
@ -252,7 +252,7 @@ class Console:
cls._output(string, x, y, end='')
@classmethod
def spinner(cls, message: str, call: Callable, *args, text_foreground_color: ForegroundColor = None, spinner_foreground_color: ForegroundColor = None, text_background_color: BackgroundColorEnum = None, spinner_background_color: BackgroundColorEnum = None) -> any:
def spinner(cls, message: str, call: Callable, *args, text_foreground_color: ForegroundColorEnum = None, spinner_foreground_color: ForegroundColorEnum = None, text_background_color: BackgroundColorEnum = None, spinner_background_color: BackgroundColorEnum = None) -> any:
if cls._hold_back:
cls._hold_back_calls.append(ConsoleCall(cls.spinner, message, call, *args))
return
@ -271,7 +271,7 @@ class Console:
spinner.stop_spinning()
cls.set_hold_back(False)
cls.set_foreground_color(ForegroundColor.default)
cls.set_foreground_color(ForegroundColorEnum.default)
cls.set_background_color(BackgroundColorEnum.default)
for call in cls._hold_back_calls:

View File

@ -1,7 +1,7 @@
from enum import Enum
class ForegroundColor(Enum):
class ForegroundColorEnum(Enum):
default = 'default'
grey = 'grey'

View File

@ -6,12 +6,12 @@ import time
from termcolor import colored
from cpl.console.background_color_enum import BackgroundColorEnum
from cpl.console.foreground_color_enum import ForegroundColor
from cpl.console.foreground_color_enum import ForegroundColorEnum
class SpinnerThread(threading.Thread):
def __init__(self, msg_len: int, foreground_color: ForegroundColor, background_color: BackgroundColorEnum):
def __init__(self, msg_len: int, foreground_color: ForegroundColorEnum, background_color: BackgroundColorEnum):
threading.Thread.__init__(self)
self._msg_len = msg_len

View File

@ -22,7 +22,7 @@ from collections import namedtuple
# imports:
from .database_model import DatabaseModel
from .database_settings import DatabaseSettings
from .database_settings_name_enum import DatabaseSettingsName
from .database_settings_name_enum import DatabaseSettingsNameEnum
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major=2021, minor=4, micro=1)

View File

@ -4,7 +4,7 @@ from sqlalchemy import engine, create_engine
from sqlalchemy.orm import Session, sessionmaker
from cpl.console.console import Console
from cpl.console.foreground_color_enum import ForegroundColor
from cpl.console.foreground_color_enum import ForegroundColorEnum
from cpl.database.connection.database_connection_abc import DatabaseConnectionABC
from cpl.database.database_settings import DatabaseSettings
@ -48,11 +48,11 @@ class DatabaseConnection(DatabaseConnectionABC):
db_session = sessionmaker(bind=self._engine)
self._session = db_session()
Console.set_foreground_color(ForegroundColor.green)
Console.set_foreground_color(ForegroundColorEnum.green)
Console.write_line(f'[{__name__}] Connected to database')
Console.set_foreground_color(ForegroundColor.default)
Console.set_foreground_color(ForegroundColorEnum.default)
except Exception as e:
Console.set_foreground_color(ForegroundColor.red)
Console.set_foreground_color(ForegroundColorEnum.red)
Console.write_line(f'[{__name__}] Database connection failed -> {e}')
Console.set_foreground_color(ForegroundColor.default)
Console.set_foreground_color(ForegroundColorEnum.default)
exit()

View File

@ -2,7 +2,7 @@ from sqlalchemy import engine, Table
from sqlalchemy.orm import Session
from cpl.console.console import Console
from cpl.console.foreground_color_enum import ForegroundColor
from cpl.console.foreground_color_enum import ForegroundColorEnum
from cpl.database.connection.database_connection import DatabaseConnection
from cpl.database.connection.database_connection_abc import DatabaseConnectionABC
from cpl.database.context.database_context_abc import DatabaseContextABC
@ -40,11 +40,11 @@ class DatabaseContext(DatabaseContextABC):
DatabaseModel.metadata.drop_all(self._db.engine, self._tables)
DatabaseModel.metadata.create_all(self._db.engine, self._tables, checkfirst=True)
Console.set_foreground_color(ForegroundColor.green)
Console.set_foreground_color(ForegroundColorEnum.green)
Console.write_line(f'[{__name__}] Created tables')
Console.set_foreground_color(ForegroundColor.default)
Console.set_foreground_color(ForegroundColorEnum.default)
except Exception as e:
Console.set_foreground_color(ForegroundColor.red)
Console.set_foreground_color(ForegroundColorEnum.red)
Console.write_line(f'[{__name__}] Creating tables failed -> {e}')
Console.set_foreground_color(ForegroundColor.default)
Console.set_foreground_color(ForegroundColorEnum.default)
exit()

View File

@ -3,8 +3,8 @@ from typing import Optional
from cpl.configuration.configuration_model_abc import ConfigurationModelABC
from cpl.console.console import Console
from cpl.console.foreground_color_enum import ForegroundColor
from cpl.database.database_settings_name_enum import DatabaseSettingsName
from cpl.console.foreground_color_enum import ForegroundColorEnum
from cpl.database.database_settings_name_enum import DatabaseSettingsNameEnum
class DatabaseSettings(ConfigurationModelABC):
@ -69,22 +69,22 @@ class DatabaseSettings(ConfigurationModelABC):
def from_dict(self, settings: dict):
try:
self._connection_string = settings[DatabaseSettingsName.connection_string.value]
self._credentials = settings[DatabaseSettingsName.credentials.value]
self._connection_string = settings[DatabaseSettingsNameEnum.connection_string.value]
self._credentials = settings[DatabaseSettingsNameEnum.credentials.value]
if DatabaseSettingsName.auth_plugin.value in settings:
self._auth_plugin = settings[DatabaseSettingsName.auth_plugin.value]
if DatabaseSettingsNameEnum.auth_plugin.value in settings:
self._auth_plugin = settings[DatabaseSettingsNameEnum.auth_plugin.value]
if DatabaseSettingsName.encoding.value in settings:
self._encoding = settings[DatabaseSettingsName.encoding.value]
if DatabaseSettingsNameEnum.encoding.value in settings:
self._encoding = settings[DatabaseSettingsNameEnum.encoding.value]
if DatabaseSettingsName.case_sensitive.value in settings:
self._case_sensitive = bool(settings[DatabaseSettingsName.case_sensitive.value])
if DatabaseSettingsNameEnum.case_sensitive.value in settings:
self._case_sensitive = bool(settings[DatabaseSettingsNameEnum.case_sensitive.value])
if DatabaseSettingsName.echo.value in settings:
self._echo = bool(settings[DatabaseSettingsName.echo.value])
if DatabaseSettingsNameEnum.echo.value in settings:
self._echo = bool(settings[DatabaseSettingsNameEnum.echo.value])
except Exception as e:
Console.set_foreground_color(ForegroundColor.red)
Console.set_foreground_color(ForegroundColorEnum.red)
Console.write_line(f'[ ERROR ] [ {__name__} ]: Reading error in {self.__name__} settings')
Console.write_line(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}')
Console.set_foreground_color(ForegroundColor.default)
Console.set_foreground_color(ForegroundColorEnum.default)

View File

@ -1,7 +1,7 @@
from enum import Enum
class DatabaseSettingsName(Enum):
class DatabaseSettingsNameEnum(Enum):
connection_string = 'ConnectionString'
credentials = 'Credentials'

View File

@ -21,7 +21,7 @@ from collections import namedtuple
# imports:
from .environment_abc import EnvironmentABC
from .environment_name_enum import EnvironmentName
from .environment_name_enum import EnvironmentNameEnum
from .hosting_environment import HostingEnvironment
VersionInfo = namedtuple('VersionInfo', 'major minor micro')

View File

@ -1,7 +1,7 @@
from enum import Enum
class EnvironmentName(Enum):
class EnvironmentNameEnum(Enum):
production = 'production'
staging = 'staging'

View File

@ -2,15 +2,15 @@ from socket import gethostname
from typing import Optional
from cpl.environment.environment_abc import EnvironmentABC
from cpl.environment.environment_name_enum import EnvironmentName
from cpl.environment.environment_name_enum import EnvironmentNameEnum
class HostingEnvironment(EnvironmentABC):
def __init__(self, name: EnvironmentName = EnvironmentName.production, crp: str = './'):
def __init__(self, name: EnvironmentNameEnum = EnvironmentNameEnum.production, crp: str = './'):
EnvironmentABC.__init__(self)
self._environment_name: Optional[EnvironmentName] = name
self._environment_name: Optional[EnvironmentNameEnum] = name
self._app_name: Optional[str] = None
self._customer: Optional[str] = None
self._content_root_path: Optional[str] = crp

View File

@ -22,9 +22,9 @@ from collections import namedtuple
# imports:
from .logger_service import Logger
from .logger_abc import LoggerABC
from .logging_level_enum import LoggingLevel
from .logging_level_enum import LoggingLevelEnum
from .logging_settings import LoggingSettings
from .logging_settings_name_enum import LoggingSettingsName
from .logging_settings_name_enum import LoggingSettingsNameEnum
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major=2021, minor=4, micro=1)

View File

@ -5,9 +5,9 @@ from string import Template
from cpl.application.application_runtime_abc import ApplicationRuntimeABC
from cpl.console.console import Console
from cpl.console.foreground_color_enum import ForegroundColor
from cpl.console.foreground_color_enum import ForegroundColorEnum
from cpl.logging.logger_abc import LoggerABC
from cpl.logging.logging_level_enum import LoggingLevel
from cpl.logging.logging_level_enum import LoggingLevelEnum
from cpl.logging.logging_settings import LoggingSettings
from cpl.time.time_format_settings import TimeFormatSettings
@ -74,106 +74,106 @@ class Logger(LoggerABC):
except Exception as e:
self._fatal_console(__name__, f'Cannot append log file, message: {string}', ex=e)
def _get_string(self, name: str, level: LoggingLevel, message: str) -> str:
def _get_string(self, name: str, level: LoggingLevelEnum, 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.set_foreground_color(ForegroundColor.default)
Console.set_foreground_color(ForegroundColorEnum.default)
Console.write_line(string)
Console.set_foreground_color(ForegroundColor.default)
Console.set_foreground_color(ForegroundColorEnum.default)
def trace(self, name: str, message: str):
output = self._get_string(name, LoggingLevel.TRACE, message)
output = self._get_string(name, LoggingLevelEnum.TRACE, message)
# check if message can be written to log
if self._level.value >= LoggingLevel.TRACE.value:
if self._level.value >= LoggingLevelEnum.TRACE.value:
self._append_log(output)
# check if message can be shown in console_old
if self._console.value >= LoggingLevel.TRACE.value:
Console.set_foreground_color(ForegroundColor.green)
if self._console.value >= LoggingLevelEnum.TRACE.value:
Console.set_foreground_color(ForegroundColorEnum.green)
Console.write_line(output)
Console.set_foreground_color(ForegroundColor.default)
Console.set_foreground_color(ForegroundColorEnum.default)
def debug(self, name: str, message: str):
output = self._get_string(name, LoggingLevel.DEBUG, message)
output = self._get_string(name, LoggingLevelEnum.DEBUG, message)
# check if message can be written to log
if self._level.value >= LoggingLevel.DEBUG.value:
if self._level.value >= LoggingLevelEnum.DEBUG.value:
self._append_log(output)
# check if message can be shown in console_old
if self._console.value >= LoggingLevel.DEBUG.value:
Console.set_foreground_color(ForegroundColor.green)
if self._console.value >= LoggingLevelEnum.DEBUG.value:
Console.set_foreground_color(ForegroundColorEnum.green)
Console.write_line(output)
Console.set_foreground_color(ForegroundColor.default)
Console.set_foreground_color(ForegroundColorEnum.default)
def info(self, name: str, message: str):
output = self._get_string(name, LoggingLevel.INFO, message)
output = self._get_string(name, LoggingLevelEnum.INFO, message)
# check if message can be written to log
if self._level.value >= LoggingLevel.INFO.value:
if self._level.value >= LoggingLevelEnum.INFO.value:
self._append_log(output)
# check if message can be shown in console_old
if self._console.value >= LoggingLevel.INFO.value:
Console.set_foreground_color(ForegroundColor.green)
if self._console.value >= LoggingLevelEnum.INFO.value:
Console.set_foreground_color(ForegroundColorEnum.green)
Console.write_line(output)
Console.set_foreground_color(ForegroundColor.default)
Console.set_foreground_color(ForegroundColorEnum.default)
def warn(self, name: str, message: str):
output = self._get_string(name, LoggingLevel.WARN, message)
output = self._get_string(name, LoggingLevelEnum.WARN, message)
# check if message can be written to log
if self._level.value >= LoggingLevel.WARN.value:
if self._level.value >= LoggingLevelEnum.WARN.value:
self._append_log(output)
# check if message can be shown in console_old
if self._console.value >= LoggingLevel.WARN.value:
Console.set_foreground_color(ForegroundColor.yellow)
if self._console.value >= LoggingLevelEnum.WARN.value:
Console.set_foreground_color(ForegroundColorEnum.yellow)
Console.write_line(output)
Console.set_foreground_color(ForegroundColor.default)
Console.set_foreground_color(ForegroundColorEnum.default)
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}')
output = self._get_string(name, LoggingLevelEnum.ERROR, f'{ex} -> {tb}')
else:
output = self._get_string(name, LoggingLevel.ERROR, message)
output = self._get_string(name, LoggingLevelEnum.ERROR, message)
# check if message can be written to log
if self._level.value >= LoggingLevel.ERROR.value:
if self._level.value >= LoggingLevelEnum.ERROR.value:
self._append_log(output)
# check if message can be shown in console_old
if self._console.value >= LoggingLevel.ERROR.value:
Console.set_foreground_color(ForegroundColor.red)
if self._console.value >= LoggingLevelEnum.ERROR.value:
Console.set_foreground_color(ForegroundColorEnum.red)
Console.write_line(output)
Console.set_foreground_color(ForegroundColor.default)
Console.set_foreground_color(ForegroundColorEnum.default)
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.FATAL, f'{ex} -> {tb}')
output = self._get_string(name, LoggingLevelEnum.FATAL, f'{ex} -> {tb}')
else:
output = self._get_string(name, LoggingLevel.FATAL, message)
output = self._get_string(name, LoggingLevelEnum.FATAL, message)
# check if message can be written to log
if self._level.value >= LoggingLevel.FATAL.value:
if self._level.value >= LoggingLevelEnum.FATAL.value:
self._append_log(output)
# check if message can be shown in console_old
if self._console.value >= LoggingLevel.FATAL.value:
Console.set_foreground_color(ForegroundColor.red)
if self._console.value >= LoggingLevelEnum.FATAL.value:
Console.set_foreground_color(ForegroundColorEnum.red)
Console.write_line(output)
Console.set_foreground_color(ForegroundColor.default)
Console.set_foreground_color(ForegroundColorEnum.default)
exit()
@ -182,14 +182,14 @@ class Logger(LoggerABC):
if ex is not None:
tb = traceback.format_exc()
self.error(name, message)
output = self._get_string(name, LoggingLevel.ERROR, f'{ex} -> {tb}')
output = self._get_string(name, LoggingLevelEnum.ERROR, f'{ex} -> {tb}')
else:
output = self._get_string(name, LoggingLevel.ERROR, message)
output = self._get_string(name, LoggingLevelEnum.ERROR, message)
# check if message can be shown in console_old
if self._console.value >= LoggingLevel.FATAL.value:
Console.set_foreground_color(ForegroundColor.red)
if self._console.value >= LoggingLevelEnum.FATAL.value:
Console.set_foreground_color(ForegroundColorEnum.red)
Console.write_line(output)
Console.set_foreground_color(ForegroundColor.default)
Console.set_foreground_color(ForegroundColorEnum.default)
exit()

View File

@ -1,7 +1,7 @@
from enum import Enum
class LoggingLevel(Enum):
class LoggingLevelEnum(Enum):
OFF = 0 # Nothing
FATAL = 1 # Error that cause exit

View File

@ -3,9 +3,9 @@ from typing import Optional
from cpl.configuration.configuration_model_abc import ConfigurationModelABC
from cpl.console.console import Console
from cpl.console.foreground_color_enum import ForegroundColor
from cpl.logging.logging_level_enum import LoggingLevel
from cpl.logging.logging_settings_name_enum import LoggingSettingsName
from cpl.console.foreground_color_enum import ForegroundColorEnum
from cpl.logging.logging_level_enum import LoggingLevelEnum
from cpl.logging.logging_settings_name_enum import LoggingSettingsNameEnum
class LoggingSettings(ConfigurationModelABC):
@ -14,8 +14,8 @@ class LoggingSettings(ConfigurationModelABC):
ConfigurationModelABC.__init__(self)
self._path: Optional[str] = None
self._filename: Optional[str] = None
self._console: Optional[LoggingLevel] = None
self._level: Optional[LoggingLevel] = None
self._console: Optional[LoggingLevelEnum] = None
self._level: Optional[LoggingLevelEnum] = None
@property
def path(self) -> str:
@ -34,29 +34,29 @@ class LoggingSettings(ConfigurationModelABC):
self._filename = filename
@property
def console(self) -> LoggingLevel:
def console(self) -> LoggingLevelEnum:
return self._console
@console.setter
def console(self, console: LoggingLevel) -> None:
def console(self, console: LoggingLevelEnum) -> None:
self._console = console
@property
def level(self) -> LoggingLevel:
def level(self) -> LoggingLevelEnum:
return self._level
@level.setter
def level(self, level: LoggingLevel) -> None:
def level(self, level: LoggingLevelEnum) -> None:
self._level = level
def from_dict(self, settings: dict):
try:
self._path = settings[LoggingSettingsName.path.value]
self._filename = settings[LoggingSettingsName.filename.value]
self._console = LoggingLevel[settings[LoggingSettingsName.console_level.value]]
self._level = LoggingLevel[settings[LoggingSettingsName.file_level.value]]
self._path = settings[LoggingSettingsNameEnum.path.value]
self._filename = settings[LoggingSettingsNameEnum.filename.value]
self._console = LoggingLevelEnum[settings[LoggingSettingsNameEnum.console_level.value]]
self._level = LoggingLevelEnum[settings[LoggingSettingsNameEnum.file_level.value]]
except Exception as e:
Console.set_foreground_color(ForegroundColor.red)
Console.set_foreground_color(ForegroundColorEnum.red)
Console.write_line(f'[ ERROR ] [ {__name__} ]: Reading error in {self.__name__} settings')
Console.write_line(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}')
Console.set_foreground_color(ForegroundColor.default)
Console.set_foreground_color(ForegroundColorEnum.default)

View File

@ -1,7 +1,7 @@
from enum import Enum
class LoggingSettingsName(Enum):
class LoggingSettingsNameEnum(Enum):
path = 'Path'
filename = 'Filename'

View File

@ -24,7 +24,7 @@ from .email import EMail
from .email_client_service import EMailClient
from .email_client_abc import EMailClientABC
from .email_client_settings import EMailClientSettings
from .email_client_settings_name_enum import EMailClientSettingsName
from .email_client_settings_name_enum import EMailClientSettingsNameEnum
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major=2021, minor=4, micro=1)

View File

@ -2,7 +2,7 @@ import traceback
from cpl.configuration.configuration_model_abc import ConfigurationModelABC
from cpl.console.console import Console
from cpl.mailing.email_client_settings_name_enum import EMailClientSettingsName
from cpl.mailing.email_client_settings_name_enum import EMailClientSettingsNameEnum
class EMailClientSettings(ConfigurationModelABC):
@ -49,10 +49,10 @@ class EMailClientSettings(ConfigurationModelABC):
def from_dict(self, settings: dict):
try:
self._host = settings[EMailClientSettingsName.host.value]
self._port = settings[EMailClientSettingsName.port.value]
self._user_name = settings[EMailClientSettingsName.user_name.value]
self._credentials = settings[EMailClientSettingsName.credentials.value]
self._host = settings[EMailClientSettingsNameEnum.host.value]
self._port = settings[EMailClientSettingsNameEnum.port.value]
self._user_name = settings[EMailClientSettingsNameEnum.user_name.value]
self._credentials = settings[EMailClientSettingsNameEnum.credentials.value]
except Exception as e:
Console.error(f'[ ERROR ] [ {__name__} ]: Reading error in {self.__name__} settings')
Console.error(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}')

View File

@ -1,7 +1,7 @@
from enum import Enum
class EMailClientSettingsName(Enum):
class EMailClientSettingsNameEnum(Enum):
host = 'Host'
port = 'Port'

View File

@ -21,7 +21,7 @@ from collections import namedtuple
# imports:
from .time_format_settings import TimeFormatSettings
from .time_format_settings_names_enum import TimeFormatSettingsNames
from .time_format_settings_names_enum import TimeFormatSettingsNamesEnum
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major=2021, minor=4, micro=1)

View File

@ -3,8 +3,8 @@ from typing import Optional
from cpl.configuration.configuration_model_abc import ConfigurationModelABC
from cpl.console.console import Console
from cpl.console.foreground_color_enum import ForegroundColor
from cpl.time.time_format_settings_names_enum import TimeFormatSettingsNames
from cpl.console.foreground_color_enum import ForegroundColorEnum
from cpl.time.time_format_settings_names_enum import TimeFormatSettingsNamesEnum
class TimeFormatSettings(ConfigurationModelABC):
@ -50,12 +50,12 @@ class TimeFormatSettings(ConfigurationModelABC):
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]
self._date_format = settings[TimeFormatSettingsNamesEnum.date_format.value]
self._time_format = settings[TimeFormatSettingsNamesEnum.time_format.value]
self._date_time_format = settings[TimeFormatSettingsNamesEnum.date_time_format.value]
self._date_time_log_format = settings[TimeFormatSettingsNamesEnum.date_time_log_format.value]
except Exception as e:
Console.set_foreground_color(ForegroundColor.red)
Console.set_foreground_color(ForegroundColorEnum.red)
Console.write_line(f'[ ERROR ] [ {__name__} ]: Reading error in {self.__name__} settings')
Console.write_line(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}')
Console.set_foreground_color(ForegroundColor.default)
Console.set_foreground_color(ForegroundColorEnum.default)

View File

@ -1,7 +1,7 @@
from enum import Enum
class TimeFormatSettingsNames(Enum):
class TimeFormatSettingsNamesEnum(Enum):
date_format = 'DateFormat'
time_format = 'TimeFormat'

View File

@ -22,7 +22,7 @@ from collections import namedtuple
# imports:
from .cli import CLI
from .command_abc import CommandABC
from .command_handler import CommandHandler
from .command_handler_service import CommandHandler
from .command_model import CommandModel
from .error import Error
from .main import main

View File

@ -1,15 +1,15 @@
from typing import Optional
from cpl.application.application_abc import ApplicationABC
from cpl_cli.command.build import Build
from cpl_cli.command.generate import Generate
from cpl_cli.command.new import New
from cpl_cli.command.publish import Publish
from cpl_cli.command_handler import CommandHandler
from cpl_cli.command.build_service import BuildService
from cpl_cli.command.generate_service import GenerateService
from cpl_cli.command.new_service import NewService
from cpl_cli.command.publish_service import PublishService
from cpl_cli.command_handler_service import CommandHandler
from cpl_cli.command_model import CommandModel
from cpl_cli.error import Error
from cpl_cli.command.help import Help
from cpl_cli.command.version import Version
from cpl_cli.command.help_service import HelpService
from cpl_cli.command.version_service import VersionService
class CLI(ApplicationABC):
@ -22,12 +22,12 @@ class CLI(ApplicationABC):
def configure(self):
self._command_handler: CommandHandler = self._services.get_service(CommandHandler)
self._command_handler.add_command(CommandModel('build', ['h', 'B'], Build, True))
self._command_handler.add_command(CommandModel('generate', ['g', 'G'], Generate, True))
self._command_handler.add_command(CommandModel('help', ['h', 'H'], Help, False))
self._command_handler.add_command(CommandModel('new', ['n', 'N'], New, False))
self._command_handler.add_command(CommandModel('publish', ['p', 'P'], Publish, True))
self._command_handler.add_command(CommandModel('version', ['v', 'V'], Version, False))
self._command_handler.add_command(CommandModel('build', ['h', 'B'], BuildService, True))
self._command_handler.add_command(CommandModel('generate', ['g', 'G'], GenerateService, True))
self._command_handler.add_command(CommandModel('help', ['h', 'H'], HelpService, False))
self._command_handler.add_command(CommandModel('new', ['n', 'N'], NewService, False))
self._command_handler.add_command(CommandModel('publish', ['p', 'P'], PublishService, True))
self._command_handler.add_command(CommandModel('version', ['v', 'V'], VersionService, False))
def main(self):
if len(self._configuration.additional_arguments) < 1:

View File

@ -3,7 +3,7 @@ from cpl_cli.command_abc import CommandABC
from cpl_cli.publish.publisher_abc import PublisherABC
class Build(CommandABC):
class BuildService(CommandABC):
def __init__(self, publisher: PublisherABC):
CommandABC.__init__(self)

View File

@ -3,7 +3,7 @@ from collections import Callable
from cpl.application.application_abc import ApplicationRuntimeABC
from cpl.configuration.configuration_abc import ConfigurationABC
from cpl.console.foreground_color_enum import ForegroundColor
from cpl.console.foreground_color_enum import ForegroundColorEnum
from cpl.console.console import Console
from cpl.utils.string import String
from cpl_cli.command_abc import CommandABC
@ -16,7 +16,7 @@ from cpl_cli.templates.generate.thread_template import ThreadTemplate
from cpl_cli.templates.template_file_abc import TemplateFileABC
class Generate(CommandABC):
class GenerateService(CommandABC):
def __init__(self, configuration: ConfigurationABC, runtime: ApplicationRuntimeABC):
CommandABC.__init__(self)
@ -99,8 +99,8 @@ class Generate(CommandABC):
self._create_file,
file_path,
template.value,
text_foreground_color=ForegroundColor.green,
spinner_foreground_color=ForegroundColor.cyan
text_foreground_color=ForegroundColorEnum.green,
spinner_foreground_color=ForegroundColorEnum.cyan
)
def run(self, args: list[str]):

View File

@ -1,9 +1,9 @@
from cpl.console.console import Console
from cpl.console.foreground_color_enum import ForegroundColor
from cpl.console.foreground_color_enum import ForegroundColorEnum
from cpl_cli.command_abc import CommandABC
class Help(CommandABC):
class HelpService(CommandABC):
def __init__(self):
CommandABC.__init__(self)
@ -21,9 +21,9 @@ class Help(CommandABC):
['version (v|V)', 'Outputs CPL CLI version.']
]
for name, description in commands:
Console.set_foreground_color(ForegroundColor.blue)
Console.set_foreground_color(ForegroundColorEnum.blue)
Console.write(f'\n\t{name} ')
Console.set_foreground_color(ForegroundColor.default)
Console.set_foreground_color(ForegroundColorEnum.default)
Console.write(f'{description}')
Console.write('\n')

View File

@ -6,14 +6,14 @@ from typing import Optional
from cpl.application.application_runtime_abc import ApplicationRuntimeABC
from cpl.configuration.configuration_abc import ConfigurationABC
from cpl.console.foreground_color_enum import ForegroundColor
from cpl.console.foreground_color_enum import ForegroundColorEnum
from cpl.console.console import Console
from cpl_cli.command_abc import CommandABC
from cpl_cli.configuration.build_settings import BuildSettings
from cpl_cli.configuration.build_settings_name import BuildSettingsName
from cpl_cli.configuration.build_settings_name_enum import BuildSettingsName
from cpl_cli.configuration.project_settings import ProjectSettings
from cpl_cli.configuration.project_settings_name import ProjectSettingsName
from cpl_cli.configuration.version_settings_name import VersionSettingsName
from cpl_cli.configuration.project_settings_name_enum import ProjectSettingsName
from cpl_cli.configuration.version_settings_name_enum import VersionSettingsName
from cpl_cli.templates.new.console.license import LicenseTemplate
from cpl_cli.templates.new.console.readme_py import ReadmeTemplate
from cpl_cli.templates.new.console.src.application import ApplicationTemplate
@ -23,7 +23,7 @@ from cpl_cli.templates.new.console.src.tests.init import TestsInitTemplate
from cpl_cli.templates.template_file_abc import TemplateFileABC
class New(CommandABC):
class NewService(CommandABC):
def __init__(self, configuration: ConfigurationABC, runtime: ApplicationRuntimeABC):
CommandABC.__init__(self)
@ -106,7 +106,7 @@ class New(CommandABC):
if result.lower() == 'y':
self._use_startup = True
Console.set_foreground_color(ForegroundColor.default)
Console.set_foreground_color(ForegroundColorEnum.default)
# else:
# result = Console.read('Do you want to use service providing? (y/n) ')
@ -142,8 +142,8 @@ class New(CommandABC):
self._create_template,
project_path,
template,
text_foreground_color=ForegroundColor.green,
spinner_foreground_color=ForegroundColor.cyan
text_foreground_color=ForegroundColorEnum.green,
spinner_foreground_color=ForegroundColorEnum.cyan
)
@staticmethod

View File

@ -3,7 +3,7 @@ from cpl_cli.command_abc import CommandABC
from cpl_cli.publish.publisher_abc import PublisherABC
class Publish(CommandABC):
class PublishService(CommandABC):
def __init__(self, publisher: PublisherABC):
CommandABC.__init__(self)

View File

@ -7,19 +7,19 @@ import pkg_resources
import cpl
import cpl_cli
from cpl.console.console import Console
from cpl.console.foreground_color_enum import ForegroundColor
from cpl.console.foreground_color_enum import ForegroundColorEnum
from cpl_cli.command_abc import CommandABC
class Version(CommandABC):
class VersionService(CommandABC):
def __init__(self):
CommandABC.__init__(self)
def run(self, args: list[str]):
Console.set_foreground_color(ForegroundColor.yellow)
Console.set_foreground_color(ForegroundColorEnum.yellow)
Console.banner('CPL CLI')
Console.set_foreground_color(ForegroundColor.default)
Console.set_foreground_color(ForegroundColorEnum.default)
if '__version__' in dir(cpl_cli):
Console.write_line(f'Common Python library CLI: ')
Console.write(cpl_cli.__version__)

View File

@ -3,8 +3,8 @@ from typing import Optional
from cpl.configuration.configuration_model_abc import ConfigurationModelABC
from cpl.console.console import Console
from cpl.console.foreground_color_enum import ForegroundColor
from cpl_cli.configuration.build_settings_name import BuildSettingsName
from cpl.console.foreground_color_enum import ForegroundColorEnum
from cpl_cli.configuration.build_settings_name_enum import BuildSettingsName
class BuildSettings(ConfigurationModelABC):
@ -64,8 +64,8 @@ class BuildSettings(ConfigurationModelABC):
self._excluded = settings[BuildSettingsName.excluded.value]
self._package_data = settings[BuildSettingsName.package_data.value]
except Exception as e:
Console.set_foreground_color(ForegroundColor.red)
Console.set_foreground_color(ForegroundColorEnum.red)
Console.write_line(
f'[ ERROR ] [ {__name__} ]: Reading error in {BuildSettings.__name__} settings')
Console.write_line(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}')
Console.set_foreground_color(ForegroundColor.default)
Console.set_foreground_color(ForegroundColorEnum.default)

View File

@ -3,9 +3,9 @@ from typing import Optional
from cpl.configuration.configuration_model_abc import ConfigurationModelABC
from cpl.console.console import Console
from cpl.console.foreground_color_enum import ForegroundColor
from cpl_cli.configuration.version import Version
from cpl_cli.configuration.project_settings_name import ProjectSettingsName
from cpl.console.foreground_color_enum import ForegroundColorEnum
from cpl_cli.configuration.version_settings import VersionSettings
from cpl_cli.configuration.project_settings_name_enum import ProjectSettingsName
class ProjectSettings(ConfigurationModelABC):
@ -14,7 +14,7 @@ class ProjectSettings(ConfigurationModelABC):
ConfigurationModelABC.__init__(self)
self._name: Optional[str] = None
self._version: Optional[Version] = Version()
self._version: Optional[VersionSettings] = VersionSettings()
self._author: Optional[str] = None
self._author_email: Optional[str] = None
self._description: Optional[str] = None
@ -32,7 +32,7 @@ class ProjectSettings(ConfigurationModelABC):
return self._name
@property
def version(self) -> Version:
def version(self) -> VersionSettings:
return self._version
@property
@ -95,8 +95,8 @@ class ProjectSettings(ConfigurationModelABC):
self._dependencies = settings[ProjectSettingsName.dependencies.value]
self._python_version = settings[ProjectSettingsName.python_version.value]
except Exception as e:
Console.set_foreground_color(ForegroundColor.red)
Console.set_foreground_color(ForegroundColorEnum.red)
Console.write_line(
f'[ ERROR ] [ {__name__} ]: Reading error in {ProjectSettings.__name__} settings')
Console.write_line(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}')
Console.set_foreground_color(ForegroundColor.default)
Console.set_foreground_color(ForegroundColorEnum.default)

View File

@ -1,10 +1,10 @@
from typing import Optional
from cpl.configuration.configuration_model_abc import ConfigurationModelABC
from cpl_cli.configuration.version_settings_name import VersionSettingsName
from cpl_cli.configuration.version_settings_name_enum import VersionSettingsName
class Version(ConfigurationModelABC):
class VersionSettings(ConfigurationModelABC):
def __init__(
self,

View File

@ -7,7 +7,7 @@ import setuptools
from setuptools import sandbox
from cpl.application.application_runtime_abc import ApplicationRuntimeABC
from cpl.console.foreground_color_enum import ForegroundColor
from cpl.console.foreground_color_enum import ForegroundColorEnum
from cpl.console.console import Console
from cpl_cli.configuration.build_settings import BuildSettings
from cpl_cli.configuration.project_settings import ProjectSettings
@ -299,20 +299,20 @@ class Publisher(PublisherABC):
def build(self):
self._output_path = os.path.join(self._output_path, 'build')
Console.spinner('Reading source files:', self._read_sources, text_foreground_color=ForegroundColor.green, spinner_foreground_color=ForegroundColor.blue)
Console.spinner('Creating internal packages:', self._create_packages, text_foreground_color=ForegroundColor.green, spinner_foreground_color=ForegroundColor.blue)
Console.spinner('Building application:', self._dist_files, text_foreground_color=ForegroundColor.green, spinner_foreground_color=ForegroundColor.blue)
Console.spinner('Reading source files:', self._read_sources, text_foreground_color=ForegroundColorEnum.green, spinner_foreground_color=ForegroundColorEnum.blue)
Console.spinner('Creating internal packages:', self._create_packages, text_foreground_color=ForegroundColorEnum.green, spinner_foreground_color=ForegroundColorEnum.blue)
Console.spinner('Building application:', self._dist_files, text_foreground_color=ForegroundColorEnum.green, spinner_foreground_color=ForegroundColorEnum.blue)
def publish(self):
self._output_path = os.path.join(self._output_path, 'publish')
Console.write_line('Build:')
Console.spinner('Reading source files:', self._read_sources, text_foreground_color=ForegroundColor.green, spinner_foreground_color=ForegroundColor.blue)
Console.spinner('Creating internal packages:', self._create_packages, text_foreground_color=ForegroundColor.green, spinner_foreground_color=ForegroundColor.blue)
Console.spinner('Building application:', self._dist_files, text_foreground_color=ForegroundColor.green, spinner_foreground_color=ForegroundColor.blue)
Console.spinner('Reading source files:', self._read_sources, text_foreground_color=ForegroundColorEnum.green, spinner_foreground_color=ForegroundColorEnum.blue)
Console.spinner('Creating internal packages:', self._create_packages, text_foreground_color=ForegroundColorEnum.green, spinner_foreground_color=ForegroundColorEnum.blue)
Console.spinner('Building application:', self._dist_files, text_foreground_color=ForegroundColorEnum.green, spinner_foreground_color=ForegroundColorEnum.blue)
Console.write_line('\nPublish:')
Console.spinner('Generating setup_template.py:', self._create_setup, text_foreground_color=ForegroundColor.green, spinner_foreground_color=ForegroundColor.blue)
Console.spinner('Generating setup_template.py:', self._create_setup, text_foreground_color=ForegroundColorEnum.green, spinner_foreground_color=ForegroundColorEnum.blue)
Console.write_line('Running setup_template.py:\n')
self._run_setup()
# Console.spinner('Cleaning dist path:', self._clean_dist_files)

View File

@ -6,15 +6,15 @@ from cpl.application.startup_abc import StartupABC
from cpl.configuration.console_argument import ConsoleArgument
from cpl.configuration.configuration_abc import ConfigurationABC
from cpl.dependency_injection.service_provider_abc import ServiceProviderABC
from cpl_cli.command.build import Build
from cpl_cli.command.generate import Generate
from cpl_cli.command.new import New
from cpl_cli.command.publish import Publish
from cpl_cli.command_handler import CommandHandler
from cpl_cli.command.help import Help
from cpl_cli.command.version import Version
from cpl_cli.command.build_service import BuildService
from cpl_cli.command.generate_service import GenerateService
from cpl_cli.command.new_service import NewService
from cpl_cli.command.publish_service import PublishService
from cpl_cli.command_handler_service import CommandHandler
from cpl_cli.command.help_service import HelpService
from cpl_cli.command.version_service import VersionService
from cpl_cli.error import Error
from cpl_cli.publish.publisher import Publisher
from cpl_cli.publish.publisher_service import Publisher
from cpl_cli.publish.publisher_abc import PublisherABC
@ -66,11 +66,11 @@ class Startup(StartupABC):
self._services.add_transient(PublisherABC, Publisher)
self._services.add_transient(Build)
self._services.add_transient(Generate)
self._services.add_transient(Help)
self._services.add_transient(New)
self._services.add_transient(Publish)
self._services.add_transient(Version)
self._services.add_transient(BuildService)
self._services.add_transient(GenerateService)
self._services.add_transient(HelpService)
self._services.add_transient(NewService)
self._services.add_transient(PublishService)
self._services.add_transient(VersionService)
return self._services