Little improvment regarding the CPU name if nothing is found. Display the CPU architecture.

This commit is contained in:
nicolargo
2025-03-22 16:05:58 +01:00
parent e7c2c219c5
commit ec0baca9f7

View File

@@ -8,6 +8,7 @@
"""CPU percent stats shared between CPU and Quicklook plugins."""
import platform
from typing import Optional, TypedDict
import psutil
@@ -95,17 +96,18 @@ class CpuPercent:
def __get_cpu_name() -> str:
# Get the CPU name once from the /proc/cpuinfo file
# Read the first line with the "model name" ("Model" for Raspberry Pi)
ret = f'CPU {platform.processor()}'
try:
cpuinfo_lines = open('/proc/cpuinfo').readlines()
except (FileNotFoundError, PermissionError):
logger.debug("No permission to read '/proc/cpuinfo'")
return 'CPU'
return ret
for line in cpuinfo_lines:
if line.startswith('model name') or line.startswith('Model') or line.startswith('cpu model'):
return line.split(':')[1].strip()
return 'CPU'
return ret
def get_cpu(self) -> float:
"""Update and/or return the CPU using the psutil library."""