2021-04-07 18:19:34 +02:00
|
|
|
import traceback
|
|
|
|
from typing import Optional
|
|
|
|
|
2021-08-05 14:21:42 +02:00
|
|
|
from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC
|
|
|
|
from cpl_core.console import Console
|
2021-04-07 18:19:34 +02:00
|
|
|
from cpl_cli.configuration.workspace_settings_name_enum import WorkspaceSettingsNameEnum
|
|
|
|
|
|
|
|
|
|
|
|
class WorkspaceSettings(ConfigurationModelABC):
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
ConfigurationModelABC.__init__(self)
|
|
|
|
|
|
|
|
self._default_project: Optional[str] = None
|
|
|
|
self._projects: dict[str, str] = {}
|
2021-07-24 17:24:01 +02:00
|
|
|
self._scripts: dict[str, str] = {}
|
2021-04-07 18:19:34 +02:00
|
|
|
|
|
|
|
@property
|
|
|
|
def default_project(self) -> str:
|
|
|
|
return self._default_project
|
|
|
|
|
|
|
|
@property
|
|
|
|
def projects(self) -> dict[str, str]:
|
|
|
|
return self._projects
|
|
|
|
|
2021-07-24 17:24:01 +02:00
|
|
|
@property
|
|
|
|
def scripts(self):
|
|
|
|
return self._scripts
|
|
|
|
|
2021-04-07 18:19:34 +02:00
|
|
|
def from_dict(self, settings: dict):
|
|
|
|
try:
|
|
|
|
self._default_project = settings[WorkspaceSettingsNameEnum.default_project.value]
|
|
|
|
self._projects = settings[WorkspaceSettingsNameEnum.projects.value]
|
2021-08-05 14:02:00 +02:00
|
|
|
|
|
|
|
if WorkspaceSettingsNameEnum.scripts.value in settings:
|
|
|
|
self._scripts = settings[WorkspaceSettingsNameEnum.scripts.value]
|
|
|
|
else:
|
|
|
|
self._scripts = {}
|
2021-04-07 18:19:34 +02:00
|
|
|
except Exception as e:
|
|
|
|
Console.error(f'[ ERROR ] [ {__name__} ]: Reading error in {self.__name__} settings')
|
|
|
|
Console.error(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}')
|