Skip to content

Commit

Permalink
Add close() and context management to ubi_file
Browse files Browse the repository at this point in the history
  • Loading branch information
AT0myks committed Jun 1, 2023
1 parent f84a4e3 commit cb8a172
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ubireader/scripts/ubireader_display_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ def main():
if match:
blocks.append(ubi_obj.blocks[block])

ufile_obj.close()

print('\nBlock matches: %s' % len(blocks))

for block in blocks:
Expand Down
3 changes: 3 additions & 0 deletions ubireader/scripts/ubireader_display_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,5 +185,8 @@ def main():
else:
print('Something went wrong to get here.')

ufile_obj.close()


if __name__=='__main__':
main()
2 changes: 2 additions & 0 deletions ubireader/scripts/ubireader_extract_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ def main():
else:
print('Something went wrong to get here.')

ufile_obj.close()


if __name__=='__main__':
main()
3 changes: 3 additions & 0 deletions ubireader/scripts/ubireader_extract_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,5 +167,8 @@ def main():
for block in image.volumes[volume].reader(ubi_obj):
f.write(block)

ufile_obj.close()


if __name__=='__main__':
main()
3 changes: 3 additions & 0 deletions ubireader/scripts/ubireader_list_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,8 @@ def main():
else:
print('Something went wrong to get here.')

ufile_obj.close()


if __name__=='__main__':
main()
3 changes: 3 additions & 0 deletions ubireader/scripts/ubireader_utils_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,5 +343,8 @@ def main():
# Create build scripts.
make_files(ubi_obj, outpath)

ufile_obj.close()


if __name__=='__main__':
main()
7 changes: 7 additions & 0 deletions ubireader/ubi_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ def __init__(self, path, block_size, start_offset=0, end_offset=None):
self._last_read_addr = self._fhandle.tell()
self.is_valid = True

def __enter__(self):
return self

def __exit__(self, exc_type, exc_value, traceback):
self.close()

def _set_start(self, i):
self._start_offset = i
Expand All @@ -105,6 +110,8 @@ def _get_block_size(self):
return self._block_size
block_size = property(_get_block_size)

def close(self):
self._fhandle.close()

def seek(self, offset):
self._fhandle.seek(offset)
Expand Down

0 comments on commit cb8a172

Please sign in to comment.