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
commit7b4d49e4bbdff6ddf1f8f7e937130e700024d5e9 (patch)
treeb45e6cb4312b050ac4e1ccf51106d44af9201b40 /tools/cru-py/cru/_path.py
parentca88aee42b741110d42683db826caf61b642abea (diff)
downloadcrupest-7b4d49e4bbdff6ddf1f8f7e937130e700024d5e9.tar.gz
crupest-7b4d49e4bbdff6ddf1f8f7e937130e700024d5e9.tar.bz2
crupest-7b4d49e4bbdff6ddf1f8f7e937130e700024d5e9.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