Skip to content

Multiple disks support #224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions library/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def load_yaml(configfile):
PATH = sys.path[0]
CONFIG_DATA = load_yaml("config.yaml")
THEME_DEFAULT = load_yaml("res/themes/default.yaml")
THEME_DISK_DEFAULT = load_yaml("res/themes/default_disk.yaml")
THEME_DATA = None


Expand Down Expand Up @@ -64,6 +65,10 @@ def load_theme():

copy_default(THEME_DEFAULT, THEME_DATA)

if THEME_DATA['STATS']['DISK'].get("MOUNTS", False):
for mount in THEME_DATA['STATS']['DISK']['MOUNTS']:
mountpoint = [k for k, v in mount.items()][0]
copy_default(THEME_DISK_DEFAULT, mount[mountpoint])

# Load theme on import
load_theme()
Expand Down
6 changes: 3 additions & 3 deletions library/sensors/sensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,17 @@ def virtual_free() -> int: # In bytes
class Disk(ABC):
@staticmethod
@abstractmethod
def disk_usage_percent() -> float:
def disk_usage_percent(path) -> float:
pass

@staticmethod
@abstractmethod
def disk_used() -> int: # In bytes
def disk_used(path) -> int: # In bytes
pass

@staticmethod
@abstractmethod
def disk_free() -> int: # In bytes
def disk_free(path) -> int: # In bytes
pass


Expand Down
12 changes: 6 additions & 6 deletions library/sensors/sensors_librehardwaremonitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,16 +341,16 @@ def virtual_free() -> int: # In bytes
# This is because LHM is a hardware-oriented library, whereas used/free/total space is for partitions, not disks
class Disk(sensors.Disk):
@staticmethod
def disk_usage_percent() -> float:
return psutil.disk_usage("/").percent
def disk_usage_percent(path) -> float:
return psutil.disk_usage(path).percent

@staticmethod
def disk_used() -> int: # In bytes
return psutil.disk_usage("/").used
def disk_used(path) -> int: # In bytes
return psutil.disk_usage(path).used

@staticmethod
def disk_free() -> int: # In bytes
return psutil.disk_usage("/").free
def disk_free(path) -> int: # In bytes
return psutil.disk_usage(path).free


class Net(sensors.Net):
Expand Down
12 changes: 6 additions & 6 deletions library/sensors/sensors_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,16 +255,16 @@ def virtual_free() -> int: # In bytes

class Disk(sensors.Disk):
@staticmethod
def disk_usage_percent() -> float:
return psutil.disk_usage("/").percent
def disk_usage_percent(path) -> float:
return psutil.disk_usage(path).percent

@staticmethod
def disk_used() -> int: # In bytes
return psutil.disk_usage("/").used
def disk_used(path) -> int: # In bytes
return psutil.disk_usage(path).used

@staticmethod
def disk_free() -> int: # In bytes
return psutil.disk_usage("/").free
def disk_free(path) -> int: # In bytes
return psutil.disk_usage(path).free


class Net(sensors.Net):
Expand Down
6 changes: 3 additions & 3 deletions library/sensors/sensors_stub_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ def virtual_free() -> int: # In bytes

class Disk(sensors.Disk):
@staticmethod
def disk_usage_percent() -> float:
def disk_usage_percent(path) -> float:
return random.uniform(0, 100)

@staticmethod
def disk_used() -> int: # In bytes
def disk_used(path) -> int: # In bytes
return random.randint(1000000000, 2000000000000)

@staticmethod
def disk_free() -> int: # In bytes
def disk_free(path) -> int: # In bytes
return random.randint(1000000000, 2000000000000)


Expand Down
6 changes: 3 additions & 3 deletions library/sensors/sensors_stub_static.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ def virtual_free() -> int: # In bytes

class Disk(sensors.Disk):
@staticmethod
def disk_usage_percent() -> float:
def disk_usage_percent(path) -> float:
return PERCENTAGE_SENSOR_VALUE

@staticmethod
def disk_used() -> int: # In bytes
def disk_used(path) -> int: # In bytes
return int(DISK_TOTAL_SIZE_GB / 100 * PERCENTAGE_SENSOR_VALUE) * 1000000000

@staticmethod
def disk_free() -> int: # In bytes
def disk_free(path) -> int: # In bytes
return int(DISK_TOTAL_SIZE_GB / 100 * (100 - PERCENTAGE_SENSOR_VALUE)) * 1000000000


Expand Down
214 changes: 110 additions & 104 deletions library/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,110 +495,116 @@ def stats():
class Disk:
@staticmethod
def stats():
used = sensors.Disk.disk_used()
free = sensors.Disk.disk_free()
if config.THEME_DATA['STATS']['DISK']['USED']['GRAPH'].get("SHOW", False):
display.lcd.DisplayProgressBar(
x=config.THEME_DATA['STATS']['DISK']['USED']['GRAPH'].get("X", 0),
y=config.THEME_DATA['STATS']['DISK']['USED']['GRAPH'].get("Y", 0),
width=config.THEME_DATA['STATS']['DISK']['USED']['GRAPH'].get("WIDTH", 0),
height=config.THEME_DATA['STATS']['DISK']['USED']['GRAPH'].get("HEIGHT", 0),
value=int(sensors.Disk.disk_usage_percent()),
min_value=config.THEME_DATA['STATS']['DISK']['USED']['GRAPH'].get("MIN_VALUE", 0),
max_value=config.THEME_DATA['STATS']['DISK']['USED']['GRAPH'].get("MAX_VALUE", 100),
bar_color=config.THEME_DATA['STATS']['DISK']['USED']['GRAPH'].get("BAR_COLOR", (0, 0, 0)),
bar_outline=config.THEME_DATA['STATS']['DISK']['USED']['GRAPH'].get("BAR_OUTLINE", False),
background_color=config.THEME_DATA['STATS']['DISK']['USED']['GRAPH'].get("BACKGROUND_COLOR",
(255, 255, 255)),
background_image=get_full_path(config.THEME_DATA['PATH'],
config.THEME_DATA['STATS']['DISK']['USED']['GRAPH'].get(
"BACKGROUND_IMAGE",
None))
)

if config.THEME_DATA['STATS']['DISK']['USED']['TEXT'].get("SHOW", False):
used_text = f"{int(used / 1000000000):>5}"
if config.THEME_DATA['STATS']['DISK']['USED']['TEXT'].get("SHOW_UNIT", True):
used_text += " G"

display.lcd.DisplayText(
text=used_text,
x=config.THEME_DATA['STATS']['DISK']['USED']['TEXT'].get("X", 0),
y=config.THEME_DATA['STATS']['DISK']['USED']['TEXT'].get("Y", 0),
font=config.THEME_DATA['STATS']['DISK']['USED']['TEXT'].get("FONT",
"roboto-mono/RobotoMono-Regular.ttf"),
font_size=config.THEME_DATA['STATS']['DISK']['USED']['TEXT'].get("FONT_SIZE", 10),
font_color=config.THEME_DATA['STATS']['DISK']['USED']['TEXT'].get("FONT_COLOR", (0, 0, 0)),
background_color=config.THEME_DATA['STATS']['DISK']['USED']['TEXT'].get("BACKGROUND_COLOR",
(255, 255, 255)),
background_image=get_full_path(config.THEME_DATA['PATH'],
config.THEME_DATA['STATS']['DISK']['USED']['TEXT'].get(
"BACKGROUND_IMAGE",
None))
)

if config.THEME_DATA['STATS']['DISK']['USED']['PERCENT_TEXT'].get("SHOW", False):
percent_text = f"{int(sensors.Disk.disk_usage_percent()):>3}"
if config.THEME_DATA['STATS']['DISK']['USED']['PERCENT_TEXT'].get("SHOW_UNIT", True):
percent_text += "%"

display.lcd.DisplayText(
text=percent_text,
x=config.THEME_DATA['STATS']['DISK']['USED']['PERCENT_TEXT'].get("X", 0),
y=config.THEME_DATA['STATS']['DISK']['USED']['PERCENT_TEXT'].get("Y", 0),
font=config.THEME_DATA['STATS']['DISK']['USED']['PERCENT_TEXT'].get("FONT",
"roboto-mono/RobotoMono-Regular.ttf"),
font_size=config.THEME_DATA['STATS']['DISK']['USED']['PERCENT_TEXT'].get("FONT_SIZE", 10),
font_color=config.THEME_DATA['STATS']['DISK']['USED']['PERCENT_TEXT'].get("FONT_COLOR", (0, 0, 0)),
background_color=config.THEME_DATA['STATS']['DISK']['USED']['PERCENT_TEXT'].get("BACKGROUND_COLOR",
(255, 255, 255)),
background_image=get_full_path(config.THEME_DATA['PATH'],
config.THEME_DATA['STATS']['DISK']['USED']['PERCENT_TEXT'].get(
"BACKGROUND_IMAGE",
None))
)

if config.THEME_DATA['STATS']['DISK']['TOTAL']['TEXT'].get("SHOW", False):
total_text = f"{int((free + used) / 1000000000):>5}"
if config.THEME_DATA['STATS']['DISK']['TOTAL']['TEXT'].get("SHOW_UNIT", True):
total_text += " G"

display.lcd.DisplayText(
text=total_text,
x=config.THEME_DATA['STATS']['DISK']['TOTAL']['TEXT'].get("X", 0),
y=config.THEME_DATA['STATS']['DISK']['TOTAL']['TEXT'].get("Y", 0),
font=config.THEME_DATA['STATS']['DISK']['TOTAL']['TEXT'].get("FONT",
"roboto-mono/RobotoMono-Regular.ttf"),
font_size=config.THEME_DATA['STATS']['DISK']['TOTAL']['TEXT'].get("FONT_SIZE", 10),
font_color=config.THEME_DATA['STATS']['DISK']['TOTAL']['TEXT'].get("FONT_COLOR", (0, 0, 0)),
background_color=config.THEME_DATA['STATS']['DISK']['TOTAL']['TEXT'].get("BACKGROUND_COLOR",
(255, 255, 255)),
background_image=get_full_path(config.THEME_DATA['PATH'],
config.THEME_DATA['STATS']['DISK']['TOTAL']['TEXT'].get(
"BACKGROUND_IMAGE",
None))
)

if config.THEME_DATA['STATS']['DISK']['FREE']['TEXT'].get("SHOW", False):
free_text = f"{int(free / 1000000000):>5}"
if config.THEME_DATA['STATS']['DISK']['FREE']['TEXT'].get("SHOW_UNIT", True):
free_text += " G"

display.lcd.DisplayText(
text=free_text,
x=config.THEME_DATA['STATS']['DISK']['FREE']['TEXT'].get("X", 0),
y=config.THEME_DATA['STATS']['DISK']['FREE']['TEXT'].get("Y", 0),
font=config.THEME_DATA['STATS']['DISK']['FREE']['TEXT'].get("FONT",
"roboto-mono/RobotoMono-Regular.ttf"),
font_size=config.THEME_DATA['STATS']['DISK']['FREE']['TEXT'].get("FONT_SIZE", 10),
font_color=config.THEME_DATA['STATS']['DISK']['FREE']['TEXT'].get("FONT_COLOR", (0, 0, 0)),
background_color=config.THEME_DATA['STATS']['DISK']['FREE']['TEXT'].get("BACKGROUND_COLOR",
(255, 255, 255)),
background_image=get_full_path(config.THEME_DATA['PATH'],
config.THEME_DATA['STATS']['DISK']['FREE']['TEXT'].get(
"BACKGROUND_IMAGE",
None))
)
if config.THEME_DATA['STATS']['DISK'].get("MOUNTS", False):
for mount in config.THEME_DATA['STATS']['DISK']['MOUNTS']:
mountpoint = [k for k, v in mount.items()][0]
if not os.path.exists(mountpoint):
logger.warning('Invalid mount point in config: "%s"' % mountpoint)
else:
used = sensors.Disk.disk_used(mountpoint)
free = sensors.Disk.disk_free(mountpoint)
if mount[mountpoint]['USED']['GRAPH'].get("SHOW", False):
display.lcd.DisplayProgressBar(
x=mount[mountpoint]['USED']['GRAPH'].get("X", 0),
y=mount[mountpoint]['USED']['GRAPH'].get("Y", 0),
width=mount[mountpoint]['USED']['GRAPH'].get("WIDTH", 0),
height=mount[mountpoint]['USED']['GRAPH'].get("HEIGHT", 0),
value=int(sensors.Disk.disk_usage_percent(mountpoint)),
min_value=mount[mountpoint]['USED']['GRAPH'].get("MIN_VALUE", 0),
max_value=mount[mountpoint]['USED']['GRAPH'].get("MAX_VALUE", 100),
bar_color=mount[mountpoint]['USED']['GRAPH'].get("BAR_COLOR", (0, 0, 0)),
bar_outline=mount[mountpoint]['USED']['GRAPH'].get("BAR_OUTLINE", False),
background_color=mount[mountpoint]['USED']['GRAPH'].get("BACKGROUND_COLOR",
(255, 255, 255)),
background_image=get_full_path(config.THEME_DATA['PATH'],
mount[mountpoint]['USED']['GRAPH'].get(
"BACKGROUND_IMAGE",
None))
)

if mount[mountpoint]['USED']['TEXT'].get("SHOW", False):
used_text = f"{int(used / 1000000000):>5}"
if mount[mountpoint]['USED']['TEXT'].get("SHOW_UNIT", True):
used_text += " G"

display.lcd.DisplayText(
text=used_text,
x=mount[mountpoint]['USED']['TEXT'].get("X", 0),
y=mount[mountpoint]['USED']['TEXT'].get("Y", 0),
font=mount[mountpoint]['USED']['TEXT'].get("FONT",
"roboto-mono/RobotoMono-Regular.ttf"),
font_size=mount[mountpoint]['USED']['TEXT'].get("FONT_SIZE", 10),
font_color=mount[mountpoint]['USED']['TEXT'].get("FONT_COLOR", (0, 0, 0)),
background_color=mount[mountpoint]['USED']['TEXT'].get("BACKGROUND_COLOR",
(255, 255, 255)),
background_image=get_full_path(config.THEME_DATA['PATH'],
mount[mountpoint]['USED']['TEXT'].get(
"BACKGROUND_IMAGE",
None))
)

if mount[mountpoint]['USED']['PERCENT_TEXT'].get("SHOW", False):
percent_text = f"{int(sensors.Disk.disk_usage_percent(mountpoint)):>3}"
if mount[mountpoint]['USED']['PERCENT_TEXT'].get("SHOW_UNIT", True):
percent_text += "%"

display.lcd.DisplayText(
text=percent_text,
x=mount[mountpoint]['USED']['PERCENT_TEXT'].get("X", 0),
y=mount[mountpoint]['USED']['PERCENT_TEXT'].get("Y", 0),
font=mount[mountpoint]['USED']['PERCENT_TEXT'].get("FONT",
"roboto-mono/RobotoMono-Regular.ttf"),
font_size=mount[mountpoint]['USED']['PERCENT_TEXT'].get("FONT_SIZE", 10),
font_color=mount[mountpoint]['USED']['PERCENT_TEXT'].get("FONT_COLOR", (0, 0, 0)),
background_color=mount[mountpoint]['USED']['PERCENT_TEXT'].get("BACKGROUND_COLOR",
(255, 255, 255)),
background_image=get_full_path(config.THEME_DATA['PATH'],
mount[mountpoint]['USED']['PERCENT_TEXT'].get(
"BACKGROUND_IMAGE",
None))
)

if mount[mountpoint]['TOTAL']['TEXT'].get("SHOW", False):
total_text = f"{int((free + used) / 1000000000):>5}"
if mount[mountpoint]['TOTAL']['TEXT'].get("SHOW_UNIT", True):
total_text += " G"

display.lcd.DisplayText(
text=total_text,
x=mount[mountpoint]['TOTAL']['TEXT'].get("X", 0),
y=mount[mountpoint]['TOTAL']['TEXT'].get("Y", 0),
font=mount[mountpoint]['TOTAL']['TEXT'].get("FONT",
"roboto-mono/RobotoMono-Regular.ttf"),
font_size=mount[mountpoint]['TOTAL']['TEXT'].get("FONT_SIZE", 10),
font_color=mount[mountpoint]['TOTAL']['TEXT'].get("FONT_COLOR", (0, 0, 0)),
background_color=mount[mountpoint]['TOTAL']['TEXT'].get("BACKGROUND_COLOR",
(255, 255, 255)),
background_image=get_full_path(config.THEME_DATA['PATH'],
mount[mountpoint]['TOTAL']['TEXT'].get(
"BACKGROUND_IMAGE",
None))
)

if mount[mountpoint]['FREE']['TEXT'].get("SHOW", False):
free_text = f"{int(free / 1000000000):>5}"
if mount[mountpoint]['FREE']['TEXT'].get("SHOW_UNIT", True):
free_text += " G"

display.lcd.DisplayText(
text=free_text,
x=mount[mountpoint]['FREE']['TEXT'].get("X", 0),
y=mount[mountpoint]['FREE']['TEXT'].get("Y", 0),
font=mount[mountpoint]['FREE']['TEXT'].get("FONT",
"roboto-mono/RobotoMono-Regular.ttf"),
font_size=mount[mountpoint]['FREE']['TEXT'].get("FONT_SIZE", 10),
font_color=mount[mountpoint]['FREE']['TEXT'].get("FONT_COLOR", (0, 0, 0)),
background_color=mount[mountpoint]['FREE']['TEXT'].get("BACKGROUND_COLOR",
(255, 255, 255)),
background_image=get_full_path(config.THEME_DATA['PATH'],
mount[mountpoint]['FREE']['TEXT'].get(
"BACKGROUND_IMAGE",
None))
)


class Net:
Expand Down
Loading