Skip to content

Commit 31507e6

Browse files
committed
feat: adding path support for disk storage display
1 parent 25acaab commit 31507e6

File tree

6 files changed

+29
-25
lines changed

6 files changed

+29
-25
lines changed

library/sensors/sensors.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,17 @@ def virtual_free() -> int: # In bytes
105105
class Disk(ABC):
106106
@staticmethod
107107
@abstractmethod
108-
def disk_usage_percent() -> float:
108+
def disk_usage_percent(path: str = "/") -> float:
109109
pass
110110

111111
@staticmethod
112112
@abstractmethod
113-
def disk_used() -> int: # In bytes
113+
def disk_used(path: str = "/") -> int: # In bytes
114114
pass
115115

116116
@staticmethod
117117
@abstractmethod
118-
def disk_free() -> int: # In bytes
118+
def disk_free(path: str = "/") -> int: # In bytes
119119
pass
120120

121121

library/sensors/sensors_librehardwaremonitor.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -450,16 +450,16 @@ def virtual_free() -> int: # In bytes
450450
# This is because LHM is a hardware-oriented library, whereas used/free/total space is for partitions, not disks
451451
class Disk(sensors.Disk):
452452
@staticmethod
453-
def disk_usage_percent() -> float:
454-
return psutil.disk_usage("/").percent
453+
def disk_usage_percent(path: str = "/") -> float:
454+
return psutil.disk_usage(path).percent
455455

456456
@staticmethod
457-
def disk_used() -> int: # In bytes
458-
return psutil.disk_usage("/").used
457+
def disk_used(path: str = "/") -> int: # In bytes
458+
return psutil.disk_usage(path).used
459459

460460
@staticmethod
461-
def disk_free() -> int: # In bytes
462-
return psutil.disk_usage("/").free
461+
def disk_free(path: str = "/") -> int: # In bytes
462+
return psutil.disk_usage(path).free
463463

464464

465465
class Net(sensors.Net):

library/sensors/sensors_python.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -453,23 +453,23 @@ def virtual_free() -> int: # In bytes
453453

454454
class Disk(sensors.Disk):
455455
@staticmethod
456-
def disk_usage_percent() -> float:
456+
def disk_usage_percent(path: str = "/") -> float:
457457
try:
458-
return psutil.disk_usage("/").percent
458+
return psutil.disk_usage(path).percent
459459
except:
460460
return math.nan
461461

462462
@staticmethod
463-
def disk_used() -> int: # In bytes
463+
def disk_used(path: str = "/") -> int: # In bytes
464464
try:
465-
return psutil.disk_usage("/").used
465+
return psutil.disk_usage(path).used
466466
except:
467467
return -1
468468

469469
@staticmethod
470-
def disk_free() -> int: # In bytes
470+
def disk_free(path: str = "/") -> int: # In bytes
471471
try:
472-
return psutil.disk_usage("/").free
472+
return psutil.disk_usage(path).free
473473
except:
474474
return -1
475475

library/sensors/sensors_stub_random.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@ def virtual_free() -> int: # In bytes
9393

9494
class Disk(sensors.Disk):
9595
@staticmethod
96-
def disk_usage_percent() -> float:
96+
def disk_usage_percent(path: str = "/") -> float:
9797
return random.uniform(0, 100)
9898

9999
@staticmethod
100-
def disk_used() -> int: # In bytes
100+
def disk_used(path: str = "/") -> int: # In bytes
101101
return random.randint(1000000000, 2000000000000)
102102

103103
@staticmethod
104-
def disk_free() -> int: # In bytes
104+
def disk_free(path: str = "/") -> int: # In bytes
105105
return random.randint(1000000000, 2000000000000)
106106

107107

library/sensors/sensors_stub_static.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,15 @@ def virtual_free() -> int: # In bytes
109109

110110
class Disk(sensors.Disk):
111111
@staticmethod
112-
def disk_usage_percent() -> float:
112+
def disk_usage_percent(path: str = "/") -> float:
113113
return PERCENTAGE_SENSOR_VALUE
114114

115115
@staticmethod
116-
def disk_used() -> int: # In bytes
116+
def disk_used(path: str = "/") -> int: # In bytes
117117
return int(DISK_TOTAL_SIZE_GB / 100 * PERCENTAGE_SENSOR_VALUE) * 1000000000
118118

119119
@staticmethod
120-
def disk_free() -> int: # In bytes
120+
def disk_free(path: str = "/") -> int: # In bytes
121121
return int(DISK_TOTAL_SIZE_GB / 100 * (100 - PERCENTAGE_SENSOR_VALUE)) * 1000000000
122122

123123

library/stats.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -647,12 +647,16 @@ class Disk:
647647

648648
@classmethod
649649
def stats(cls):
650-
used = sensors.Disk.disk_used()
651-
free = sensors.Disk.disk_free()
652-
653650
disk_theme_data = config.THEME_DATA['STATS']['DISK']
651+
652+
path = "/"
653+
if disk_theme_data['PATH'] is not None:
654+
path = disk_theme_data['PATH']
655+
656+
used = sensors.Disk.disk_used(path)
657+
free = sensors.Disk.disk_free(path)
654658

655-
disk_usage_percent = sensors.Disk.disk_usage_percent()
659+
disk_usage_percent = sensors.Disk.disk_usage_percent(path)
656660
save_last_value(disk_usage_percent, cls.last_values_disk_usage,
657661
disk_theme_data['USED']['LINE_GRAPH'].get("HISTORY_SIZE", DEFAULT_HISTORY_SIZE))
658662
display_themed_progress_bar(disk_theme_data['USED']['GRAPH'], disk_usage_percent)

0 commit comments

Comments
 (0)