From 731749f0e3fd535c633ed373ab7e17b86e1e8000 Mon Sep 17 00:00:00 2001 From: Douglas Eddie Date: Tue, 24 Nov 2015 22:51:01 +0000 Subject: [PATCH] Added check for ismount() and empty directories. Previously the free space of the underlying filesystem would be reported if the path provided was a directory but not a valid mountpoint. This adds a check to first confirm whether a directory is a mountpoint using os.path.ismount(), and if not, then runs an os.listdir() to count the files; empty directories are considered not mounted. This functionality allows for usage on setups with NFS and will not report free space of underlying filesystem in cases with local mountpoints as path. --- i3pystatus/disk.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/i3pystatus/disk.py b/i3pystatus/disk.py index 8623da1..5b131ac 100644 --- a/i3pystatus/disk.py +++ b/i3pystatus/disk.py @@ -37,17 +37,25 @@ class Disk(IntervalModule): round_size = 2 mounted_only = False + def not_mounted(self): + if self.mounted_only: + self.output = {} + else: + self.output = {} if not self.format_not_mounted else { + "full_text": self.format_not_mounted, + "color": self.color_not_mounted, + } + def run(self): + if os.path.isdir(self.path) and not os.path.ismount(self.path): + if len(os.listdir(self.path)) == 0: + self.not_mounted() + return + try: stat = os.statvfs(self.path) except Exception: - if self.mounted_only: - self.output = {} - else: - self.output = {} if not self.format_not_mounted else { - "full_text": self.format_not_mounted, - "color": self.color_not_mounted, - } + self.not_mounted() return available = (stat.f_bsize * stat.f_bavail) / self.divisor