diff --git a/gns3server/compute/iou/utils/iou_export.py b/gns3server/compute/iou/utils/iou_export.py index f3b67d039..3ee1d2f5c 100644 --- a/gns3server/compute/iou/utils/iou_export.py +++ b/gns3server/compute/iou/utils/iou_export.py @@ -204,9 +204,8 @@ if __name__ == "__main__": args = parser.parse_args() try: - fd = open(args.nvram, "rb") - nvram = fd.read() - fd.close() + with open(args.nvram, "rb") as fd: + nvram = fd.read() except OSError as err: sys.stderr.write(f"Error reading file: {err}\n") sys.exit(1) @@ -218,16 +217,14 @@ if __name__ == "__main__": sys.exit(3) try: - fd = open(args.startup, "wb") - fd.write(startup) - fd.close() + with open(args.startup, "wb") as out: + out.write(startup) if args.private is not None: if private is None: sys.stderr.write("Warning: No private config\n") else: - fd = open(args.private, "wb") - fd.write(private) - fd.close() + with open(args.private, "wb") as out: + out.write(private) except OSError as err: sys.stderr.write(f"Error writing file: {err}\n") sys.exit(1) diff --git a/gns3server/compute/iou/utils/iou_import.py b/gns3server/compute/iou/utils/iou_import.py index 361ed0c54..1dbcbfba4 100644 --- a/gns3server/compute/iou/utils/iou_import.py +++ b/gns3server/compute/iou/utils/iou_import.py @@ -197,22 +197,17 @@ if __name__ == "__main__": parser.add_argument("private", metavar="private-config", nargs="?", help="private configuration") args = parser.parse_args() + nvram: bytes | None = None + private: bytes | None = None try: if args.create is None: - fd = open(args.nvram, "rb") - nvram = fd.read() - fd.close() - else: - nvram = None - fd = open(args.startup, "rb") - startup = fd.read() - fd.close() - if args.private is None: - private = None - else: - fd = open(args.private, "rb") - private = fd.read() - fd.close() + with open(args.nvram, "rb") as fd: + nvram = fd.read() + with open(args.startup, "rb") as fd: + startup = fd.read() + if args.private is not None: + with open(args.private, "rb") as fd: + private = fd.read() except OSError as err: sys.stderr.write(f"Error reading file: {err}\n") sys.exit(1) @@ -224,9 +219,8 @@ if __name__ == "__main__": sys.exit(3) try: - fd = open(args.nvram, "wb") - fd.write(nvram) - fd.close() + with open(args.nvram, "wb") as out: + out.write(nvram) except OSError as err: sys.stderr.write(f"Error writing file: {err}\n") sys.exit(1) diff --git a/pyproject.toml b/pyproject.toml index b6cf0462f..63d910a26 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -355,8 +355,6 @@ module = [ "gns3server.api.routes.controller.snapshots", # 1 "gns3server.api.routes.controller.templates", # 10 "gns3server.api.routes.controller.users", # 14 - "gns3server.compute.iou.utils.iou_export", # 2 - "gns3server.compute.iou.utils.iou_import", # 2 "gns3server.compute.virtualbox.virtualbox_vm", # 1 "gns3server.compute.vpcs.vpcs_vm", # 2 "gns3server.controller.appliance", # 2