8000 shutil: Add disk_usage function. · micropython/micropython-lib@a14226f · GitHub
[go: up one dir, main page]

Skip to content

Commit a14226f

Browse files
ThinkTransitdpgeorge
authored andcommitted
shutil: Add disk_usage function.
Signed-off-by: Patrick Joy <patrick@joytech.com.au>
1 parent c26d77b commit a14226f

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

python-stdlib/shutil/manifest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
metadata(version="0.0.3")
1+
metadata(version="0.0.4")
22

33
module("shutil.py")

python-stdlib/shutil/shutil.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Reimplement, because CPython3.3 impl is rather bloated
22
import os
3+
from collections import namedtuple
4+
5+
_ntuple_diskusage = namedtuple("usage", ("total", "used", "free"))
36

47

58
def rmtree(top):
@@ -27,3 +30,13 @@ def copyfileobj(src, dest, length=512):
2730
if not buf:
2831
break
2932
dest.write(buf)
33+
34+
35+
def disk_usage(path):
36+
bit_tuple = os.statvfs(path)
37+
blksize = bit_tuple[0] # system block size
38+
total = bit_tuple[2] * blksize
39+
free = bit_tuple[3] * blksize
40+
used = total - free
41+
42+
return _ntuple_diskusage(total, used, free)

0 commit comments

Comments
 (0)
0