Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/lib/hardware.py
diff options
context:
space:
mode:
authorDaniel Girtler <blackrabbit256@gmail.com>2023-05-04 00:36:46 +1000
committerGitHub <noreply@github.com>2023-05-03 16:36:46 +0200
commitec4ecbcb7a839ab06b739f01ce42bfd18376c620 (patch)
treeb617783f2d7cb4d4bf32690590859e68666bf3d4 /archinstall/lib/hardware.py
parente78ddb03e1bbc46e59fd6a9889699b12808d0fec (diff)
Full mypy compliance and small fixes (#1777)
* Fix mypy compliance --------- Co-authored-by: Daniel Girtler <girtler.daniel@gmail.com>
Diffstat (limited to 'archinstall/lib/hardware.py')
-rw-r--r--archinstall/lib/hardware.py55
1 files changed, 31 insertions, 24 deletions
diff --git a/archinstall/lib/hardware.py b/archinstall/lib/hardware.py
index 9660ea95..3759725f 100644
--- a/archinstall/lib/hardware.py
+++ b/archinstall/lib/hardware.py
@@ -2,7 +2,7 @@ import os
import logging
from functools import partial
from pathlib import Path
-from typing import Iterator, Optional, Union
+from typing import Iterator, Optional, Dict
from .general import SysCommand
from .networking import list_interfaces, enrich_iface_types
@@ -61,15 +61,15 @@ AVAILABLE_GFX_DRIVERS = {
"VMware / VirtualBox (open-source)": ["mesa", "xf86-video-vmware"],
}
-CPUINFO = Path("/proc/cpuinfo")
-MEMINFO = Path("/proc/meminfo")
-
def cpuinfo() -> Iterator[dict[str, str]]:
- """Yields information about the CPUs of the system."""
- cpu = {}
+ """
+ Yields information about the CPUs of the system
+ """
+ cpu_info_path = Path("/proc/cpuinfo")
+ cpu: Dict[str, str] = {}
- with CPUINFO.open() as file:
+ with cpu_info_path.open() as file:
for line in file:
if not (line := line.strip()):
yield cpu
@@ -80,24 +80,31 @@ def cpuinfo() -> Iterator[dict[str, str]]:
cpu[key.strip()] = value.strip()
-def meminfo(key: Optional[str] = None) -> Union[dict[str, int], Optional[int]]:
- """Returns a dict with memory info if called with no args
+def all_meminfo() -> Dict[str, int]:
+ """
+ Returns a dict with memory info if called with no args
or the value of the given key of said dict.
"""
- with MEMINFO.open() as file:
- mem_info = {
- (columns := line.strip().split())[0].rstrip(':'): int(columns[1])
- for line in file
- }
+ mem_info_path = Path("/proc/meminfo")
+ mem_info: Dict[str, int] = {}
- if key is None:
- return mem_info
+ with mem_info_path.open() as file:
+ for line in file:
+ key, value = line.strip().split(':')
+ num = value.split()[0]
+ mem_info[key] = int(num)
+
+ return mem_info
- return mem_info.get(key)
+
+def meminfo_for_key(key: str) -> int:
+ info = all_meminfo()
+ return info[key]
def has_wifi() -> bool:
- return 'WIRELESS' in enrich_iface_types(list_interfaces().values()).values()
+ ifaces = list(list_interfaces().values())
+ return 'WIRELESS' in enrich_iface_types(ifaces).values()
def has_cpu_vendor(vendor_id: str) -> bool:
@@ -160,15 +167,15 @@ def product_name() -> Optional[str]:
def mem_available() -> Optional[int]:
- return meminfo('MemAvailable')
+ return meminfo_for_key('MemAvailable')
def mem_free() -> Optional[int]:
- return meminfo('MemFree')
+ return meminfo_for_key('MemFree')
def mem_total() -> Optional[int]:
- return meminfo('MemTotal')
+ return meminfo_for_key('MemTotal')
def virtualization() -> Optional[str]:
@@ -182,9 +189,9 @@ def virtualization() -> Optional[str]:
def is_vm() -> bool:
try:
- return b"none" not in b"".join(SysCommand("systemd-detect-virt")).lower()
+ result = SysCommand("systemd-detect-virt")
+ return b"none" not in b"".join(result).lower()
except SysCallError as error:
log(f"System is not running in a VM: {error}", level=logging.DEBUG)
- return None
-# TODO: Add more identifiers
+ return False