From bec09b9a5720d5aa75e41d987bbcd690c470622a Mon Sep 17 00:00:00 2001 From: Pierre Kancir Date: Tue, 8 Nov 2016 12:06:05 +0100 Subject: [PATCH] autotest: python3 support --- Tools/autotest/apmrover2.py | 4 ++-- Tools/autotest/arducopter.py | 6 +++--- Tools/autotest/arduplane.py | 4 ++-- Tools/autotest/autotest.py | 2 +- Tools/autotest/common.py | 1 + Tools/autotest/dump_logs.py | 2 +- Tools/autotest/fakepos.py | 2 +- Tools/autotest/jsb_sim/runsim.py | 2 +- Tools/autotest/param_metadata/param_parse.py | 2 +- Tools/autotest/param_metadata/rstemit.py | 4 ++-- Tools/autotest/pysim/fdpexpect.py | 2 +- Tools/autotest/pysim/rotmat.py | 2 +- Tools/autotest/pysim/testwind.py | 2 +- Tools/autotest/pysim/util.py | 13 +++++++++---- Tools/autotest/quadplane.py | 4 ++-- 15 files changed, 29 insertions(+), 23 deletions(-) diff --git a/Tools/autotest/apmrover2.py b/Tools/autotest/apmrover2.py index cb65d0c9f9..5a430a5508 100644 --- a/Tools/autotest/apmrover2.py +++ b/Tools/autotest/apmrover2.py @@ -1,5 +1,5 @@ # drive APMrover2 in SITL - +from __future__ import print_function import os import shutil @@ -188,7 +188,7 @@ def drive_APMrover2(binary, viewerip=None, use_map=False, valgrind=False, gdb=Fa valgrind_log = util.valgrind_log_filepath(binary=binary, model='rover') if os.path.exists(valgrind_log): - os.chmod(valgrind_log, 0644) + os.chmod(valgrind_log, 0o644) shutil.copy(valgrind_log, util.reltopdir("../buildlogs/APMrover2-valgrind.log")) if failed: diff --git a/Tools/autotest/arducopter.py b/Tools/autotest/arducopter.py index ce1910d056..b45e59012d 100644 --- a/Tools/autotest/arducopter.py +++ b/Tools/autotest/arducopter.py @@ -6,7 +6,7 @@ # switch 4 = Auto # switch 5 = Loiter # switch 6 = Stabilize - +from __future__ import print_function import math import os import shutil @@ -1291,7 +1291,7 @@ def fly_ArduCopter(binary, viewerip=None, use_map=False, valgrind=False, gdb=Fal valgrind_log = util.valgrind_log_filepath(binary=binary, model='+') if os.path.exists(valgrind_log): - os.chmod(valgrind_log, 0644) + os.chmod(valgrind_log, 0o644) shutil.copy(valgrind_log, util.reltopdir("../buildlogs/ArduCopter-valgrind.log")) # [2014/05/07] FC Because I'm doing a cross machine build (source is on host, build is on guest VM) I cannot hard link @@ -1418,7 +1418,7 @@ def fly_CopterAVC(binary, viewerip=None, use_map=False, valgrind=False, gdb=Fals valgrind_log = util.valgrind_log_filepath(binary=binary, model='heli') if os.path.exists(valgrind_log): - os.chmod(valgrind_log, 0644) + os.chmod(valgrind_log, 0o644) shutil.copy(valgrind_log, util.reltopdir("../buildlogs/Helicopter-valgrind.log")) if failed: diff --git a/Tools/autotest/arduplane.py b/Tools/autotest/arduplane.py index bdc76c1df0..1c454ee269 100644 --- a/Tools/autotest/arduplane.py +++ b/Tools/autotest/arduplane.py @@ -1,5 +1,5 @@ # Fly ArduPlane in SITL - +from __future__ import print_function import math import os import shutil @@ -565,7 +565,7 @@ def fly_ArduPlane(binary, viewerip=None, use_map=False, valgrind=False, gdb=Fals valgrind_log = util.valgrind_log_filepath(binary=binary, model='plane-elevrev') if os.path.exists(valgrind_log): - os.chmod(valgrind_log, 0644) + os.chmod(valgrind_log, 0o644) shutil.copy(valgrind_log, util.reltopdir("../buildlogs/ArduPlane-valgrind.log")) if failed: diff --git a/Tools/autotest/autotest.py b/Tools/autotest/autotest.py index 66cebdf45e..6fce9aaac1 100755 --- a/Tools/autotest/autotest.py +++ b/Tools/autotest/autotest.py @@ -3,7 +3,7 @@ APM automatic test suite Andrew Tridgell, October 2011 """ - +from __future__ import print_function import atexit import fnmatch import glob diff --git a/Tools/autotest/common.py b/Tools/autotest/common.py index ec87bea978..ba9a40fccd 100644 --- a/Tools/autotest/common.py +++ b/Tools/autotest/common.py @@ -1,3 +1,4 @@ +from __future__ import print_function import math import time diff --git a/Tools/autotest/dump_logs.py b/Tools/autotest/dump_logs.py index 44c75d99a2..b3c8528824 100755 --- a/Tools/autotest/dump_logs.py +++ b/Tools/autotest/dump_logs.py @@ -3,7 +3,7 @@ dump flash logs from SITL Andrew Tridgell, April 2013 """ - +from __future__ import print_function import optparse import os import sys diff --git a/Tools/autotest/fakepos.py b/Tools/autotest/fakepos.py index 9e62661d9b..c6a2846a2e 100755 --- a/Tools/autotest/fakepos.py +++ b/Tools/autotest/fakepos.py @@ -1,5 +1,5 @@ #!/usr/bin/env python - +from __future__ import print_function import errno import socket import struct diff --git a/Tools/autotest/jsb_sim/runsim.py b/Tools/autotest/jsb_sim/runsim.py index cf4f12ece0..439dee334f 100755 --- a/Tools/autotest/jsb_sim/runsim.py +++ b/Tools/autotest/jsb_sim/runsim.py @@ -2,7 +2,7 @@ """ Run a jsbsim model as a child process. """ - +from __future__ import print_function import atexit import errno import fdpexpect diff --git a/Tools/autotest/param_metadata/param_parse.py b/Tools/autotest/param_metadata/param_parse.py index 315c7d4638..927ddb50b3 100755 --- a/Tools/autotest/param_metadata/param_parse.py +++ b/Tools/autotest/param_metadata/param_parse.py @@ -1,5 +1,5 @@ #!/usr/bin/env python - +from __future__ import print_function import glob import os import re diff --git a/Tools/autotest/param_metadata/rstemit.py b/Tools/autotest/param_metadata/rstemit.py index 403aa9081a..da5b7f8db8 100644 --- a/Tools/autotest/param_metadata/rstemit.py +++ b/Tools/autotest/param_metadata/rstemit.py @@ -1,5 +1,5 @@ #!/usr/bin/env python - +from __future__ import print_function import re from param import known_param_fields from emit import Emit @@ -254,7 +254,7 @@ def table_test(): print(e.tablify([["A", "B"], ["C", "D"]])) print("Test 2") - print e.tablify([["A", "B"], ["CD\nE", "FG"]]) + print(e.tablify([["A", "B"], ["CD\nE", "FG"]])) print("Test 3") print(e.tablify([["A", "B"], ["CD\nEF", "GH"]], rowheadings=["r1", "row2"])) diff --git a/Tools/autotest/pysim/fdpexpect.py b/Tools/autotest/pysim/fdpexpect.py index c1f5059077..4ffd94688d 100644 --- a/Tools/autotest/pysim/fdpexpect.py +++ b/Tools/autotest/pysim/fdpexpect.py @@ -3,7 +3,7 @@ So you are responsible for opening and close the file descriptor. $Id: fdpexpect.py 505 2007-12-26 21:33:50Z noah $ """ - +from __future__ import print_function import os from pexpect import ExceptionPexpect, spawn diff --git a/Tools/autotest/pysim/rotmat.py b/Tools/autotest/pysim/rotmat.py index 0e042208da..ef3eaa7104 100644 --- a/Tools/autotest/pysim/rotmat.py +++ b/Tools/autotest/pysim/rotmat.py @@ -21,7 +21,7 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA """ - +from __future__ import print_function from math import acos, asin, atan2, cos, pi, radians, sin, sqrt diff --git a/Tools/autotest/pysim/testwind.py b/Tools/autotest/pysim/testwind.py index a4b0ba98a6..92934bff8b 100755 --- a/Tools/autotest/pysim/testwind.py +++ b/Tools/autotest/pysim/testwind.py @@ -2,7 +2,7 @@ """ simple test of wind generation code """ - +from __future__ import print_function import time import util from rotmat import Vector3 diff --git a/Tools/autotest/pysim/util.py b/Tools/autotest/pysim/util.py index bac35c28d5..746846779c 100644 --- a/Tools/autotest/pysim/util.py +++ b/Tools/autotest/pysim/util.py @@ -1,3 +1,4 @@ +from __future__ import print_function import math import os import random @@ -9,8 +10,12 @@ from subprocess import PIPE, Popen, call, check_call import pexpect -from rotmat import Matrix3, Vector3 +from . rotmat import Matrix3, Vector3 +if (sys.version_info[0] >= 3): + ENCODING = 'ascii' +else: + ENCODING = None def m2ft(x): """Meters to feet.""" @@ -211,7 +216,7 @@ def start_SITL(binary, valgrind=False, gdb=False, wipe=False, synthetic_clock=Tr print("Running: %s" % cmd_as_shell(cmd)) first = cmd[0] rest = cmd[1:] - child = pexpect.spawn(first, rest, logfile=sys.stdout, timeout=5) + child = pexpect.spawn(first, rest, logfile=sys.stdout, encoding=ENCODING, timeout=5) delaybeforesend = 0 pexpect_autoclose(child) # give time for parameters to properly setup @@ -224,7 +229,7 @@ def start_SITL(binary, valgrind=False, gdb=False, wipe=False, synthetic_clock=Tr # TODO: have a SITL-compiled ardupilot able to have its # console on an output fd. else: - child.expect(u'Waiting for connection', timeout=300) + child.expect('Waiting for connection', timeout=300) return child @@ -242,7 +247,7 @@ def start_MAVProxy_SITL(atype, aircraft=None, setup=False, master='tcp:127.0.0.1 cmd += ' --aircraft=%s' % aircraft if options is not None: cmd += ' ' + options - ret = pexpect.spawn(cmd, logfile=logfile, timeout=60) + ret = pexpect.spawn(cmd, logfile=logfile, encoding=ENCODING, timeout=60) ret.delaybeforesend = 0 pexpect_autoclose(ret) return ret diff --git a/Tools/autotest/quadplane.py b/Tools/autotest/quadplane.py index 1a69ee222d..cf5cddfaf4 100644 --- a/Tools/autotest/quadplane.py +++ b/Tools/autotest/quadplane.py @@ -1,5 +1,5 @@ # fly ArduPlane QuadPlane in SITL - +from __future__ import print_function import os import pexpect import shutil @@ -126,7 +126,7 @@ def fly_QuadPlane(binary, viewerip=None, use_map=False, valgrind=False, gdb=Fals valgrind_log = util.valgrind_log_filepath(binary=binary, model='quadplane') if os.path.exists(valgrind_log): - os.chmod(valgrind_log, 0644) + os.chmod(valgrind_log, 0o644) shutil.copy(valgrind_log, util.reltopdir("../buildlogs/QuadPlane-valgrind.log")) if failed: