From 502db7928ca95dde7373083ecfaa0e14e8930315 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Tue, 5 Mar 2024 23:34:57 +1100 Subject: [PATCH] mavproxy.py: add option to not run startup scripts for future use in ArduPilot's autotest --- MAVProxy/mavproxy.py | 48 +++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/MAVProxy/mavproxy.py b/MAVProxy/mavproxy.py index 6c2fe2b0f7..8673af8d74 100644 --- a/MAVProxy/mavproxy.py +++ b/MAVProxy/mavproxy.py @@ -1231,6 +1231,30 @@ def set_mav_version(mav10, mav20, autoProtocol, mavversionArg): os.environ['MAVLINK20'] = '1' mavversion = "2" +def run_startup_scripts(): + start_scripts = [] + if not opts.setup: + if 'HOME' in os.environ: + start_scripts.append(os.path.join(os.environ['HOME'], ".mavinit.scr")) + start_script = mp_util.dot_mavproxy("mavinit.scr") + start_scripts.append(start_script) + if (mpstate.settings.state_basedir is not None and + opts.aircraft is not None): + start_script = os.path.join(mpstate.aircraft_dir, "mavinit.scr") + start_scripts.append(start_script) + for start_script in start_scripts: + if os.path.exists(start_script): + print("Running script (%s)" % (start_script)) + run_script(start_script) + + if opts.aircraft is not None: + start_script = os.path.join(opts.aircraft, "mavinit.scr") + if os.path.exists(start_script): + run_script(start_script) + else: + print("no script %s" % start_script) + + if __name__ == '__main__': from optparse import OptionParser parser = OptionParser("mavproxy.py [options]") @@ -1301,6 +1325,7 @@ def set_mav_version(mav10, mav20, autoProtocol, mavversionArg): parser.add_option("--version", action='store_true', help="version information") parser.add_option("--default-modules", default="log,signing,wp,rally,fence,ftp,param,relay,tuneopt,arm,mode,calibration,rc,auxopt,misc,cmdlong,battery,terrain,output,adsb,layout", help='default module list') parser.add_option("--udp-timeout",dest="udp_timeout", default=0.0, type='float', help="Timeout for udp clients in seconds") + parser.add_option("--no-startup-scripts", action='store_true', help="Do not run .mavinit.scr and other startup scripts") (opts, args) = parser.parse_args() if len(args) != 0: @@ -1482,27 +1507,8 @@ def quit_handler(signum = None, frame = None): elif opts.aircraft is not None: mpstate.aircraft_dir = opts.aircraft - start_scripts = [] - if not opts.setup: - if 'HOME' in os.environ: - start_scripts.append(os.path.join(os.environ['HOME'], ".mavinit.scr")) - start_script = mp_util.dot_mavproxy("mavinit.scr") - start_scripts.append(start_script) - if (mpstate.settings.state_basedir is not None and - opts.aircraft is not None): - start_script = os.path.join(mpstate.aircraft_dir, "mavinit.scr") - start_scripts.append(start_script) - for start_script in start_scripts: - if os.path.exists(start_script): - print("Running script (%s)" % (start_script)) - run_script(start_script) - - if opts.aircraft is not None: - start_script = os.path.join(opts.aircraft, "mavinit.scr") - if os.path.exists(start_script): - run_script(start_script) - else: - print("no script %s" % start_script) + if not opts.no_startup_scripts: + run_startup_scripts() if opts.cmd is not None: for cstr in opts.cmd: