diff --git a/voussoirkit/pathclass.py b/voussoirkit/pathclass.py index 341bde3..d6d5c39 100644 --- a/voussoirkit/pathclass.py +++ b/voussoirkit/pathclass.py @@ -1,5 +1,6 @@ import glob import os +import shutil _glob = glob @@ -41,6 +42,13 @@ class NotDirectory(PathclassException): class NotExists(PathclassException): pass + +class NotEnoughSpace(PathclassException): + def __init__(self, free, reserve, path): + self.free = free + self.reserve = reserve + self.path = path + class NotFile(PathclassException): pass @@ -207,6 +215,12 @@ class Path: self._absolute_path = absolute return self._absolute_path + def assert_disk_space(self, reserve): + free = shutil.disk_usage(self).free + if free < reserve: + raise NotEnoughSpace(path=self, reserve=reserve, free=free) + return free + def assert_exists(self): if not self.exists: raise NotExists(self)