Skip to content

Commit

Permalink
[MODEL] Honors /proc/device-tree/model when it exists
Browse files Browse the repository at this point in the history
  • Loading branch information
HorlogeSkynet committed Aug 19, 2024
1 parent 9e61a38 commit 1d479f2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ and this project (partially) adheres to [Semantic Versioning](https://semver.org
- `Model` support for Raspberry Pi 5+
- AppArmor confinement profile (included in Debian and AUR packages)

### Changed
- `Model` honor `/proc/device-tree/model` when it exists

## [v4.14.3.0] - 2024-04-06
### Added
- Official Armbian distribution support
Expand Down
1 change: 1 addition & 0 deletions apparmor.profile
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ profile archey4 /usr/{,local/}bin/archey{,4} {
@{PROC}/loadavg r,

# [Model] entry
@{PROC}/device-tree/model r,
@{sys}/devices/virtual/dmi/id/* r,
/{,usr/}bin/systemd-detect-virt PUx,
/{,usr/}{,s}bin/virt-what PUx,
Expand Down
8 changes: 7 additions & 1 deletion archey/entries/model.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Hardware model information detection class"""

import contextlib
import os
import platform
import re
Expand Down Expand Up @@ -156,7 +157,12 @@ def _fetch_sysctl_hw() -> Optional[str]:

@staticmethod
def _fetch_raspberry_pi_revision() -> Optional[str]:
"""Tries to retrieve 'Hardware' and 'Revision IDs' from `/proc/cpuinfo`"""
"""Tries to retrieve hardware info from `/proc/device-tree/model` or `/proc/cpuinfo`"""
with contextlib.suppress(OSError), open(
"/proc/device-tree/model", encoding="ASCII"
) as f_model:
return f_model.read().rstrip()

try:
with open("/proc/cpuinfo", encoding="ASCII") as f_cpu_info:
cpu_info = f_cpu_info.read()
Expand Down
22 changes: 19 additions & 3 deletions archey/test/entries/test_archey_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,19 +217,35 @@ def test_fetch_raspberry_pi_revision(self):
"""Test `_fetch_raspberry_pi_revision` static method"""
with patch("archey.entries.model.open", mock_open()) as mock:
mock.return_value.read.side_effect = [
"Revision\t: REV\nSerial\t: SERIAL\nModel\t: HARDWARE Model MODEL Rev REVISION\n",
"Hardware\t: HARDWARE\nRevision\t: REVISION\n",
"processor : 0\ncpu family : X\n",
"Raspberry Pi 3 Model B Plus Rev 1.3\n",
]
self.assertEqual(
Model._fetch_raspberry_pi_revision(), # pylint: disable=protected-access
"Raspberry Pi 3 Model B Plus Rev 1.3",
)

mock.return_value.read.side_effect = [
FileNotFoundError(), # /proc/device-tree/model doesn't exist
"Revision\t: REV\nSerial\t: SERIAL\nModel\t: HARDWARE Model MODEL Rev REVISION\n",
]
self.assertEqual(
Model._fetch_raspberry_pi_revision(), # pylint: disable=protected-access
"HARDWARE Model MODEL Rev REVISION",
)

mock.return_value.read.side_effect = [
FileNotFoundError(), # /proc/device-tree/model doesn't exist
"Hardware\t: HARDWARE\nRevision\t: REVISION\n",
]
self.assertEqual(
Model._fetch_raspberry_pi_revision(), # pylint: disable=protected-access
"Raspberry Pi HARDWARE (Rev. REVISION)",
)

mock.return_value.read.side_effect = [
FileNotFoundError(), # /proc/device-tree/model doesn't exist
"processor : 0\ncpu family : X\n",
]
self.assertIsNone(
Model._fetch_raspberry_pi_revision() # pylint: disable=protected-access
)
Expand Down

0 comments on commit 1d479f2

Please sign in to comment.