@@ -48,11 +48,10 @@ 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 ()
52
- for line in cpuinfo :
53
- match = re .search (pattern , line , flags = re .IGNORECASE )
54
- if match :
55
- return match .group (1 )
51
+ for line in cpuinfo :
52
+ match = re .search (pattern , line , flags = re .IGNORECASE )
53
+ if match :
54
+ return match .group (1 )
56
55
return None
57
56
58
57
def check_dt_compatible_value (self , value ):
@@ -82,7 +81,6 @@ def get_armbian_release_field(self, field):
82
81
match = re .search (pattern , line )
83
82
if match :
84
83
field_value = match .group (1 )
85
- release_file .close ()
86
84
except FileNotFoundError :
87
85
pass
88
86
@@ -93,60 +91,44 @@ def get_device_model(self):
93
91
Search /proc/device-tree/model for the device model and return its value, if found,
94
92
otherwise None.
95
93
"""
96
- model = None
97
-
98
94
try :
99
95
with open ("/proc/device-tree/model" , "r" ) as model_file :
100
- model = model_file .read ()
101
- model_file .close ()
96
+ return model_file .read ()
102
97
except FileNotFoundError :
103
98
pass
104
-
105
- return model
99
+ return None
106
100
107
101
def get_device_compatible (self ):
108
102
"""
109
103
Search /proc/device-tree/compatible for the compatible chip name.
110
104
"""
111
- model = None
112
-
113
105
try :
114
106
with open ("/proc/device-tree/compatible" , "r" ) as model_file :
115
- model = model_file .read ()
116
- model_file .close ()
107
+ return model_file .read ()
117
108
except FileNotFoundError :
118
109
pass
119
-
120
- return model
110
+ return None
121
111
122
112
def check_board_asset_tag_value (self ):
123
113
"""
124
114
Search /sys/devices/virtual/dmi/id for the device model and return its value, if found,
125
115
otherwise None.
126
116
"""
127
- tag = None
128
-
129
117
try :
130
118
with open ("/sys/devices/virtual/dmi/id/board_asset_tag" , "r" ) as tag_file :
131
- tag = tag_file .read ().strip ()
132
- tag_file .close ()
119
+ return tag_file .read ().strip ()
133
120
except FileNotFoundError :
134
121
pass
135
-
136
- return tag
122
+ return None
137
123
138
124
def check_board_name_value (self ):
139
125
"""
140
126
Search /sys/devices/virtual/dmi/id for the board name and return its value, if found,
141
127
otherwise None. Debian/ubuntu based
142
128
"""
143
- board_name = None
144
-
145
129
try :
146
130
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 ()
131
+ return board_name_file .read ().strip ()
149
132
except FileNotFoundError :
150
133
pass
151
-
152
- return board_name
134
+ return None
0 commit comments