Tools: flake8 sitl-on-hw.py

This commit is contained in:
Pierre Kancir 2024-08-01 11:20:15 +02:00 committed by Peter Barker
parent 699dfb5385
commit 53a6c2d045
1 changed files with 20 additions and 12 deletions

View File

@ -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()
@ -47,6 +48,7 @@ args, unknown_args = parser.parse_known_args()
extra_hwdef = None
def run_program(cmd_list):
'''run a program from a command list'''
print("Running (%s)" % " ".join(cmd_list))
@ -59,27 +61,33 @@ def run_program(cmd_list):
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)
if args.frame and args.frame not in frame_options:
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"
@ -135,6 +143,7 @@ if args.frame:
print(f"Error: frame {args.frame} not found in frame_defines")
sys.exit(1)
extra_hwdef.flush()
extra_defaults.flush()
@ -164,4 +173,3 @@ run_program(build_cmd)
# cleanup
extra_hwdef.close()