From ca25c356b687ffe9a2b63494de97607e8adc68ca Mon Sep 17 00:00:00 2001 From: Richard Neumann Date: Thu, 21 Oct 2021 22:48:52 +0200 Subject: Update type hints meminfo() returns ints. --- archinstall/lib/hardware.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'archinstall/lib/hardware.py') diff --git a/archinstall/lib/hardware.py b/archinstall/lib/hardware.py index a8f87b80..e4308638 100644 --- a/archinstall/lib/hardware.py +++ b/archinstall/lib/hardware.py @@ -152,15 +152,15 @@ def product_name() -> Optional[str]: return product.read().strip() -def mem_available() -> Optional[str]: +def mem_available() -> Optional[int]: return meminfo('MemAvailable') -def mem_free() -> Optional[str]: +def mem_free() -> Optional[int]: return meminfo('MemFree') -def mem_total() -> Optional[str]: +def mem_total() -> Optional[int]: return meminfo('MemTotal') -- cgit v1.2.3-70-g09d2 From 4f6cec5069023198b047cb61e3e65fb37a93d577 Mon Sep 17 00:00:00 2001 From: Richard Neumann Date: Thu, 21 Oct 2021 22:50:49 +0200 Subject: Remove useless initialization of mem_info = {} --- archinstall/lib/hardware.py | 2 -- 1 file changed, 2 deletions(-) (limited to 'archinstall/lib/hardware.py') diff --git a/archinstall/lib/hardware.py b/archinstall/lib/hardware.py index e4308638..4f8192e4 100644 --- a/archinstall/lib/hardware.py +++ b/archinstall/lib/hardware.py @@ -79,8 +79,6 @@ def meminfo(key: Optional[str] = None) -> Union[dict[str, int], int]: """Returns a dict with memory info if called with no args or the value of the given key of said dict. """ - mem_info = {} - with MEMINFO.open() as file: mem_info = { (columns := line.strip().split())[0].rstrip(':'): int(columns[1]) -- cgit v1.2.3-70-g09d2 From 63c6f39f98efcaa644d2d64c2e9468cb240a32dd Mon Sep 17 00:00:00 2001 From: Richard Neumann Date: Thu, 21 Oct 2021 22:54:00 +0200 Subject: Generalize CPU vendor detection Implement has_amd_cpu() and has_intel_cpu() as partials. --- archinstall/lib/hardware.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'archinstall/lib/hardware.py') diff --git a/archinstall/lib/hardware.py b/archinstall/lib/hardware.py index 4f8192e4..7172628b 100644 --- a/archinstall/lib/hardware.py +++ b/archinstall/lib/hardware.py @@ -1,4 +1,5 @@ import os +from functools import partial from pathlib import Path from typing import Iterator, Optional, Union @@ -95,11 +96,11 @@ def has_wifi() -> bool: return 'WIRELESS' in enrich_iface_types(list_interfaces().values()).values() -def has_amd_cpu() -> bool: - return any(cpu.get("vendor_id") == "AuthenticAMD" for cpu in cpuinfo()) +def has_cpu_vendor(vendor_id: str) -> bool: + return any(cpu.get("vendor_id") == vendor_id for cpu in cpuinfo()) -def has_intel_cpu() -> bool: - return any(cpu.get("vendor_id") == "GenuineIntel" for cpu in cpuinfo()) +has_amd_cpu = partial(has_cpu_vendor, "AuthenticAMD") +has_intel_cpu = partial(has_cpu_vendor, "GenuineIntel") def has_uefi() -> bool: return os.path.isdir('/sys/firmware/efi') -- cgit v1.2.3-70-g09d2 From 8eea3259245814e269e32ce69a08b81fcb2fca53 Mon Sep 17 00:00:00 2001 From: Richard Neumann Date: Thu, 21 Oct 2021 22:56:46 +0200 Subject: Improve type hint --- archinstall/lib/hardware.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'archinstall/lib/hardware.py') diff --git a/archinstall/lib/hardware.py b/archinstall/lib/hardware.py index 7172628b..bbfb06a9 100644 --- a/archinstall/lib/hardware.py +++ b/archinstall/lib/hardware.py @@ -76,7 +76,7 @@ def cpuinfo() -> Iterator[dict[str, str]]: cpu[key.strip()] = value.strip() -def meminfo(key: Optional[str] = None) -> Union[dict[str, int], int]: +def meminfo(key: Optional[str] = None) -> Union[dict[str, int], Optional[int]]: """Returns a dict with memory info if called with no args or the value of the given key of said dict. """ -- cgit v1.2.3-70-g09d2