added support for btrfs free space readout
This commit is contained in:
parent
22600d3b31
commit
79b47e1130
1 changed files with 23 additions and 8 deletions
|
@ -313,7 +313,10 @@ def command(cmd):
|
|||
Executes a command, returns stdout, suppresses stderr."
|
||||
"""
|
||||
|
||||
s = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
if type(cmd) == str:
|
||||
cmd = cmd.split()
|
||||
|
||||
s = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
s.wait()
|
||||
|
||||
return s.stdout.read().decode("utf-8")
|
||||
|
@ -549,7 +552,7 @@ class StatsPart(Part):
|
|||
if "rw" not in options.split(","):
|
||||
continue
|
||||
|
||||
# /proc/self/mounts uses a literal \\040 string to escape spaces
|
||||
# /proc/self/mounts uses a literal \040 string to escape spaces
|
||||
dir = dir.replace("\\040", " ")
|
||||
|
||||
basename = os.path.basename(dir)
|
||||
|
@ -565,13 +568,25 @@ class StatsPart(Part):
|
|||
else:
|
||||
short_name = " /"
|
||||
|
||||
try:
|
||||
stat = os.statvfs(dir)
|
||||
except PermissionError:
|
||||
continue
|
||||
# handle btrfs separately
|
||||
if type == "btrfs":
|
||||
btrfs_raw = command(["/sbin/btrfs", "fi", "usage", "-b", dir])
|
||||
|
||||
for line in btrfs_raw.split("\n"):
|
||||
if "Device size" in line:
|
||||
stor_total = int(line.split()[-1])
|
||||
elif "Free" in line:
|
||||
stor_free = int(line.split()[-3])
|
||||
break
|
||||
|
||||
stor_total = stat.f_blocks * stat.f_bsize
|
||||
stor_free = stat.f_bavail * stat.f_bsize
|
||||
else:
|
||||
try:
|
||||
stat = os.statvfs(dir)
|
||||
except PermissionError:
|
||||
continue
|
||||
|
||||
stor_total = stat.f_blocks * stat.f_bsize
|
||||
stor_free = stat.f_bavail * stat.f_bsize
|
||||
|
||||
# ignore virtual filesystems
|
||||
if stor_total == 0:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue