diff --git a/libexec/render.py b/libexec/render.py index 11cfe68..1d62353 100755 --- a/libexec/render.py +++ b/libexec/render.py @@ -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: