From 8f393b0795a9c9b817aaea8eeeaebfd145cdf886 Mon Sep 17 00:00:00 2001 From: Valdur Kana Date: Thu, 10 Oct 2024 17:01:00 +0300 Subject: [PATCH 1/4] hddtemp: remove deprecated telnetlib dependency (fixes #2261) --- py3status/modules/hddtemp.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/py3status/modules/hddtemp.py b/py3status/modules/hddtemp.py index 1d5fd9d280..2cf740e3a6 100644 --- a/py3status/modules/hddtemp.py +++ b/py3status/modules/hddtemp.py @@ -36,6 +36,8 @@ Requires: hddtemp: utility to monitor hard drive temperatures + netcat: (nc) is a 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. @@ -108,7 +110,6 @@ """ from string import printable -from telnetlib import Telnet class Py3status: @@ -135,7 +136,7 @@ def post_config_hook(self): 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("||"): From e6fd157bfafc9340278de60e2a2deec9e4b09516 Mon Sep 17 00:00:00 2001 From: Valdur Kana Date: Thu, 10 Oct 2024 17:29:40 +0300 Subject: [PATCH 2/4] hddtemp: codereview improvements --- py3status/modules/hddtemp.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/py3status/modules/hddtemp.py b/py3status/modules/hddtemp.py index 2cf740e3a6..7ecc632be0 100644 --- a/py3status/modules/hddtemp.py +++ b/py3status/modules/hddtemp.py @@ -36,8 +36,7 @@ Requires: hddtemp: utility to monitor hard drive temperatures - netcat: (nc) is a command-line utility for reading - data from hddtemp telnet interface + netcat: 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. @@ -111,6 +110,8 @@ from string import printable +STRING_NOT_INSTALLED = "netcat not installed" + class Py3status: """ """ @@ -134,9 +135,11 @@ def post_config_hook(self): self.keys = ["path", "name", "temperature", "unit"] self.cache_names = {} self.thresholds_init = self.py3.get_color_names_list(self.format_hdd) + if not self.py3.check_commands("netcat"): + raise Exception(STRING_NOT_INSTALLED) def hddtemp(self): - line = self.py3.command_output("nc localhost 7634") + line = self.py3.command_output("netcat localhost 7634") new_data = [] for chunk in line[1:-1].split("||"): From 9612d11f48acfd21d18327190b0cb6ca3435c180 Mon Sep 17 00:00:00 2001 From: Valdur Kana Date: Thu, 10 Oct 2024 18:27:14 +0300 Subject: [PATCH 3/4] hddtemp: post_config_hook improvement --- py3status/modules/hddtemp.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/py3status/modules/hddtemp.py b/py3status/modules/hddtemp.py index 7ecc632be0..ff29f297a0 100644 --- a/py3status/modules/hddtemp.py +++ b/py3status/modules/hddtemp.py @@ -132,11 +132,12 @@ class Py3status: ] def post_config_hook(self): + if not self.py3.check_commands("netcat"): + raise Exception(STRING_NOT_INSTALLED) + self.keys = ["path", "name", "temperature", "unit"] self.cache_names = {} self.thresholds_init = self.py3.get_color_names_list(self.format_hdd) - if not self.py3.check_commands("netcat"): - raise Exception(STRING_NOT_INSTALLED) def hddtemp(self): line = self.py3.command_output("netcat localhost 7634") From 549a0cfee9f74df1ca88831d7db2c6d2cf85ea27 Mon Sep 17 00:00:00 2001 From: Valdur Kana Date: Fri, 11 Oct 2024 16:20:42 +0300 Subject: [PATCH 4/4] hddtemp: post_config_hook checks hddtemp and nc executable presence and informs about missing hddtemp, ncat/netcat. --- py3status/modules/hddtemp.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/py3status/modules/hddtemp.py b/py3status/modules/hddtemp.py index ff29f297a0..26ec1ccedc 100644 --- a/py3status/modules/hddtemp.py +++ b/py3status/modules/hddtemp.py @@ -36,7 +36,8 @@ Requires: hddtemp: utility to monitor hard drive temperatures - netcat: command-line utility for reading data from hddtemp telnet interface + 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. @@ -110,7 +111,7 @@ from string import printable -STRING_NOT_INSTALLED = "netcat not installed" +STRING_NOT_INSTALLED = "shell command {} not installed" class Py3status: @@ -132,15 +133,17 @@ class Py3status: ] def post_config_hook(self): - if not self.py3.check_commands("netcat"): - raise Exception(STRING_NOT_INSTALLED) + 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 = self.py3.command_output("netcat localhost 7634") + line = self.py3.command_output("nc localhost 7634") new_data = [] for chunk in line[1:-1].split("||"):