[PATCH 16/23] tuna: replace match with if statements

John Kacur
2025-11-07T18:58:16Z

From: "John B. Wyatt IV" <jwyatt@redhat.com>

The match-case keyword statements were introduced in Python 3.10.
This patch will accomodate older distributions that only have Python 3.9
This patch will make it easier for older distributions to use newer versions
of Tuna.

Signed-off-by: John B. Wyatt IV <jwyatt@redhat.com>
- modified commit message
Signed-off-by: John Kacur <jkacur@redhat.com>
---
tuna/cpupower.py | 25 ++++++++++++-------------
1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/tuna/cpupower.py b/tuna/cpupower.py
index ec04b908855a..ecb2507b2127 100755
--- a/tuna/cpupower.py
+++ b/tuna/cpupower.py
@@ -38,20 +38,19 @@ if have_cpupower:
self.__cpu_list = utils.get_all_cpu_list()

def handle_common_lcpw_errors(self, e, error_type, idle_name):
- match e:
- case 0:
- pass
- case -1:
- print(f"Idlestate {idle_name} not available", file=sys.stderr)
- case -2:
- print("Disabling is not supported by the kernel", file=sys.stderr)
- case -3:
- if error_type == Cpupower.LCPW_ERROR_THREE_CASE:
- print("No write access to disable/enable C-states: try using sudo", file=sys.stderr)
- else:
- print(f"Not documented: {e}", file=sys.stderr)
- case _:
+ if e == 0:
+ pass
+ elif e == -1:
+ print(f"Idlestate {idle_name} not available", file=sys.stderr)
+ elif e == -2:
+ print("Disabling is not supported by the kernel", file=sys.stderr)
+ elif e == -3:
+ if error_type == Cpupower.LCPW_ERROR_THREE_CASE:
+ print("No write access to disable/enable C-states: try using sudo", file=sys.stderr)
+ else:
print(f"Not documented: {e}", file=sys.stderr)
+ else:
+ print(f"Not documented: {e}", file=sys.stderr)

def get_idle_states(self, cpu):
"""
--
2.51.1