From 7570c1d9eb65dc07851cbbd537081d1e8d4843e7 Mon Sep 17 00:00:00 2001 From: Pierre Kancir Date: Thu, 1 Aug 2024 11:20:15 +0200 Subject: [PATCH] Tools: flake8 sitl-on-hw.py --- Tools/scripts/sitl-on-hardware/sitl-on-hw.py | 32 ++++++++++++-------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/Tools/scripts/sitl-on-hardware/sitl-on-hw.py b/Tools/scripts/sitl-on-hardware/sitl-on-hw.py index 7072fd8cb379da..178b0431be502f 100755 --- a/Tools/scripts/sitl-on-hardware/sitl-on-hw.py +++ b/Tools/scripts/sitl-on-hardware/sitl-on-hw.py @@ -2,17 +2,18 @@ ''' script to build a firmware for SITL-on-hardware see https://ardupilot.org/dev/docs/sim-on-hardware.html + +AP_FLAKE8_CLEAN ''' import subprocess import sys import os import tempfile +from argparse import ArgumentParser sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../../Tools', 'autotest')) -from pysim import vehicleinfo - -from argparse import ArgumentParser +from pysim import vehicleinfo # noqa: E402 vinfo = vehicleinfo.VehicleInfo() @@ -45,17 +46,19 @@ extra_hwdef = None + def run_program(cmd_list): '''run a program from a command list''' print("Running (%s)" % " ".join(cmd_list)) retcode = subprocess.call(cmd_list) if retcode != 0: - print("FAILED: %s" % (' '.join(cmd_list))) - global extra_hwdef - if extra_hwdef is not None: - extra_hwdef.close() - os.unlink(extra_hwdef.name) - sys.exit(1) + print("FAILED: %s" % (' '.join(cmd_list))) + global extra_hwdef + if extra_hwdef is not None: + extra_hwdef.close() + os.unlink(extra_hwdef.name) + sys.exit(1) + frame_options = sorted(vinfo.options[vehicle_map[args.vehicle]]["frames"].keys()) frame_options_string = ' '.join(frame_options) @@ -63,21 +66,26 @@ def run_program(cmd_list): print(f"ERROR: frame must be one of {frame_options_string}") sys.exit(1) + extra_hwdef = tempfile.NamedTemporaryFile(mode='w') extra_defaults = tempfile.NamedTemporaryFile(mode='w') + def hwdef_write(s): '''write to the hwdef temp file''' extra_hwdef.write(s) + def defaults_write(s): '''write to the hwdef temp file''' extra_defaults.write(s) + def sohw_path(fname): '''get path to a file in on-hardware directory''' return os.path.join(os.path.dirname(os.path.realpath(__file__)), fname) + if args.vehicle == "plane": extra_hwdef_base = "plane-extra-hwdef-sitl-on-hw.dat" defaults_base = "plane-default.param" @@ -92,7 +100,7 @@ def sohw_path(fname): defaults_write(open(sohw_path(defaults_base), "r").read() + "\n") if args.defaults: - defaults_write(open(args.defaults,"r").read() + "\n") + defaults_write(open(args.defaults, "r").read() + "\n") if args.simclass: if args.simclass == 'Glider': @@ -133,6 +141,7 @@ def sohw_path(fname): print(f"Error: frame {args.frame} not found in frame_defines") sys.exit(1) + extra_hwdef.flush() extra_defaults.flush() @@ -148,10 +157,9 @@ def sohw_path(fname): build_cmd = ["./waf", waf_vehicle] if args.upload: - build_cmd.append("--upload") + build_cmd.append("--upload") run_program(build_cmd) # cleanup extra_hwdef.close() -