From 2e417b1587e08d13c1507bb9ab167468ecfad897 Mon Sep 17 00:00:00 2001 From: Jorge Capona Date: Tue, 16 Jul 2024 09:04:09 -0400 Subject: [PATCH] Use regex to parse kernel version --- pitopd/poweroff.py | 8 +++++--- pitopd/pthub/pthub_spi.py | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/pitopd/poweroff.py b/pitopd/poweroff.py index 543fb6f3..c9670ba2 100644 --- a/pitopd/poweroff.py +++ b/pitopd/poweroff.py @@ -1,6 +1,6 @@ -from distutils.version import StrictVersion from os.path import isfile from platform import uname +from re import match from time import sleep from pitop.common.common_ids import DeviceID @@ -22,8 +22,10 @@ def _do_poweroff_legacy(): request_shutdown = False def using_old_kernel(): - current_version_name = uname().release.split("-")[0] - return StrictVersion(current_version_name) < StrictVersion("5.0.0") + # check if kernel version is lower than "5.0.0" + # to avoid errors when setting cshigh + # https://github.com/raspberrypi/linux/issues/3745 + return match(r"^[0-4]\.", uname().release) is not None def parity7(data): p = False diff --git a/pitopd/pthub/pthub_spi.py b/pitopd/pthub/pthub_spi.py index 03d3923c..ad0397e0 100644 --- a/pitopd/pthub/pthub_spi.py +++ b/pitopd/pthub/pthub_spi.py @@ -1,9 +1,9 @@ import logging import threading import traceback -from distutils.version import StrictVersion from enum import Enum from platform import uname +from re import match from time import sleep from pitop.common.common_ids import DeviceID @@ -301,8 +301,10 @@ def _process_spi_resp(self, resp, init=False): self._state.set_brightness(spi_brightness_int, False) def __using_old_kernel(self): - current_version_name = uname().release.split("-")[0] - return StrictVersion(current_version_name) < StrictVersion("5.0.0") + # check if kernel version is lower than "5.0.0" + # to avoid errors when setting cshigh + # https://github.com/raspberrypi/linux/issues/3745 + return match(r"^[0-4]\.", uname().release) is not None def _transceive_spi(self, bits_to_send): hex_str_to_send = "0x" + str(hex(bits_to_send))[2:].zfill(2)