Add Path.assert_disk_space.
This commit is contained in:
parent
77769aa2ef
commit
bcab9b34d6
1 changed files with 14 additions and 0 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue