Skip to content

Commit

Permalink
mavproxy.py: add option to not run startup scripts
Browse files Browse the repository at this point in the history
for future use in ArduPilot's autotest
  • Loading branch information
peterbarker committed Mar 5, 2024
1 parent 3192cae commit 502db79
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions MAVProxy/mavproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]")
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 502db79

Please sign in to comment.