Compare commits
2 Commits
2025.10.19
...
mail_queue
| Author | SHA1 | Date | |
|---|---|---|---|
| 761f4f2103 | |||
| dfbb0a8c1f |
@@ -3,7 +3,8 @@
|
||||
"projects": [
|
||||
"src/cli/cpl.project.json",
|
||||
"src/core/cpl.project.json",
|
||||
"src/mail/cpl.project.json"
|
||||
"src/mail/cpl.project.json",
|
||||
"src/mail-queue/cpl.project.json"
|
||||
],
|
||||
"defaultProject": "cpl-cli",
|
||||
"scripts": {
|
||||
|
||||
@@ -11,12 +11,16 @@ T = TypeVar("T", bound="CPLStructureModel")
|
||||
|
||||
|
||||
class CPLStructureModel:
|
||||
def __init__(self, path: Optional[str] = None):
|
||||
self.__path = path
|
||||
def __init__(self, path: Optional[str] = None, ignore_fields: Optional[List[str]] = None):
|
||||
self._path = path
|
||||
|
||||
self._ignore = {"_ignore", "_path"}
|
||||
if ignore_fields is not None:
|
||||
self._ignore.update(ignore_fields)
|
||||
|
||||
@property
|
||||
def path(self) -> Optional[str]:
|
||||
return self.__path
|
||||
return self._path
|
||||
|
||||
@classmethod
|
||||
def from_file(cls: Type[T], path: Path | str) -> T:
|
||||
@@ -68,7 +72,7 @@ class CPLStructureModel:
|
||||
def to_json(self) -> Dict[str, Any]:
|
||||
result: Dict[str, Any] = {}
|
||||
for key, value in self.__dict__.items():
|
||||
if not key.startswith("_") or key.startswith("__") or key.endswith("_"):
|
||||
if not key.startswith("_") or key in self._ignore:
|
||||
continue
|
||||
out_key = _self_or_cls_snake_to_camel(key[1:])
|
||||
|
||||
@@ -79,13 +83,13 @@ class CPLStructureModel:
|
||||
return result
|
||||
|
||||
def save(self):
|
||||
if not self.__path:
|
||||
if not self._path:
|
||||
raise ValueError("Cannot save model without a path.")
|
||||
|
||||
if not Path(self.__path).exists():
|
||||
os.makedirs(Path(self.__path).parent, exist_ok=True)
|
||||
if not Path(self._path).exists():
|
||||
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)
|
||||
|
||||
@staticmethod
|
||||
|
||||
@@ -24,23 +24,23 @@ class Workspace(CPLStructureModel):
|
||||
default_project: Optional[str],
|
||||
scripts: Dict[str, str],
|
||||
):
|
||||
CPLStructureModel.__init__(self, path)
|
||||
CPLStructureModel.__init__(self, path, ["_actual_projects", "_project_names"])
|
||||
|
||||
self._name = name
|
||||
self._projects = projects
|
||||
self._default_project = default_project
|
||||
|
||||
self.__actual_projects = []
|
||||
self.__project_names = []
|
||||
self._actual_projects = []
|
||||
self._project_names = []
|
||||
for project in projects:
|
||||
if Path(project).is_dir() or not Path(project).exists():
|
||||
raise ValueError(f"Project path '{project}' does not exist or is a directory.")
|
||||
|
||||
p = Project.from_file(project)
|
||||
self.__actual_projects.append(p)
|
||||
self.__project_names.append(p.name)
|
||||
self._actual_projects.append(p)
|
||||
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.")
|
||||
|
||||
self._scripts = scripts
|
||||
@@ -63,11 +63,11 @@ class Workspace(CPLStructureModel):
|
||||
|
||||
@property
|
||||
def actual_projects(self) -> List[Project]:
|
||||
return self.__actual_projects
|
||||
return self._actual_projects
|
||||
|
||||
@property
|
||||
def project_names(self) -> List[str]:
|
||||
return self.__project_names
|
||||
return self._project_names
|
||||
|
||||
@property
|
||||
def default_project(self) -> Optional[str]:
|
||||
|
||||
3
src/mail-queue/class.py
Normal file
3
src/mail-queue/class.py
Normal file
@@ -0,0 +1,3 @@
|
||||
class Class1:
|
||||
|
||||
def __init__(self): ...
|
||||
24
src/mail-queue/cpl.project.json
Normal file
24
src/mail-queue/cpl.project.json
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"name": "mail-queue",
|
||||
"version": "0.1.0",
|
||||
"type": "library",
|
||||
"license": "",
|
||||
"author": "",
|
||||
"description": "",
|
||||
"homepage": "",
|
||||
"keywords": [],
|
||||
"dependencies": {
|
||||
"cpl-core": "~2024.7.0",
|
||||
"cpl-mail": "~2024.7.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"cpl-cli": ">2024.7.0"
|
||||
},
|
||||
"references": [],
|
||||
"main": null,
|
||||
"directory": "./",
|
||||
"build": {
|
||||
"include": [],
|
||||
"exclude": []
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user