added support for btrfs free space readout

This commit is contained in:
Martinez 2016-10-03 15:05:46 +02:00
parent 22600d3b31
commit 79b47e1130

View file

@ -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,6 +568,18 @@ class StatsPart(Part):
else:
short_name = " /"
# 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
else:
try:
stat = os.statvfs(dir)
except PermissionError: