Updated cpl structure model json handling
All checks were successful
Test before pr merge / test-lint (pull_request) Successful in 7s
Build on push / prepare (push) Successful in 10s
Build on push / query (push) Successful in 19s
Build on push / core (push) Successful in 23s
Build on push / dependency (push) Successful in 18s
Build on push / cli (push) Successful in 25s
Build on push / mail (push) Successful in 17s
Build on push / application (push) Successful in 21s
Build on push / database (push) Successful in 20s
Build on push / translation (push) Successful in 20s
Build on push / auth (push) Successful in 18s
Build on push / api (push) Successful in 15s
All checks were successful
Test before pr merge / test-lint (pull_request) Successful in 7s
Build on push / prepare (push) Successful in 10s
Build on push / query (push) Successful in 19s
Build on push / core (push) Successful in 23s
Build on push / dependency (push) Successful in 18s
Build on push / cli (push) Successful in 25s
Build on push / mail (push) Successful in 17s
Build on push / application (push) Successful in 21s
Build on push / database (push) Successful in 20s
Build on push / translation (push) Successful in 20s
Build on push / auth (push) Successful in 18s
Build on push / api (push) Successful in 15s
This commit is contained in:
@@ -12,11 +12,11 @@ T = TypeVar("T", bound="CPLStructureModel")
|
|||||||
|
|
||||||
class CPLStructureModel:
|
class CPLStructureModel:
|
||||||
def __init__(self, path: Optional[str] = None):
|
def __init__(self, path: Optional[str] = None):
|
||||||
self._path = path
|
self.__path = path
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def path(self) -> Optional[str]:
|
def path(self) -> Optional[str]:
|
||||||
return self._path
|
return self.__path
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_file(cls: Type[T], path: Path | str) -> T:
|
def from_file(cls: Type[T], path: Path | str) -> T:
|
||||||
@@ -68,7 +68,7 @@ class CPLStructureModel:
|
|||||||
def to_json(self) -> Dict[str, Any]:
|
def to_json(self) -> Dict[str, Any]:
|
||||||
result: Dict[str, Any] = {}
|
result: Dict[str, Any] = {}
|
||||||
for key, value in self.__dict__.items():
|
for key, value in self.__dict__.items():
|
||||||
if not key.startswith("_") or key == "_path":
|
if not key.startswith("_") or key.startswith("__") or key.endswith("_"):
|
||||||
continue
|
continue
|
||||||
out_key = _self_or_cls_snake_to_camel(key[1:])
|
out_key = _self_or_cls_snake_to_camel(key[1:])
|
||||||
|
|
||||||
@@ -79,13 +79,13 @@ class CPLStructureModel:
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
if not self._path:
|
if not self.__path:
|
||||||
raise ValueError("Cannot save model without a path.")
|
raise ValueError("Cannot save model without a path.")
|
||||||
|
|
||||||
if not Path(self._path).exists():
|
if not Path(self.__path).exists():
|
||||||
os.makedirs(Path(self._path).parent, exist_ok=True)
|
os.makedirs(Path(self.__path).parent, exist_ok=True)
|
||||||
|
|
||||||
with open(self._path, "w", encoding="utf-8") as f:
|
with open(self.__path, "w", encoding="utf-8") as f:
|
||||||
json.dump(self.to_json(), f, indent=2)
|
json.dump(self.to_json(), f, indent=2)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
@@ -30,17 +30,17 @@ class Workspace(CPLStructureModel):
|
|||||||
self._projects = projects
|
self._projects = projects
|
||||||
self._default_project = default_project
|
self._default_project = default_project
|
||||||
|
|
||||||
self._actual_projects = []
|
self.__actual_projects = []
|
||||||
self._project_names = []
|
self.__project_names = []
|
||||||
for project in projects:
|
for project in projects:
|
||||||
if Path(project).is_dir() or not Path(project).exists():
|
if Path(project).is_dir() or not Path(project).exists():
|
||||||
raise ValueError(f"Project path '{project}' does not exist or is a directory.")
|
raise ValueError(f"Project path '{project}' does not exist or is a directory.")
|
||||||
|
|
||||||
p = Project.from_file(project)
|
p = Project.from_file(project)
|
||||||
self._actual_projects.append(p)
|
self.__actual_projects.append(p)
|
||||||
self._project_names.append(p.name)
|
self.__project_names.append(p.name)
|
||||||
|
|
||||||
if default_project is not None and default_project not in self._project_names:
|
if default_project is not None and default_project not in self.__project_names:
|
||||||
raise ValueError(f"Default project '{default_project}' not found in workspace projects.")
|
raise ValueError(f"Default project '{default_project}' not found in workspace projects.")
|
||||||
|
|
||||||
self._scripts = scripts
|
self._scripts = scripts
|
||||||
@@ -63,11 +63,11 @@ class Workspace(CPLStructureModel):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def actual_projects(self) -> List[Project]:
|
def actual_projects(self) -> List[Project]:
|
||||||
return self._actual_projects
|
return self.__actual_projects
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def project_names(self) -> List[str]:
|
def project_names(self) -> List[str]:
|
||||||
return self._project_names
|
return self.__project_names
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def default_project(self) -> Optional[str]:
|
def default_project(self) -> Optional[str]:
|
||||||
|
|||||||
Reference in New Issue
Block a user