diff --git a/CHANGELOG.md b/CHANGELOG.md index 907a49a..f77c878 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/apparmor.profile b/apparmor.profile index a7f5e21..e64cdd2 100644 --- a/apparmor.profile +++ b/apparmor.profile @@ -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, diff --git a/archey/entries/model.py b/archey/entries/model.py index cac3458..7d6f8d0 100644 --- a/archey/entries/model.py +++ b/archey/entries/model.py @@ -1,5 +1,6 @@ """Hardware model information detection class""" +import contextlib import os import platform import re @@ -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() diff --git a/archey/test/entries/test_archey_model.py b/archey/test/entries/test_archey_model.py index 7183083..06414c5 100644 --- a/archey/test/entries/test_archey_model.py +++ b/archey/test/entries/test_archey_model.py @@ -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 )