More fixes for Python 3 compatibility (#13008)

* More fixes for Python 3 compatibility

* Workaround if the six module is not pip installed

* Lose the semicolons
This commit is contained in:
Christian Clauss
2019-12-19 11:05:55 +01:00
committed by Julian Oes
parent 2a848c365c
commit 6dc55f97d4
14 changed files with 107 additions and 105 deletions

View File

@@ -53,6 +53,13 @@ try:
except ImportError:
raise ImportError(
"Failed to import yaml. You may need to install it with 'sudo pip install pyyaml'")
try:
from six.moves import input
except ImportError:
try:
input = raw_input # Python 2
except NameError:
pass # Python 3
def check_rtps_id_uniqueness(classifier):
@@ -281,9 +288,9 @@ if agent == False and client == False:
if del_tree:
if agent:
_continue = str(raw_input("\nFiles in " + agent_out_dir +
" will be erased, continue?[Y/n]\n"))
if _continue == "N" or _continue == "n":
_continue = str(input("\nFiles in " + agent_out_dir +
" will be erased, continue?[Y/n]\n"))
if _continue.strip() in ("N", "n"):
print("Aborting execution...")
exit(-1)
else:
@@ -291,9 +298,9 @@ if del_tree:
shutil.rmtree(agent_out_dir)
if client:
_continue = str(raw_input(
_continue = str(input(
"\nFiles in " + client_out_dir + " will be erased, continue?[Y/n]\n"))
if _continue == "N" or _continue == "n":
if _continue.strip() in ("N", "n"):
print("Aborting execution...")
exit(-1)
else:

View File

@@ -35,6 +35,7 @@
import sys
import os
import argparse
import errno
import yaml
import re
import difflib

View File

@@ -3,10 +3,12 @@
Script to read an yaml file containing the RTPS message IDs and update the naming convention to PascalCase
"""
import errno
import os
import yaml
import sys
import argparse
import six
__author__ = 'PX4 Development Team'
__copyright__ = \
@@ -91,14 +93,8 @@ def update_dict(list):
if verbose:
num_of_msgs = 0
for i, dictionary in enumerate(list["rtps"]):
# implementation depends on the Python version being used
if sys.version_info[0] < 3:
dict = {k: v.title().replace('_', '') if isinstance(
v, basestring) else v for k, v in dictionary.iteritems()}
else:
dict = {k: v.title().replace('_', '') if isinstance(
v, str) else v for k, v in dictionary.items()}
list["rtps"][i] = dict
list["rtps"][i] = {k: v.title().replace('_', '') if isinstance(
v, six.string_types) else v for k, v in six.iteritems(dictionary)}
if verbose:
num_of_msgs += 1
if verbose: