[PATCH v2 1/1] travis-ci: Fix "ResourceWarning: unclosed file"

This patch gets rid of the warning messages like:
uboot-test-hooks/py/travis-ci/travis_tftp.py:43: ResourceWarning: unclosed file <_io.BufferedReader name='.bm-work/qemu_arm/u-boot.bin'>
Signed-off-by: Cristian Ciocaltea cristian.ciocaltea@gmail.com --- Changes in v2: * The warning line number in the comment relies on Heinrich Schuchardt's work 'travis-ci: provide env__efi_fit_tftp_file', but my initial patch was based on the master version. Even though it is still applicable, to avoid any confusion, I rebased it on Heinrich's latest patch (v2):
https://lists.denx.de/pipermail/u-boot/2019-December/395029.html
py/travis-ci/travis_tftp.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/py/travis-ci/travis_tftp.py b/py/travis-ci/travis_tftp.py index 884823c..f9a44aa 100644 --- a/py/travis-ci/travis_tftp.py +++ b/py/travis-ci/travis_tftp.py @@ -40,8 +40,11 @@ def file2env(file_name, addr=None): ret = { "fn": file_name, "size": os.path.getsize(file_full), - "crc32": hex(binascii.crc32(open(file_full, 'rb').read()) & 0xffffffff)[2:], } + + with open(file_full, 'rb') as fd: + ret["crc32"] = hex(binascii.crc32(fd.read()) & 0xffffffff)[2:] + if addr is not None: ret['addr'] = addr

On 12/30/19 4:49 AM, Cristian Ciocaltea wrote:
This patch gets rid of the warning messages like:
uboot-test-hooks/py/travis-ci/travis_tftp.py:43: ResourceWarning: unclosed file <_io.BufferedReader name='.bm-work/qemu_arm/u-boot.bin'>
Signed-off-by: Cristian Ciocaltea cristian.ciocaltea@gmail.com
Changes in v2:
The warning line number in the comment relies on Heinrich Schuchardt's work 'travis-ci: provide env__efi_fit_tftp_file', but my initial patch was based on the master version. Even though it is still applicable, to avoid any confusion, I rebased it on Heinrich's latest patch (v2):
https://lists.denx.de/pipermail/u-boot/2019-December/395029.html
There's no need to rebase the patch for that kind of thing; the warning is only a reference/example anyway, and the next time someone edits this file after you, the line number will change again, and we can't go back and edit this commit description to patch that up.
diff --git a/py/travis-ci/travis_tftp.py b/py/travis-ci/travis_tftp.py
- with open(file_full, 'rb') as fd:
ret["crc32"] = hex(binascii.crc32(fd.read()) & 0xffffffff)[2:]
Nit: "f" for "file" rather than "fd" for "file descriptor" (usually an integer) would have been a better variable name. No need to resend to change this though.
Reviewed-by: Stephen Warren swarren@nvidia.com

On 12/30/19 9:41 AM, Stephen Warren wrote:
On 12/30/19 4:49 AM, Cristian Ciocaltea wrote:
This patch gets rid of the warning messages like:
uboot-test-hooks/py/travis-ci/travis_tftp.py:43: ResourceWarning: unclosed file <_io.BufferedReader name='.bm-work/qemu_arm/u-boot.bin'>
Signed-off-by: Cristian Ciocaltea cristian.ciocaltea@gmail.com
Changes in v2:
- The warning line number in the comment relies on Heinrich Schuchardt's
work 'travis-ci: provide env__efi_fit_tftp_file', but my initial patch was based on the master version. Even though it is still applicable, to avoid any confusion, I rebased it on Heinrich's latest patch (v2): https://lists.denx.de/pipermail/u-boot/2019-December/395029.html
There's no need to rebase the patch for that kind of thing; the warning is only a reference/example anyway, and the next time someone edits this file after you, the line number will change again, and we can't go back and edit this commit description to patch that up.
diff --git a/py/travis-ci/travis_tftp.py b/py/travis-ci/travis_tftp.py
+ with open(file_full, 'rb') as fd: + ret["crc32"] = hex(binascii.crc32(fd.read()) & 0xffffffff)[2:]
Nit: "f" for "file" rather than "fd" for "file descriptor" (usually an integer) would have been a better variable name. No need to resend to change this though.
Reviewed-by: Stephen Warren swarren@nvidia.com
Oh, somehow I failed to realize that I needed to apply this. It's now applied.

On Wed, Jun 24, 2020 at 02:30:24PM -0600, Stephen Warren wrote:
On 12/30/19 9:41 AM, Stephen Warren wrote:
On 12/30/19 4:49 AM, Cristian Ciocaltea wrote:
This patch gets rid of the warning messages like:
uboot-test-hooks/py/travis-ci/travis_tftp.py:43: ResourceWarning: unclosed file <_io.BufferedReader name='.bm-work/qemu_arm/u-boot.bin'>
Signed-off-by: Cristian Ciocaltea cristian.ciocaltea@gmail.com
Changes in v2:
- The warning line number in the comment relies on Heinrich Schuchardt's
work 'travis-ci: provide env__efi_fit_tftp_file', but my initial patch was based on the master version. Even though it is still applicable, to avoid any confusion, I rebased it on Heinrich's latest patch (v2): https://lists.denx.de/pipermail/u-boot/2019-December/395029.html
There's no need to rebase the patch for that kind of thing; the warning is only a reference/example anyway, and the next time someone edits this file after you, the line number will change again, and we can't go back and edit this commit description to patch that up.
diff --git a/py/travis-ci/travis_tftp.py b/py/travis-ci/travis_tftp.py
+ with open(file_full, 'rb') as fd: + ret["crc32"] = hex(binascii.crc32(fd.read()) & 0xffffffff)[2:]
Nit: "f" for "file" rather than "fd" for "file descriptor" (usually an integer) would have been a better variable name. No need to resend to change this though.
Reviewed-by: Stephen Warren swarren@nvidia.com
Oh, somehow I failed to realize that I needed to apply this. It's now applied.
Great, thanks!
participants (2)
-
Cristian Ciocaltea
-
Stephen Warren