Skip to content

Commit

Permalink
Merge pull request #65 from bridadan/catch-oserror
Browse files Browse the repository at this point in the history
Catch OSError when listing files in mount point
  • Loading branch information
PrzemekWirkus committed Mar 30, 2016
2 parents 85277ef + 05ef921 commit 3c4ef60
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions mbed_lstools/lstools_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,15 +487,20 @@ def get_mbed_htm(self, mount_point):
def get_mbed_htm_lines(self, mount_point):
result = []
if mount_point:
for mount_point_file in [f for f in listdir(mount_point) if isfile(join(mount_point, f))]:
if mount_point_file.lower() == self.MBED_HTM_NAME:
mbed_htm_path = os.path.join(mount_point, mount_point_file)
try:
with open(mbed_htm_path, 'r') as f:
result = f.readlines()
except IOError:
if self.DEBUG_FLAG:
self.debug(self.get_mbed_htm_target_id.__name__, ('Failed to open file', mbed_htm_path))
try:
for mount_point_file in [f for f in listdir(mount_point) if isfile(join(mount_point, f))]:
if mount_point_file.lower() == self.MBED_HTM_NAME:
mbed_htm_path = os.path.join(mount_point, mount_point_file)
try:
with open(mbed_htm_path, 'r') as f:
result = f.readlines()
except IOError:
if self.DEBUG_FLAG:
self.debug(self.get_mbed_htm_target_id.__name__, ('Failed to open file', mbed_htm_path))
except OSError:
if self.DEBUG_FLAG:
self.debug(self.get_mbed_htm_target_id.__name__, ('Failed to list mount point', mount_point))

return result

def get_details_txt(self, mount_point):
Expand Down

0 comments on commit 3c4ef60

Please sign in to comment.