@@ -48,11 +48,11 @@ def get_cpuinfo_field(self, field):
48
48
49
49
with open ("/proc/cpuinfo" , "r" ) as infile :
50
50
cpuinfo = infile .read ().split ("\n " )
51
+ infile .close ()
51
52
for line in cpuinfo :
52
53
match = re .search (pattern , line , flags = re .IGNORECASE )
53
54
if match :
54
55
return match .group (1 )
55
-
56
56
return None
57
57
58
58
def check_dt_compatible_value (self , value ):
@@ -61,11 +61,9 @@ def check_dt_compatible_value(self, value):
61
61
otherwise False.
62
62
"""
63
63
# 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
69
67
70
68
return False
71
69
@@ -84,6 +82,7 @@ def get_armbian_release_field(self, field):
84
82
match = re .search (pattern , line )
85
83
if match :
86
84
field_value = match .group (1 )
85
+ release_file .close ()
87
86
except FileNotFoundError :
88
87
pass
89
88
@@ -99,6 +98,7 @@ def get_device_model(self):
99
98
try :
100
99
with open ("/proc/device-tree/model" , "r" ) as model_file :
101
100
model = model_file .read ()
101
+ model_file .close ()
102
102
except FileNotFoundError :
103
103
pass
104
104
@@ -113,22 +113,40 @@ def get_device_compatible(self):
113
113
try :
114
114
with open ("/proc/device-tree/compatible" , "r" ) as model_file :
115
115
model = model_file .read ()
116
+ model_file .close ()
116
117
except FileNotFoundError :
117
118
pass
118
119
119
120
return model
120
121
121
122
def check_board_asset_tag_value (self ):
122
123
"""
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,
124
125
otherwise None.
125
126
"""
126
127
tag = None
127
128
128
129
try :
129
130
with open ("/sys/devices/virtual/dmi/id/board_asset_tag" , "r" ) as tag_file :
130
131
tag = tag_file .read ().strip ()
132
+ tag_file .close ()
131
133
except FileNotFoundError :
132
134
pass
133
135
134
136
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