From bcab9b34d693ecfba735fa0eb95205c2f8ac2df2 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Wed, 19 Jan 2022 19:23:11 -0800 Subject: [PATCH] Add Path.assert_disk_space. --- voussoirkit/pathclass.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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)