Skip to content
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

hddtemp: remove deprecated telnetlib dependency (fixes #2261) #2262

Merged
merged 4 commits into from
Oct 22, 2024
Merged
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
12 changes: 10 additions & 2 deletions py3status/modules/hddtemp.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

Requires:
hddtemp: utility to monitor hard drive temperatures
nc: netcat / ncat is command-line utility for reading data from hddtemp
telnet interface

Bible of HDD failures:
Hard disk temperatures higher than 45°C led to higher failure rates.
Expand Down Expand Up @@ -108,7 +110,8 @@
"""

from string import printable
from telnetlib import Telnet

STRING_NOT_INSTALLED = "shell command {} not installed"


class Py3status:
Expand All @@ -130,12 +133,17 @@ class Py3status:
]

def post_config_hook(self):
if not self.py3.check_commands("hddtemp"):
raise Exception(STRING_NOT_INSTALLED.format("hddtemp"))
if not self.py3.check_commands("nc"):
raise Exception(STRING_NOT_INSTALLED.format("netcat / ncat"))

self.keys = ["path", "name", "temperature", "unit"]
self.cache_names = {}
self.thresholds_init = self.py3.get_color_names_list(self.format_hdd)

def hddtemp(self):
line = Telnet("localhost", 7634).read_all().decode("utf-8", "ignore")
line = self.py3.command_output("nc localhost 7634")
new_data = []

for chunk in line[1:-1].split("||"):
Expand Down
Loading