Merge pull request #615 from conqp/native_cpu_detection

Native cpu detection
This commit is contained in:
Anton Hvornum 2021-09-06 15:55:05 +02:00 committed by GitHub
commit 81f3ccad40
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,7 +1,7 @@
import json import json
import os import os
import subprocess from pathlib import Path
from typing import Optional from typing import Iterator, Optional
from .general import SysCommand from .general import SysCommand
from .networking import list_interfaces, enrich_iface_types from .networking import list_interfaces, enrich_iface_types
@ -57,25 +57,33 @@ AVAILABLE_GFX_DRIVERS = {
"VMware / VirtualBox (open-source)": ["mesa", "xf86-video-vmware"], "VMware / VirtualBox (open-source)": ["mesa", "xf86-video-vmware"],
} }
CPUINFO = Path("/proc/cpuinfo")
def cpuinfo() -> Iterator[dict[str, str]]:
"""Yields information about the CPUs of the system."""
cpu = {}
with CPUINFO.open() as file:
for line in file:
if not (line := line.strip()):
yield cpu
cpu = {}
continue
key, value = line.split(":", maxsplit=1)
cpu[key.strip()] = value.strip()
def has_wifi() -> bool: def has_wifi() -> bool:
return 'WIRELESS' in enrich_iface_types(list_interfaces().values()).values() return 'WIRELESS' in enrich_iface_types(list_interfaces().values()).values()
def has_amd_cpu() -> bool: def has_amd_cpu() -> bool:
try: return any(cpu.get("vendor_id") == "AuthenticAMD" for cpu in cpuinfo())
return subprocess.check_output("lscpu | grep AMD", shell=True).strip().decode()
except:
pass
return False
def has_intel_cpu() -> bool: def has_intel_cpu() -> bool:
try: return any(cpu.get("vendor_id") == "GenuineIntel" for cpu in cpuinfo())
return subprocess.check_output("lscpu | grep Intel", shell=True).strip().decode()
except:
pass
return False
def has_uefi() -> bool: def has_uefi() -> bool:
return os.path.isdir('/sys/firmware/efi') return os.path.isdir('/sys/firmware/efi')