shutil: Add disk_usage function.

Signed-off-by: Patrick Joy <patrick@joytech.com.au>
pull/571/head
Patrick Joy 2022-11-09 13:51:03 +11:00 zatwierdzone przez Damien George
rodzic c26d77b52e
commit a14226f7c5
2 zmienionych plików z 14 dodań i 1 usunięć

Wyświetl plik

@ -1,3 +1,3 @@
metadata(version="0.0.3")
metadata(version="0.0.4")
module("shutil.py")

Wyświetl plik

@ -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)