move parse_yaml_msg_id_file() definition to generate_microRTPS_bridge.py

This commit is contained in:
TSC21 2018-09-24 15:12:23 +01:00 committed by Beat Küng
parent a50fed1bf9
commit 28521ea77c
2 changed files with 20 additions and 22 deletions

View File

@ -47,6 +47,11 @@ import px_generate_uorb_topic_helper
import subprocess
import glob
import errno
try:
import yaml
except ImportError:
raise ImportError(
"Failed to import yaml. You may need to install it with 'sudo pip install pyyaml'")
def get_absolute_path(arg_parse_dir):
@ -63,6 +68,20 @@ def get_absolute_path(arg_parse_dir):
return dir
def parse_yaml_msg_id_file(yaml_file):
"""
Parses a yaml file into a dict
"""
try:
with open(yaml_file, 'r') as f:
return yaml.load(f)
except OSError as e:
if e.errno == errno.ENOENT:
raise IOError(errno.ENOENT, os.strerror(errno.ENOENT), yaml_file)
else:
raise
default_client_out = get_absolute_path(
"src/modules/micrortps_bridge/micrortps_client")
default_agent_out = get_absolute_path(
@ -186,8 +205,7 @@ if agent and os.path.isdir(os.path.join(agent_out_dir, "idl")):
uorb_templates_dir = os.path.join(msg_folder, args.uorb_templates)
urtps_templates_dir = os.path.join(msg_folder, args.urtps_templates)
# parse yaml file into a map of ids
rtps_ids = px_generate_uorb_topic_helper.parse_yaml_msg_id_file(
os.path.join(msg_folder, args.yaml_file))
rtps_ids = parse_yaml_msg_id_file(os.path.join(msg_folder, args.yaml_file))
uRTPS_CLIENT_TEMPL_FILE = 'microRTPS_client.cpp.template'

View File

@ -41,11 +41,6 @@ precompiled and thus message generation will be much faster
import os
import errno
try:
import yaml
except ImportError:
raise ImportError(
"Failed to import yaml. You may need to install it with 'sudo pip install pyyaml")
import genmsg.msgs
import gencpp
@ -351,21 +346,6 @@ def print_field_def(field):
print('\t%s%s%s %s%s;%s' % (type_prefix, type_px4, type_appendix, field.name,
array_size, comment))
def parse_yaml_msg_id_file(yaml_file):
"""
Parses a yaml file into a dict
"""
try:
with open(yaml_file, 'r') as f:
return yaml.load(f)
except OSError as e:
if e.errno == errno.ENOENT:
raise IOError(errno.ENOENT, os.strerror(errno.ENOENT), yaml_file)
else:
raise
def rtps_message_id(msg_id_map, message):
"""
Get RTPS ID of uORB message