diff --git a/boot-qemu.py b/boot-qemu.py index eaa86a6..c108338 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 @@ -410,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 @@ -428,7 +431,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