Skip to content

Commit 3069583

Browse files
committed
[MODEL] Ignores "Default string" fuzzy data (encountered against ASRock)
> closes #167
1 parent b79d7f0 commit 3069583

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project (partially) adheres to [Semantic Versioning](https://semver.org
1313

1414
### Changed
1515
- `Entry` behavior in boolean contexts ("truthy" when `value` is populated)
16+
- `Model` now ignores "Default string" fuzzy data
1617

1718
### Fixed
1819
- Sub-process execution failure when `PATH` contains an invalid component

archey/entries/model.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,18 @@
1010
from archey.distributions import Distributions
1111
from archey.entry import Entry
1212

13+
LINUX_DMI_SYS_PATH = "/sys/devices/virtual/dmi/id"
14+
LINUX_DMI_FUZZY_PATTERNS = [
15+
re.compile("to be filled", re.IGNORECASE),
16+
re.compile("default string", re.IGNORECASE),
17+
]
18+
1319

1420
class Model(Entry):
1521
"""Uses multiple methods to retrieve some information about the host hardware"""
1622

1723
_ICON = "\ueabe" # cod_circuit_board
1824

19-
LINUX_DMI_SYS_PATH = "/sys/devices/virtual/dmi/id"
20-
2125
def __init__(self, *args, **kwargs):
2226
super().__init__(*args, **kwargs)
2327

@@ -76,21 +80,21 @@ def _fetch_virtual_env_info(self) -> Optional[str]:
7680
except (OSError, CalledProcessError):
7781
return None
7882

79-
@classmethod
80-
def _fetch_dmi_info(cls) -> Optional[str]:
83+
@staticmethod
84+
def _fetch_dmi_info() -> Optional[str]:
8185
"""Tries to open DMI Linux files, looking for hardware information"""
8286

8387
def _read_dmi_file(file_name: str) -> str:
8488
try:
8589
with open(
86-
os.path.join(cls.LINUX_DMI_SYS_PATH, file_name), encoding="UTF-8"
90+
os.path.join(LINUX_DMI_SYS_PATH, file_name), encoding="UTF-8"
8791
) as f_dmi_file:
8892
dmi_info = f_dmi_file.read().rstrip()
8993
except OSError:
9094
return ""
9195

9296
# Stop `/sys/devices/virtual/dmi/id/*` parsing on fuzzy data.
93-
if "to be filled" in dmi_info.lower():
97+
if any(fuzzy_pattern.match(dmi_info) for fuzzy_pattern in LINUX_DMI_FUZZY_PATTERNS):
9498
return ""
9599

96100
return dmi_info

0 commit comments

Comments
 (0)