Пример #1
0
def test_load_msg_from_file():
    from genmsg.msgs import InvalidMsgSpec
    from genmsg.msg_loader import load_msg_from_file, MsgContext
    test_d = get_test_dir()
    test_ros_dir = os.path.join(test_d, 'test_ros', 'msg')
    test_string_path = os.path.join(test_ros_dir, 'TestString.msg')

    msg_context = MsgContext.create_default()
    spec = load_msg_from_file(msg_context, test_string_path,
                              'test_ros/TestString')
    assert spec.full_name == 'test_ros/TestString'
    assert spec.package == 'test_ros'
    assert spec.short_name == 'TestString'
    _validate_TestString(spec)

    # test repeat
    spec_2 = load_msg_from_file(msg_context, test_string_path,
                                'test_ros/TestString')
    assert spec == spec_2
    assert spec.package == spec_2.package
    assert spec.short_name == spec_2.short_name

    # test w/ bad file
    test_bad_path = os.path.join(test_ros_dir, 'Bad.msg')
    try:
        load_msg_from_file(msg_context, test_bad_path, 'test_ros/Bad')
        assert False, "should have raised"
    except InvalidMsgSpec:
        pass

    # supposed to register
    assert msg_context.is_registered('test_ros/TestString'), msg_context
Пример #2
0
def test_load_msg_from_file():
    from genmsg.msgs import InvalidMsgSpec
    from genmsg.msg_loader import load_msg_from_file, MsgContext
    test_d = get_test_dir()
    test_ros_dir = os.path.join(test_d, 'test_ros', 'msg')
    test_string_path = os.path.join(test_ros_dir, 'TestString.msg')

    msg_context = MsgContext.create_default()
    spec = load_msg_from_file(msg_context, test_string_path, 'test_ros/TestString')
    assert spec.full_name == 'test_ros/TestString'
    assert spec.package == 'test_ros'
    assert spec.short_name == 'TestString'
    _validate_TestString(spec)

    # test repeat
    spec_2 = load_msg_from_file(msg_context, test_string_path, 'test_ros/TestString')
    assert spec == spec_2
    assert spec.package == spec_2.package
    assert spec.short_name == spec_2.short_name
    
    # test w/ bad file
    test_bad_path = os.path.join(test_ros_dir, 'Bad.msg')
    try:
        load_msg_from_file(msg_context, test_bad_path, 'test_ros/Bad')
        assert False, "should have raised"
    except InvalidMsgSpec:
        pass
    
    # supposed to register
    assert msg_context.is_registered('test_ros/TestString'), msg_context
Пример #3
0
def parse_message_file(msg_file, msg_name):
    spec = load_msg_from_file(g_msg_context, msg_file, msg_name)
    if is_header_type(spec.full_name):
        # The std_msgs/Header of ROS2 does not contain the `seq` member field
        # that the ROS1 version has. The ROS2 definition should be treated as
        # the canonical one, so we'll remove the `seq` field from this message
        # specification. We make a special case for this because std_msgs/Header
        # usage is so prevalent in downstream message packages.
        seq_index = spec.names.index('seq')
        del spec.names[seq_index]
        del spec.types[seq_index]
        del spec._parsed_fields[seq_index]
    return spec
Пример #4
0
def find_package_info(requested_pkg_name):
    info = PackageInfo(requested_pkg_name)

    share_dir = g_manifest.get_path(requested_pkg_name)

    message_dir = '{}/msg'.format(share_dir)
    if os.path.exists(message_dir):
        for relative_msg_file in os.listdir(message_dir):
            if not relative_msg_file.endswith('.msg'):
                continue

            msg_file = '{}/{}'.format(message_dir, relative_msg_file)

            # Strip off the extension to get the local name of the message type
            msg_subname = relative_msg_file[:-4]

            info.msg_files.append(msg_file)
            msg = load_msg_from_file(
                g_msg_context, msg_file,
                '{}/{}'.format(requested_pkg_name, msg_subname))
            append_msg_dependencies(msg, info.dependencies)

    service_dir = '{}/srv'.format(share_dir)
    if os.path.exists(service_dir):
        for relative_srv_file in os.listdir(service_dir):
            if not relative_srv_file.endswith('.srv'):
                continue

            srv_file = '{}/{}'.format(service_dir, relative_srv_file)

            # Strip off the extension to get the local name of the service type
            srv_subname = relative_srv_file[:-4]

            info.srv_files.append(srv_file)
            srv = load_srv_from_file(
                g_msg_context, srv_file,
                '{}/{}'.format(requested_pkg_name, srv_subname))
            for component in [srv.request, srv.response]:
                append_msg_dependencies(component, info.dependencies)

    return info
Пример #5
0
def test_MsgContext():
    from genmsg.msg_loader import MsgContext, load_msg_from_file
    msg_context = MsgContext()
    assert not msg_context.is_registered('time')
    assert not msg_context.is_registered('duration')

    msg_context = MsgContext.create_default()
    # tripwires
    repr(msg_context)
    str(msg_context)

    assert msg_context.is_registered('time'), msg_context._registered_packages
    assert msg_context.is_registered('duration')

    assert not msg_context.is_registered('test_ros/TestString')
    assert not msg_context.is_registered('Header')

    # start loading stuff into context
    test_d = get_test_dir()
    test_ros_dir = os.path.join(test_d, 'test_ros', 'msg')
    test_string_path = os.path.join(test_ros_dir, 'TestString.msg')
    spec = load_msg_from_file(msg_context, test_string_path,
                              'test_ros/TestString')
    msg_context.register('test_ros/TestString', spec)
    assert msg_context.get_registered('test_ros/TestString') == spec
    try:
        msg_context.get_registered('bad/TestString')
        assert False, 'should have raised'
    except KeyError:
        pass

    assert msg_context.is_registered('test_ros/TestString')

    # test Header
    assert not msg_context.is_registered('Header')
    assert not msg_context.is_registered('std_msgs/Header')

    msg_context.register('std_msgs/Header', spec)
    assert msg_context.is_registered('std_msgs/Header')
Пример #6
0
def test_MsgContext():
    from genmsg.msg_loader import MsgContext, load_msg_from_file

    msg_context = MsgContext()
    assert not msg_context.is_registered("time")
    assert not msg_context.is_registered("duration")

    msg_context = MsgContext.create_default()
    # tripwires
    repr(msg_context)
    str(msg_context)

    assert msg_context.is_registered("time"), msg_context._registered_packages
    assert msg_context.is_registered("duration")

    assert not msg_context.is_registered("test_ros/TestString")
    assert not msg_context.is_registered("Header")

    # start loading stuff into context
    test_d = get_test_dir()
    test_ros_dir = os.path.join(test_d, "test_ros", "msg")
    test_string_path = os.path.join(test_ros_dir, "TestString.msg")
    spec = load_msg_from_file(msg_context, test_string_path, "test_ros/TestString")
    msg_context.register("test_ros/TestString", spec)
    assert msg_context.get_registered("test_ros/TestString") == spec
    try:
        msg_context.get_registered("bad/TestString")
        assert False, "should have raised"
    except KeyError:
        pass

    assert msg_context.is_registered("test_ros/TestString")

    # test Header
    assert not msg_context.is_registered("Header")
    assert not msg_context.is_registered("std_msgs/Header")

    msg_context.register("std_msgs/Header", spec)
    assert msg_context.is_registered("std_msgs/Header")
Пример #7
0
def test_MsgContext():
    from genmsg.msg_loader import MsgContext, load_msg_from_file
    msg_context = MsgContext()
    assert not msg_context.is_registered('time')
    assert not msg_context.is_registered('duration')
    
    msg_context = MsgContext.create_default()
    # tripwires
    repr(msg_context)
    str(msg_context)

    assert msg_context.is_registered('time'), msg_context._registered_packages
    assert msg_context.is_registered('duration')

    assert not msg_context.is_registered('test_ros/TestString')
    assert not msg_context.is_registered('Header')
    
    # start loading stuff into context
    test_d = get_test_dir()
    test_ros_dir = os.path.join(test_d, 'test_ros', 'msg')
    test_string_path = os.path.join(test_ros_dir, 'TestString.msg')
    spec = load_msg_from_file(msg_context, test_string_path, 'test_ros/TestString')
    msg_context.register('test_ros/TestString', spec)
    assert msg_context.get_registered('test_ros/TestString') == spec
    try:
        msg_context.get_registered('bad/TestString')
        assert False, 'should have raised'
    except KeyError:
        pass
    
    assert msg_context.is_registered('test_ros/TestString')

    # test Header
    assert not msg_context.is_registered('Header')
    assert not msg_context.is_registered('std_msgs/Header')
    
    msg_context.register('std_msgs/Header', spec)
    assert msg_context.is_registered('std_msgs/Header')
Пример #8
0
import sys

from genmsg import EXT_MSG, EXT_SRV, MsgContext
from genmsg.gentools import compute_full_type_name
from genmsg.msg_loader import load_msg_from_file, load_srv_from_file
from genmsg.msgs import bare_msg_type, is_builtin, resolve_type

pkg_name = sys.argv[1]
msg_file = sys.argv[2]
deps = sys.argv[3].split(':') if len(sys.argv) > 3 else []

msg_context = MsgContext.create_default()
full_type_name = compute_full_type_name(pkg_name, os.path.basename(msg_file))

if msg_file.endswith(EXT_MSG):
    spec = load_msg_from_file(msg_context, msg_file, full_type_name)
    unresolved_types = spec.types
elif msg_file.endswith(EXT_SRV):
    spec = load_srv_from_file(msg_context, msg_file, full_type_name)
    unresolved_types = spec.request.types + spec.response.types
else:
    print("Processing file: '%s' - unknown file extension" % msg_file, file=sys.stderr)
    sys.exit(1)

package_context = spec.package
for unresolved_type in unresolved_types:
    bare_type = bare_msg_type(unresolved_type)
    resolved_type = resolve_type(bare_type, package_context)
    if not is_builtin(resolved_type) and resolved_type not in deps:
        print("The dependencies of the message/service '%s' have changed. Please rerun cmake." % spec.full_name, file=sys.stderr)
        sys.exit(1)
import sys

from genmsg import EXT_MSG, EXT_SRV, MsgContext
from genmsg.gentools import compute_full_type_name
from genmsg.msg_loader import load_msg_from_file, load_srv_from_file
from genmsg.msgs import bare_msg_type, is_builtin, resolve_type

pkg_name = sys.argv[1]
msg_file = sys.argv[2]
deps = sys.argv[3].split(':') if len(sys.argv) > 3 else []

msg_context = MsgContext.create_default()
full_type_name = compute_full_type_name(pkg_name, os.path.basename(msg_file))

if msg_file.endswith(EXT_MSG):
    spec = load_msg_from_file(msg_context, msg_file, full_type_name)
    unresolved_types = spec.types
elif msg_file.endswith(EXT_SRV):
    spec = load_srv_from_file(msg_context, msg_file, full_type_name)
    unresolved_types = spec.request.types + spec.response.types
else:
    print("Processing file: '%s' - unknown file extension" % msg_file,
          file=sys.stderr)
    sys.exit(1)

package_context = spec.package
for unresolved_type in unresolved_types:
    bare_type = bare_msg_type(unresolved_type)
    resolved_type = resolve_type(bare_type, package_context)
    if not is_builtin(resolved_type) and resolved_type not in deps:
        print(