From b8ede1b333e3dd4d2a6c3553685e5026dfd2c346 Mon Sep 17 00:00:00 2001 From: Richard Neumann Date: Fri, 20 Aug 2021 18:13:23 +0200 Subject: Add cpuinfo() --- archinstall/lib/hardware.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'archinstall/lib') diff --git a/archinstall/lib/hardware.py b/archinstall/lib/hardware.py index a63155f5..56a9fa11 100644 --- a/archinstall/lib/hardware.py +++ b/archinstall/lib/hardware.py @@ -1,7 +1,8 @@ import json import os import subprocess -from typing import Optional +from pathlib import Path +from typing import Iterator, Optional from .general import SysCommand from .networking import list_interfaces, enrich_iface_types @@ -57,6 +58,24 @@ AVAILABLE_GFX_DRIVERS = { "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: return 'WIRELESS' in enrich_iface_types(list_interfaces().values()).values() -- cgit v1.2.3-70-g09d2 From 61947ab944aec76d60ee921ff3c451b7d02a5df2 Mon Sep 17 00:00:00 2001 From: Richard Neumann Date: Fri, 20 Aug 2021 18:16:00 +0200 Subject: Rewrite CPU vendor detection functions Use cpuinfo() function rather than a subprocess. --- archinstall/lib/hardware.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'archinstall/lib') diff --git a/archinstall/lib/hardware.py b/archinstall/lib/hardware.py index 56a9fa11..eaf01f40 100644 --- a/archinstall/lib/hardware.py +++ b/archinstall/lib/hardware.py @@ -1,6 +1,5 @@ import json import os -import subprocess from pathlib import Path from typing import Iterator, Optional @@ -82,15 +81,11 @@ def has_wifi() -> bool: def has_amd_cpu() -> bool: - if subprocess.check_output("lscpu | grep AMD", shell=True).strip().decode(): - return True - return False + return any(cpu.get("vendor_id") == "AuthenticAMD" for cpu in cpuinfo()) def has_intel_cpu() -> bool: - if subprocess.check_output("lscpu | grep Intel", shell=True).strip().decode(): - return True - return False + return any(cpu.get("vendor_id") == "GenuineIntel" for cpu in cpuinfo()) def has_uefi() -> bool: -- cgit v1.2.3-70-g09d2 From a5a56728f155f689bed5826bbd30532a56450cf3 Mon Sep 17 00:00:00 2001 From: Richard Neumann Date: Fri, 20 Aug 2021 18:16:45 +0200 Subject: Remove excess newline --- archinstall/lib/hardware.py | 1 - 1 file changed, 1 deletion(-) (limited to 'archinstall/lib') diff --git a/archinstall/lib/hardware.py b/archinstall/lib/hardware.py index eaf01f40..1299a6b4 100644 --- a/archinstall/lib/hardware.py +++ b/archinstall/lib/hardware.py @@ -62,7 +62,6 @@ CPUINFO = Path("/proc/cpuinfo") def cpuinfo() -> Iterator[dict[str, str]]: """Yields information about the CPUs of the system.""" - cpu = {} with CPUINFO.open() as file: -- cgit v1.2.3-70-g09d2