Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NAS-131305 / 24.10.0 / cache parse_dmi() (by yocalebo) #5

Merged
merged 2 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.9
uses: actions/setup-python@v1
- uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: '3.11'
- name: Install pytest
run: |
python -m pip install --upgrade pip
Expand Down
21 changes: 15 additions & 6 deletions ixhardware/dmi.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from dataclasses import dataclass
from datetime import date, datetime
from functools import cache
import logging
import subprocess
from typing import Optional

logger = logging.getLogger(__name__)

Expand All @@ -11,7 +11,7 @@

@dataclass
class DMIInfo:
bios_release_date: Optional[date] = None
bios_release_date: date | None = None
ecc_memory: bool = False
baseboard_manufacturer: str = ""
baseboard_product_name: str = ""
Expand All @@ -28,7 +28,7 @@ class DMIParser:
def parse(self, output: str) -> DMIInfo:
return self._parse_dmi(output.splitlines())

def _parse_dmi(self, lines: [str]) -> DMIInfo:
def _parse_dmi(self, lines: list[str]) -> DMIInfo:
info = DMIInfo()

_type = None
Expand Down Expand Up @@ -89,11 +89,20 @@ def _parse_bios_release_date(self, string):
try:
return datetime.strptime(string, formatter).date()
except Exception as e:
logger.warning(f"Failed to format BIOS release date to datetime object: {e!r}")
logger.warning(
f"Failed to format BIOS release date to datetime object: {e!r}"
)


@cache
def parse_dmi() -> DMIInfo:
return DMIParser().parse(
subprocess.run(DMIParser.command, check=False, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL,
encoding="utf-8", errors="ignore").stdout
subprocess.run(
DMIParser.command,
check=False,
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL,
encoding="utf-8",
errors="ignore",
).stdout
)
Loading