aboutsummaryrefslogtreecommitdiff
path: root/tools/cru-py/cru/_path.py
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2024-11-11 01:12:29 +0800
committerYuqian Yang <crupest@crupest.life>2024-12-18 18:31:27 +0800
commit7692763f83ad1be735b0b9e9ab0af8ce666d8de8 (patch)
treeb45e6cb4312b050ac4e1ccf51106d44af9201b40 /tools/cru-py/cru/_path.py
parent297beaf0fedd297dde6d665bd13c929b95b3d1c4 (diff)
downloadcrupest-7692763f83ad1be735b0b9e9ab0af8ce666d8de8.tar.gz
crupest-7692763f83ad1be735b0b9e9ab0af8ce666d8de8.tar.bz2
crupest-7692763f83ad1be735b0b9e9ab0af8ce666d8de8.zip
HALF WORK: 2024.12.17
Diffstat (limited to 'tools/cru-py/cru/_path.py')
-rw-r--r--tools/cru-py/cru/_path.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/tools/cru-py/cru/_path.py b/tools/cru-py/cru/_path.py
new file mode 100644
index 0000000..a131c41
--- /dev/null
+++ b/tools/cru-py/cru/_path.py
@@ -0,0 +1,23 @@
+from pathlib import Path
+
+from ._error import CruException
+
+
+class CruPathError(CruException):
+ def __init__(self, message, _path: Path, *args, **kwargs):
+ super().__init__(message, *args, **kwargs)
+ self._path = _path
+
+ @property
+ def path(self) -> Path:
+ return self._path
+
+
+class CruPath(Path):
+ def check_parents_dir(self, must_exist: bool = False) -> bool:
+ for p in reversed(self.parents):
+ if not p.exists() and not must_exist:
+ return False
+ if not p.is_dir():
+ raise CruPathError("Parents path must be a dir.", self)
+ return True