diff --git a/python-stdlib/shutil/manifest.py b/python-stdlib/shutil/manifest.py index 385d50ad..d5d597f3 100644 --- a/python-stdlib/shutil/manifest.py +++ b/python-stdlib/shutil/manifest.py @@ -1,3 +1,3 @@ -metadata(version="0.0.3") +metadata(version="0.0.4") module("shutil.py") diff --git a/python-stdlib/shutil/shutil.py b/python-stdlib/shutil/shutil.py index 2a02a7cd..e4841125 100644 --- a/python-stdlib/shutil/shutil.py +++ b/python-stdlib/shutil/shutil.py @@ -1,5 +1,8 @@ # Reimplement, because CPython3.3 impl is rather bloated import os +from collections import namedtuple + +_ntuple_diskusage = namedtuple("usage", ("total", "used", "free")) def rmtree(top): @@ -27,3 +30,13 @@ def copyfileobj(src, dest, length=512): if not buf: break dest.write(buf) + + +def disk_usage(path): + bit_tuple = os.statvfs(path) + blksize = bit_tuple[0] # system block size + total = bit_tuple[2] * blksize + free = bit_tuple[3] * blksize + used = total - free + + return _ntuple_diskusage(total, used, free)