Improved internal settings

This commit is contained in:
Sven Heidemann 2023-04-04 23:19:59 +02:00
parent a8d4a7a362
commit 9af2a1962d
12 changed files with 112 additions and 143 deletions

View File

@ -17,21 +17,15 @@ class ConfigModel(GenerateSchematicABC):
class $Name(ConfigurationModelABC): class $Name(ConfigurationModelABC):
def __init__(self): def __init__(self, atr: str = None):
ConfigurationModelABC.__init__(self) ConfigurationModelABC.__init__(self)
self._atr = '' self._atr = atr
@property @property
def atr(self) -> str: def atr(self) -> str:
return self._atr return self._atr
def from_dict(self, settings: dict):
try:
self._atr = settings['atr']
except Exception as e:
Console.error(f'[ ERROR ] [ {__name__} ]: Reading error in {type(self).__name__} settings')
Console.error(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}')
""" """
x = self.build_code_str(code, Name=self._class_name) x = self.build_code_str(code, Name=self._class_name)
return x return x

View File

@ -7,18 +7,11 @@ from cpl_cli.cli_settings_name_enum import CLISettingsNameEnum
class CLISettings(ConfigurationModelABC): class CLISettings(ConfigurationModelABC):
def __init__(self): def __init__(self, pip_path: str = None):
ConfigurationModelABC.__init__(self) ConfigurationModelABC.__init__(self)
self._pip_path: Optional[str] = None self._pip_path: Optional[str] = pip_path
@property @property
def pip_path(self) -> str: def pip_path(self) -> str:
return self._pip_path return self._pip_path
def from_dict(self, settings: dict):
try:
self._pip_path = settings[CLISettingsNameEnum.pip_path.value]
except Exception as e:
Console.error(f"[ ERROR ] [ {__name__} ]: Reading error in {type(self).__name__} settings")
Console.error(f"[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}")

View File

@ -2,27 +2,57 @@ import sys
import traceback import traceback
from typing import Optional from typing import Optional
from cpl_cli.configuration.build_settings_name_enum import BuildSettingsNameEnum
from cpl_cli.configuration.project_type_enum import ProjectTypeEnum
from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC
from cpl_core.console.console import Console from cpl_core.console.console import Console
from cpl_core.console.foreground_color_enum import ForegroundColorEnum from cpl_core.console.foreground_color_enum import ForegroundColorEnum
from cpl_cli.configuration.build_settings_name_enum import BuildSettingsNameEnum
from cpl_cli.configuration.project_type_enum import ProjectTypeEnum
class BuildSettings(ConfigurationModelABC): class BuildSettings(ConfigurationModelABC):
def __init__(self): def __init__(
self,
project_type: ProjectTypeEnum = None,
source_path: str = None,
output_path: str = None,
main: str = None,
entry_point: str = None,
include_package_data: bool = None,
included: list[str] = None,
excluded: list[str] = None,
package_data: dict[str, list[str]] = None,
project_references: list[str] = None,
):
ConfigurationModelABC.__init__(self) ConfigurationModelABC.__init__(self)
self._project_type: Optional[ProjectTypeEnum] = None self._project_type: Optional[ProjectTypeEnum] = project_type
self._source_path: Optional[str] = None self._source_path: Optional[str] = source_path
self._output_path: Optional[str] = None self._output_path: Optional[str] = output_path
self._main: Optional[str] = None self._main: Optional[str] = main
self._entry_point: Optional[str] = None self._entry_point: Optional[str] = entry_point
self._include_package_data: Optional[bool] = None self._include_package_data: Optional[bool] = include_package_data
self._included: Optional[list[str]] = None self._included: Optional[list[str]] = included
self._excluded: Optional[list[str]] = None self._excluded: Optional[list[str]] = excluded
self._package_data: Optional[dict[str, list[str]]] = None self._package_data: Optional[dict[str, list[str]]] = package_data
self._project_references: Optional[list[str]] = None self._project_references: Optional[list[str]] = [] if project_references is None else project_references
if sys.platform == "win32":
self._source_path = str(self._source_path).replace("/", "\\")
self._output_path = str(self._output_path).replace("/", "\\")
# windows paths for excluded files
excluded = []
for ex in self._excluded:
excluded.append(str(ex).replace("/", "\\"))
self._excluded = excluded
# windows paths for included files
included = []
for inc in self._included:
included.append(str(inc).replace("/", "\\"))
self._included = included
@property @property
def project_type(self): def project_type(self):

View File

@ -12,26 +12,59 @@ from cpl_core.console.foreground_color_enum import ForegroundColorEnum
class ProjectSettings(ConfigurationModelABC): class ProjectSettings(ConfigurationModelABC):
def __init__(self): def __init__(
self,
name: str = None,
version: VersionSettings = None,
author: str = None,
author_email: str = None,
description: str = None,
long_description: str = None,
url: str = None,
copyright_date: str = None,
copyright_name: str = None,
license_name: str = None,
license_description: str = None,
dependencies: list = None,
dev_dependencies: list = None,
python_version: str = None,
python_path: dict = None,
python_executable: str = None,
classifiers: list = None,
):
ConfigurationModelABC.__init__(self) ConfigurationModelABC.__init__(self)
self._name: Optional[str] = None self._name: Optional[str] = name
self._version: Optional[VersionSettings] = VersionSettings() self._version: Optional[VersionSettings] = version
self._author: Optional[str] = None self._author: Optional[str] = author
self._author_email: Optional[str] = None self._author_email: Optional[str] = author_email
self._description: Optional[str] = None self._description: Optional[str] = description
self._long_description: Optional[str] = None self._long_description: Optional[str] = long_description
self._url: Optional[str] = None self._url: Optional[str] = url
self._copyright_date: Optional[str] = None self._copyright_date: Optional[str] = copyright_date
self._copyright_name: Optional[str] = None self._copyright_name: Optional[str] = copyright_name
self._license_name: Optional[str] = None self._license_name: Optional[str] = license_name
self._license_description: Optional[str] = None self._license_description: Optional[str] = license_description
self._dependencies: Optional[list[str]] = None self._dependencies: Optional[list[str]] = [] if dependencies is None else dependencies
self._dev_dependencies: Optional[list[str]] = None self._dev_dependencies: Optional[list[str]] = [] if dev_dependencies is None else dev_dependencies
self._python_version: Optional[str] = None self._python_version: Optional[str] = python_version
self._python_path: Optional[str] = None self._python_path: Optional[str] = python_path
self._python_executable: Optional[str] = None self._python_executable: Optional[str] = python_executable
self._classifiers: Optional[list[str]] = None self._classifiers: Optional[list[str]] = [] if classifiers is None else classifiers
if python_path is not None:
path = f"{python_path[sys.platform]}"
if path == "" or path is None:
Error.warn(f"{ProjectSettingsNameEnum.python_path.value} not set")
path = sys.executable
else:
if not path.endswith("bin/python"):
path = os.path.join(path, "bin/python")
else:
path = sys.executable
self._python_executable = path
@property @property
def name(self): def name(self):

View File

@ -10,7 +10,7 @@ class VersionSettings(ConfigurationModelABC):
self._major: Optional[str] = major self._major: Optional[str] = major
self._minor: Optional[str] = minor self._minor: Optional[str] = minor
self._micro: Optional[str] = micro self._micro: Optional[str] = micro if micro != "" else None
@property @property
def major(self) -> str: def major(self) -> str:
@ -30,13 +30,6 @@ class VersionSettings(ConfigurationModelABC):
else: else:
return f"{self._major}.{self._minor}.{self._micro}" return f"{self._major}.{self._minor}.{self._micro}"
def from_dict(self, settings: dict):
self._major = settings[VersionSettingsNameEnum.major.value]
self._minor = settings[VersionSettingsNameEnum.minor.value]
micro = settings[VersionSettingsNameEnum.micro.value]
if micro != "":
self._micro = micro
def to_dict(self) -> dict: def to_dict(self) -> dict:
version = { version = {
VersionSettingsNameEnum.major.value: self._major, VersionSettingsNameEnum.major.value: self._major,

View File

@ -1,18 +1,23 @@
import traceback import traceback
from typing import Optional from typing import Optional
from cpl_cli.configuration.workspace_settings_name_enum import WorkspaceSettingsNameEnum
from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC
from cpl_core.console import Console from cpl_core.console import Console
from cpl_cli.configuration.workspace_settings_name_enum import WorkspaceSettingsNameEnum
class WorkspaceSettings(ConfigurationModelABC): class WorkspaceSettings(ConfigurationModelABC):
def __init__(self): def __init__(
self,
default_project: str = None,
projects: dict = None,
scripts: dict = None,
):
ConfigurationModelABC.__init__(self) ConfigurationModelABC.__init__(self)
self._default_project: Optional[str] = None self._default_project: Optional[str] = default_project
self._projects: dict[str, str] = {} self._projects: dict[str, str] = {} if projects is None else projects
self._scripts: dict[str, str] = {} self._scripts: dict[str, str] = {} if scripts is None else scripts
@property @property
def default_project(self) -> str: def default_project(self) -> str:
@ -25,16 +30,3 @@ class WorkspaceSettings(ConfigurationModelABC):
@property @property
def scripts(self): def scripts(self):
return self._scripts return self._scripts
def from_dict(self, settings: dict):
try:
self._default_project = settings[WorkspaceSettingsNameEnum.default_project.value]
self._projects = settings[WorkspaceSettingsNameEnum.projects.value]
if WorkspaceSettingsNameEnum.scripts.value in settings:
self._scripts = settings[WorkspaceSettingsNameEnum.scripts.value]
else:
self._scripts = {}
except Exception as e:
Console.error(f"[ ERROR ] [ {__name__} ]: Reading error in {type(self).__name__} settings")
Console.error(f"[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}")

View File

@ -290,6 +290,7 @@ class Configuration(ConfigurationABC):
Console.color_reset() Console.color_reset()
configuration.from_dict(value) configuration.from_dict(value)
else: else:
Console.error(sub, 1)
configuration = JSONProcessor.process(sub, value) configuration = JSONProcessor.process(sub, value)
self.add_configuration(sub, configuration) self.add_configuration(sub, configuration)

View File

@ -65,36 +65,3 @@ class DatabaseSettings(ConfigurationModelABC):
@property @property
def auth_plugin(self) -> Optional[str]: def auth_plugin(self) -> Optional[str]:
return self._auth_plugin return self._auth_plugin
# def from_dict(self, settings: dict):
# r"""Sets attributes from given dict
#
# Parameter:
# settings: :class:`dict`
# """
# try:
# self._host = settings[DatabaseSettingsNameEnum.host.value]
# if DatabaseSettingsNameEnum.port.value in settings:
# self._port = settings[DatabaseSettingsNameEnum.port.value]
# else:
# self._port = 3306
# self._user = settings[DatabaseSettingsNameEnum.user.value]
# self._password = settings[DatabaseSettingsNameEnum.password.value]
# self._databse = settings[DatabaseSettingsNameEnum.database.value]
#
# if DatabaseSettingsNameEnum.charset.value in settings:
# self._charset = settings[DatabaseSettingsNameEnum.charset.value]
#
# if DatabaseSettingsNameEnum.buffered.value in settings:
# self._use_unicode = bool(settings[DatabaseSettingsNameEnum.use_unicode.value])
#
# if DatabaseSettingsNameEnum.buffered.value in settings:
# self._buffered = bool(settings[DatabaseSettingsNameEnum.buffered.value])
#
# if DatabaseSettingsNameEnum.auth_plugin.value in settings:
# self._auth_plugin = settings[DatabaseSettingsNameEnum.auth_plugin.value]
# except Exception as e:
# Console.set_foreground_color(ForegroundColorEnum.red)
# Console.write_line(f"[ ERROR ] [ {__name__} ]: Reading error in {type(self).__name__} settings")
# Console.write_line(f"[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}")
# Console.set_foreground_color(ForegroundColorEnum.default)

View File

@ -55,15 +55,3 @@ class LoggingSettings(ConfigurationModelABC):
@level.setter @level.setter
def level(self, level: LoggingLevelEnum) -> None: def level(self, level: LoggingLevelEnum) -> None:
self._level = level self._level = level
# def from_dict(self, settings: dict):
# try:
# 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(ForegroundColorEnum.red)
# Console.write_line(f"[ ERROR ] [ {__name__} ]: Reading error in {type(self).__name__} settings")
# Console.write_line(f"[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}")
# Console.set_foreground_color(ForegroundColorEnum.default)

View File

@ -49,13 +49,3 @@ class EMailClientSettings(ConfigurationModelABC):
@credentials.setter @credentials.setter
def credentials(self, credentials: str) -> None: def credentials(self, credentials: str) -> None:
self._credentials = credentials self._credentials = credentials
# def from_dict(self, settings: dict):
# try:
# 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 {type(self).__name__} settings")
# Console.error(f"[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}")

View File

@ -54,15 +54,3 @@ class TimeFormatSettings(ConfigurationModelABC):
@date_time_log_format.setter @date_time_log_format.setter
def date_time_log_format(self, date_time_now_format: str) -> None: def date_time_log_format(self, date_time_now_format: str) -> None:
self._date_time_log_format = date_time_now_format self._date_time_log_format = date_time_now_format
# def from_dict(self, settings: dict):
# try:
# 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(ForegroundColorEnum.red)
# Console.write_line(f"[ ERROR ] [ {__name__} ]: Reading error in {type(self).__name__} settings")
# Console.write_line(f"[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}")
# Console.set_foreground_color(ForegroundColorEnum.default)

View File

@ -24,8 +24,8 @@ class JSONProcessor:
else: else:
value = values[name_first_lower] value = values[name_first_lower]
if isinstance(value, dict): if isinstance(value, dict) and not issubclass(parameter.annotation, dict):
value = JSONProcessor.process(parameter.annotation, value) value = JSONProcessor.process(dict, value)
if issubclass(parameter.annotation, enum.Enum): if issubclass(parameter.annotation, enum.Enum):
value = parameter.annotation[value] value = parameter.annotation[value]