def _get_drive_usage(path):
"""
Use Python libraries to get drive space/usage statistics. Prior to v3.3, use `os.statvfs`;
on v3.3+, use the more accurate `shutil.disk_usage`.
"""
if sys.version_info >= (3, 3):
usage = shutil.disk_usage(path)
return {
"total": usage.total,
"used": usage.used,
"free": usage.free,
}
else:
# with os.statvfs, we need to multiple block sizes by block counts to get bytes
stats = os.statvfs(path)
total = stats.f_frsize * stats.f_blocks
free = stats.f_frsize * stats.f_bavail
return {
"total": total,
"free": free,
"used": total - free,
}
评论列表
文章目录