blob: a131c41931e1187564c759078dcc305e41d5bc82 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
|