Skip to content

Remove unecessary file close #155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 12 additions & 30 deletions adafruit_platformdetect/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,10 @@ def get_cpuinfo_field(self, field):

with open("/proc/cpuinfo", "r") as infile:
cpuinfo = infile.read().split("\n")
infile.close()
for line in cpuinfo:
match = re.search(pattern, line, flags=re.IGNORECASE)
if match:
return match.group(1)
for line in cpuinfo:
match = re.search(pattern, line, flags=re.IGNORECASE)
if match:
return match.group(1)
return None

def check_dt_compatible_value(self, value):
Expand Down Expand Up @@ -82,7 +81,6 @@ def get_armbian_release_field(self, field):
match = re.search(pattern, line)
if match:
field_value = match.group(1)
release_file.close()
except FileNotFoundError:
pass

Expand All @@ -93,60 +91,44 @@ def get_device_model(self):
Search /proc/device-tree/model for the device model and return its value, if found,
otherwise None.
"""
model = None

try:
with open("/proc/device-tree/model", "r") as model_file:
model = model_file.read()
model_file.close()
return model_file.read()
except FileNotFoundError:
pass

return model
return None

def get_device_compatible(self):
"""
Search /proc/device-tree/compatible for the compatible chip name.
"""
model = None

try:
with open("/proc/device-tree/compatible", "r") as model_file:
model = model_file.read()
model_file.close()
return model_file.read()
except FileNotFoundError:
pass

return model
return None

def check_board_asset_tag_value(self):
"""
Search /sys/devices/virtual/dmi/id for the device model and return its value, if found,
otherwise None.
"""
tag = None

try:
with open("/sys/devices/virtual/dmi/id/board_asset_tag", "r") as tag_file:
tag = tag_file.read().strip()
tag_file.close()
return tag_file.read().strip()
except FileNotFoundError:
pass

return tag
return None

def check_board_name_value(self):
"""
Search /sys/devices/virtual/dmi/id for the board name and return its value, if found,
otherwise None. Debian/ubuntu based
"""
board_name = None

try:
with open("/sys/devices/virtual/dmi/id/board_name", "r") as board_name_file:
board_name = board_name_file.read().strip()
board_name.close()
return board_name_file.read().strip()
except FileNotFoundError:
pass

return board_name
return None