Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 13 additions & 18 deletions archinstall/lib/hardware.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import os
from enum import Enum
from enum import Enum, StrEnum
from functools import cached_property
from pathlib import Path
from typing import Self

from archinstall.lib.command import SysCommand
from archinstall.lib.exceptions import SysCallError
Expand All @@ -11,29 +10,21 @@
from archinstall.lib.translationhandler import tr


class CpuVendor(Enum):
AuthenticAMD = 'amd'
GenuineIntel = 'intel'
_Unknown = 'unknown'

@classmethod
def get_vendor(cls, name: str) -> Self:
if vendor := getattr(cls, name, None):
return vendor
else:
debug(f"Unknown CPU vendor '{name}' detected.")
return cls._Unknown
class CPUVendor(StrEnum):
AMD = 'AuthenticAMD'
INTEL = 'GenuineIntel'
_UNKNOWN = 'unknown'

def _has_microcode(self) -> bool:
match self:
case CpuVendor.AuthenticAMD | CpuVendor.GenuineIntel:
case CPUVendor.AMD | CPUVendor.INTEL:
return True
case _:
return False

def get_ucode(self) -> Path | None:
if self._has_microcode():
return Path(self.value + '-ucode.img')
return Path(self.name.lower() + '-ucode.img')
return None


Expand Down Expand Up @@ -253,9 +244,13 @@ def has_intel_graphics() -> bool:
return any('intel' in x.lower() for x in _sys_info.graphics_devices)

@staticmethod
def cpu_vendor() -> CpuVendor | None:
def cpu_vendor() -> CPUVendor | None:
if vendor := _sys_info.cpu_info.get('vendor_id'):
return CpuVendor.get_vendor(vendor)
try:
return CPUVendor(vendor)
except ValueError:
debug(f"Unknown CPU vendor '{vendor}' detected.")
return CPUVendor._UNKNOWN
return None

@staticmethod
Expand Down