|
10 | 10 | from archey.distributions import Distributions |
11 | 11 | from archey.entry import Entry |
12 | 12 |
|
| 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 | + |
13 | 19 |
|
14 | 20 | class Model(Entry): |
15 | 21 | """Uses multiple methods to retrieve some information about the host hardware""" |
16 | 22 |
|
17 | 23 | _ICON = "\ueabe" # cod_circuit_board |
18 | 24 |
|
19 | | - LINUX_DMI_SYS_PATH = "/sys/devices/virtual/dmi/id" |
20 | | - |
21 | 25 | def __init__(self, *args, **kwargs): |
22 | 26 | super().__init__(*args, **kwargs) |
23 | 27 |
|
@@ -76,21 +80,21 @@ def _fetch_virtual_env_info(self) -> Optional[str]: |
76 | 80 | except (OSError, CalledProcessError): |
77 | 81 | return None |
78 | 82 |
|
79 | | - @classmethod |
80 | | - def _fetch_dmi_info(cls) -> Optional[str]: |
| 83 | + @staticmethod |
| 84 | + def _fetch_dmi_info() -> Optional[str]: |
81 | 85 | """Tries to open DMI Linux files, looking for hardware information""" |
82 | 86 |
|
83 | 87 | def _read_dmi_file(file_name: str) -> str: |
84 | 88 | try: |
85 | 89 | 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" |
87 | 91 | ) as f_dmi_file: |
88 | 92 | dmi_info = f_dmi_file.read().rstrip() |
89 | 93 | except OSError: |
90 | 94 | return "" |
91 | 95 |
|
92 | 96 | # 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): |
94 | 98 | return "" |
95 | 99 |
|
96 | 100 | return dmi_info |
|
0 commit comments