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