Skip to content

Commit 8a40e3d

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 34d046a + 23121c6 commit 8a40e3d

File tree

11 files changed

+398
-83
lines changed

11 files changed

+398
-83
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
source actions-ci/install.sh
3636
- name: Pip install pylint, black, & Sphinx
3737
run: |
38-
pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme
38+
pip install --force-reinstall pylint black Sphinx sphinx-rtd-theme
3939
- name: Library version
4040
run: git describe --dirty --always --tags
4141
- name: Check formatting

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Introduction
66
:alt: Documentation Status
77

88
.. image:: https://img.shields.io/discord/327254708534116352.svg
9-
:target: https://discord.gg/nBQh6qu
9+
:target: https://adafru.it/discord
1010
:alt: Discord
1111

1212
.. image:: https://github.com/adafruit/Adafruit_Python_PlatformDetect/workflows/Build%20CI/badge.svg

adafruit_platformdetect/__init__.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ def get_cpuinfo_field(self, field):
4848

4949
with open("/proc/cpuinfo", "r") as infile:
5050
cpuinfo = infile.read().split("\n")
51+
infile.close()
5152
for line in cpuinfo:
5253
match = re.search(pattern, line, flags=re.IGNORECASE)
5354
if match:
5455
return match.group(1)
55-
5656
return None
5757

5858
def check_dt_compatible_value(self, value):
@@ -61,11 +61,9 @@ def check_dt_compatible_value(self, value):
6161
otherwise False.
6262
"""
6363
# Match a value like 'qcom,apq8016-sbc':
64-
try:
65-
if value in open("/proc/device-tree/compatible").read():
66-
return True
67-
except FileNotFoundError:
68-
pass
64+
dt_compatible = self.get_device_compatible()
65+
if dt_compatible and value in dt_compatible:
66+
return True
6967

7068
return False
7169

@@ -84,6 +82,7 @@ def get_armbian_release_field(self, field):
8482
match = re.search(pattern, line)
8583
if match:
8684
field_value = match.group(1)
85+
release_file.close()
8786
except FileNotFoundError:
8887
pass
8988

@@ -99,6 +98,7 @@ def get_device_model(self):
9998
try:
10099
with open("/proc/device-tree/model", "r") as model_file:
101100
model = model_file.read()
101+
model_file.close()
102102
except FileNotFoundError:
103103
pass
104104

@@ -113,22 +113,40 @@ def get_device_compatible(self):
113113
try:
114114
with open("/proc/device-tree/compatible", "r") as model_file:
115115
model = model_file.read()
116+
model_file.close()
116117
except FileNotFoundError:
117118
pass
118119

119120
return model
120121

121122
def check_board_asset_tag_value(self):
122123
"""
123-
Search /proc/device-tree/model for the device model and return its value, if found,
124+
Search /sys/devices/virtual/dmi/id for the device model and return its value, if found,
124125
otherwise None.
125126
"""
126127
tag = None
127128

128129
try:
129130
with open("/sys/devices/virtual/dmi/id/board_asset_tag", "r") as tag_file:
130131
tag = tag_file.read().strip()
132+
tag_file.close()
131133
except FileNotFoundError:
132134
pass
133135

134136
return tag
137+
138+
def check_board_name_value(self):
139+
"""
140+
Search /sys/devices/virtual/dmi/id for the board name and return its value, if found,
141+
otherwise None. Debian/ubuntu based
142+
"""
143+
board_name = None
144+
145+
try:
146+
with open("/sys/devices/virtual/dmi/id/board_name", "r") as board_name_file:
147+
board_name = board_name_file.read().strip()
148+
board_name.close()
149+
except FileNotFoundError:
150+
pass
151+
152+
return board_name

0 commit comments

Comments
 (0)