2021.4 #19

Merged
edraft merged 237 commits from 2021.4 into master 2021-04-01 10:13:33 +02:00
4 changed files with 118 additions and 16 deletions
Showing only changes of commit 3f56247aa7 - Show all commits

View File

@ -18,6 +18,9 @@ from cpl.environment.environment_name_enum import EnvironmentNameEnum
class Configuration(ConfigurationABC):
def __init__(self):
"""
Representation of configuration
"""
ConfigurationABC.__init__(self)
self._hosting_environment = ApplicationEnvironment()
@ -28,7 +31,6 @@ class Configuration(ConfigurationABC):
self._argument_error_function: Optional[Callable] = None
self._is_multiple_args_allowed = False
self._handled_args = []
@property
@ -47,28 +49,49 @@ class Configuration(ConfigurationABC):
def argument_error_function(self, argument_error_function: Callable):
self._argument_error_function = argument_error_function
def allow_multiple_args(self):
self._is_multiple_args_allowed = True
@staticmethod
def _print_info(name: str, message: str):
"""
Prints an info message
:param name:
:param message:
:return:
"""
Console.set_foreground_color(ForegroundColorEnum.green)
Console.write_line(f'[{name}] {message}')
Console.set_foreground_color(ForegroundColorEnum.default)
@staticmethod
def _print_warn(name: str, message: str):
"""
Prints a warning
:param name:
:param message:
:return:
"""
Console.set_foreground_color(ForegroundColorEnum.yellow)
Console.write_line(f'[{name}] {message}')
Console.set_foreground_color(ForegroundColorEnum.default)
@staticmethod
def _print_error(name: str, message: str):
"""
Prints an error
:param name:
:param message:
:return:
"""
Console.set_foreground_color(ForegroundColorEnum.red)
Console.write_line(f'[{name}] {message}')
Console.set_foreground_color(ForegroundColorEnum.default)
def _set_variable(self, name: str, value: str):
"""
Sets variable to given value
:param name:
:param value:
:return:
"""
if name == ConfigurationVariableNameEnum.environment.value:
self._hosting_environment.environment_name = EnvironmentNameEnum(value)
@ -83,6 +106,13 @@ class Configuration(ConfigurationABC):
def _validate_argument_child(self, argument: str, argument_type: ConsoleArgument,
next_arguments: Optional[list[str]]) -> bool:
"""
Validates the child arguments of argument
:param argument:
:param argument_type:
:param next_arguments:
:return:
"""
if argument_type.console_arguments is not None and len(argument_type.console_arguments) > 0:
found = False
for child_argument_type in argument_type.console_arguments:
@ -99,6 +129,13 @@ class Configuration(ConfigurationABC):
def _validate_argument_by_argument_type(self, argument: str, argument_type: ConsoleArgument,
next_arguments: list[str] = None) -> bool:
"""
Validate argument by argument type
:param argument:
:param argument_type:
:param next_arguments:
:return:
"""
argument_name = ''
value = ''
result = False
@ -274,6 +311,12 @@ class Configuration(ConfigurationABC):
self.add_configuration(sub, configuration)
def _load_json_file(self, file: str, output: bool) -> dict:
"""
Reads the json file
:param file:
:param output:
:return:
"""
try:
# open config file, create if not exists
with open(file, encoding='utf-8') as cfg:

View File

@ -10,7 +10,11 @@ from cpl.environment.environment_abc import ApplicationEnvironmentABC
class ConfigurationABC(ABC):
@abstractmethod
def __init__(self): pass
def __init__(self):
"""
ABC of configuration
"""
pass
@property
@abstractmethod
@ -29,22 +33,58 @@ class ConfigurationABC(ABC):
def argument_error_function(self, argument_error_function: Callable): pass
@abstractmethod
def allow_multiple_args(self): pass
def add_environment_variables(self, prefix: str):
"""
Reads the environment variables
:param prefix:
:return:
"""
pass
@abstractmethod
def add_environment_variables(self, prefix: str): pass
def add_console_argument(self, argument: ConsoleArgument):
"""
Adds console argument to known console arguments
:param argument:
:return:
"""
pass
@abstractmethod
def add_console_argument(self, argument: ConsoleArgument): pass
def add_console_arguments(self):
"""
Reads the console arguments
:return:
"""
pass
@abstractmethod
def add_console_arguments(self): pass
def add_json_file(self, name: str, optional: bool = None, output: bool = True):
"""
Reads and saves settings from given json file
:param name:
:param optional:
:param output:
:return:
"""
pass
@abstractmethod
def add_json_file(self, name: str, optional: bool = None, output: bool = True): pass
def add_configuration(self, key_type: type, value: object):
"""
Add configuration object
:param key_type:
:param value:
:return:
"""
pass
@abstractmethod
def add_configuration(self, key_type: type, value: object): pass
@abstractmethod
def get_configuration(self, search_type: Union[str, Type[ConfigurationModelABC]]) -> Union[str, Callable[ConfigurationModelABC]]: pass
def get_configuration(self, search_type: Union[str, Type[ConfigurationModelABC]]) -> Union[
str, Callable[ConfigurationModelABC]]:
"""
Returns value in configuration by given type
:param search_type:
:return:
"""
pass

View File

@ -4,7 +4,17 @@ from abc import ABC, abstractmethod
class ConfigurationModelABC(ABC):
@abstractmethod
def __init__(self): pass
def __init__(self):
"""
ABC for settings representation
"""
pass
@abstractmethod
def from_dict(self, settings: dict): pass
def from_dict(self, settings: dict):
"""
Converts attributes to dict
:param settings:
:return:
"""
pass

View File

@ -8,6 +8,15 @@ class ConsoleArgument:
is_value_token_optional: bool = None,
console_arguments: list['ConsoleArgument'] = None
):
"""
Representation of an console argument
:param token:
:param name:
:param aliases:
:param value_token:
:param is_value_token_optional:
:param console_arguments:
"""
self._token = token
self._name = name
self._aliases = aliases