@@ -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