@@ -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,12 +61,8 @@ 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
- with open ("/proc/device-tree/compatible" ) as compatible :
66
- if value in compatible .read ():
67
- return True
68
- except FileNotFoundError :
69
- pass
64
+ if value in self .get_device_compatible ():
65
+ return True
70
66
71
67
return False
72
68
@@ -85,6 +81,7 @@ def get_armbian_release_field(self, field):
85
81
match = re .search (pattern , line )
86
82
if match :
87
83
field_value = match .group (1 )
84
+ release_file .close ()
88
85
except FileNotFoundError :
89
86
pass
90
87
@@ -100,6 +97,7 @@ def get_device_model(self):
100
97
try :
101
98
with open ("/proc/device-tree/model" , "r" ) as model_file :
102
99
model = model_file .read ()
100
+ model_file .close ()
103
101
except FileNotFoundError :
104
102
pass
105
103
@@ -114,6 +112,7 @@ def get_device_compatible(self):
114
112
try :
115
113
with open ("/proc/device-tree/compatible" , "r" ) as model_file :
116
114
model = model_file .read ()
115
+ model_file .close ()
117
116
except FileNotFoundError :
118
117
pass
119
118
@@ -129,21 +128,23 @@ def check_board_asset_tag_value(self):
129
128
try :
130
129
with open ("/sys/devices/virtual/dmi/id/board_asset_tag" , "r" ) as tag_file :
131
130
tag = tag_file .read ().strip ()
131
+ tag_file .close ()
132
132
except FileNotFoundError :
133
133
pass
134
134
135
135
return tag
136
136
137
137
def check_board_name_value (self ):
138
138
"""
139
- Search /sys/devices/virtual/dmi/id for the device model and return its value, if found,
139
+ Search /sys/devices/virtual/dmi/id for the board name and return its value, if found,
140
140
otherwise None. Debian/ubuntu based
141
141
"""
142
142
board_name = None
143
143
144
144
try :
145
145
with open ("/sys/devices/virtual/dmi/id/board_name" , "r" ) as board_name_file :
146
146
board_name = board_name_file .read ().strip ()
147
+ board_name .close ()
147
148
except FileNotFoundError :
148
149
pass
149
150
0 commit comments