kopia lustrzana https://github.com/micropython/micropython-lib
shutil: Add disk_usage function.
Signed-off-by: Patrick Joy <patrick@joytech.com.au>pull/571/head
rodzic
c26d77b52e
commit
a14226f7c5
|
@ -1,3 +1,3 @@
|
||||||
metadata(version="0.0.3")
|
metadata(version="0.0.4")
|
||||||
|
|
||||||
module("shutil.py")
|
module("shutil.py")
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
# Reimplement, because CPython3.3 impl is rather bloated
|
# Reimplement, because CPython3.3 impl is rather bloated
|
||||||
import os
|
import os
|
||||||
|
from collections import namedtuple
|
||||||
|
|
||||||
|
_ntuple_diskusage = namedtuple("usage", ("total", "used", "free"))
|
||||||
|
|
||||||
|
|
||||||
def rmtree(top):
|
def rmtree(top):
|
||||||
|
@ -27,3 +30,13 @@ def copyfileobj(src, dest, length=512):
|
||||||
if not buf:
|
if not buf:
|
||||||
break
|
break
|
||||||
dest.write(buf)
|
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)
|
||||||
|
|
Ładowanie…
Reference in New Issue