From 66e18834da3fbaa0008bbb4896b4bd575bfd844d Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Wed, 1 Feb 2023 14:35:42 -0700 Subject: [PATCH 1/2] boot-qemu.py: Use more specific exception class New pylint warns: boot-qemu.py:401:12: W0719: Raising too general exception: Exception (broad-exception-raised) boot-qemu.py:431:16: W0719: Raising too general exception: Exception (broad-exception-raised) The type of exception really does not matter, as we do not expect this script to be called, so the exception will never be caught. However, it is easy to silence this by switching to a more specific exception. FileNotFoundError is descriptive so use this exception to silence the warning. Signed-off-by: Nathan Chancellor --- boot-qemu.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/boot-qemu.py b/boot-qemu.py index eaa86a6..4f221c9 100755 --- a/boot-qemu.py +++ b/boot-qemu.py @@ -398,7 +398,8 @@ def get_efi_args(guest_arch): for efi_img_location in efi_img_locations[guest_arch]: if efi_img_location is None: - raise Exception(f"edk2 could not be found for {guest_arch}!") + raise FileNotFoundError( + f"edk2 could not be found for {guest_arch}!") efi_img = Path("/usr/share", efi_img_location) if efi_img.exists(): break @@ -428,7 +429,7 @@ def get_efi_args(guest_arch): ] for efi_vars_location in efi_vars_locations: if efi_vars_location is None: - raise Exception("OVMF_VARS.fd could not be found!") + raise FileNotFoundError("OVMF_VARS.fd could not be found!") efi_vars = Path('/usr/share', efi_vars_location) if efi_vars.exists(): break From 0709eae174f22ea61e410614857d1e197b29f864 Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Wed, 1 Feb 2023 14:39:16 -0700 Subject: [PATCH 2/2] boot-qemu.py: Use context manager for pathlib open() calls New pylint warns: boot-qemu.py:413:8: R1732: Consider using 'with' for resource-allocating operations (consider-using-with) boot-qemu.py:418:8: R1732: Consider using 'with' for resource-allocating operations (consider-using-with) We do not expect these calls to fail but the refactoring is simple to silence the warning. Signed-off-by: Nathan Chancellor --- boot-qemu.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/boot-qemu.py b/boot-qemu.py index 4f221c9..c108338 100755 --- a/boot-qemu.py +++ b/boot-qemu.py @@ -411,12 +411,14 @@ def get_efi_args(guest_arch): efi_img_qemu = base_folder.joinpath("images", guest_arch, "efi.img") shutil.copyfile(efi_img, efi_img_qemu) - efi_img_qemu.open(mode="r+b").truncate(efi_img_size) + with efi_img_qemu.open(mode="r+b") as file: + file.truncate(efi_img_size) efi_vars_qemu = base_folder.joinpath("images", guest_arch, "efivars.img") efi_vars_qemu.unlink(missing_ok=True) - efi_vars_qemu.open(mode="xb").truncate(efi_img_size) + with efi_vars_qemu.open(mode="xb") as file: + file.truncate(efi_img_size) elif guest_arch == "x86_64": efi_img_qemu = efi_img # This is just usable, it is marked read only