def _rosservice_cmd_call(argv):
    """
    Parse 'call' command arguments and run command.  Will cause a system
    exit if command-line argument parsing fails.
    @param argv: command-line arguments
    @type  argv: [str]
    @raise ROSServiceException: if call command cannot be executed
    """
    try:
        import yaml
    except ImportError as e:
        raise ROSServiceException(
            "Cannot import yaml. Please make sure the pyyaml system dependency is installed"
        )

    args = argv[2:]
    parser = OptionParser(usage="usage: %prog call /service [args...]",
                          prog=NAME)
    parser.add_option("-v",
                      dest="verbose",
                      default=False,
                      action="store_true",
                      help="print verbose output")
    parser.add_option("--wait",
                      dest="wait",
                      default=False,
                      action="store_true",
                      help="wait for service to be advertised")

    (options, args) = parser.parse_args(args)
    if len(args) == 0:
        parser.error("service must be specified")
    service_name = args[0]

    if options.wait:
        # have to make sure there is at least a master as the error
        # behavior of all ros online tools is to fail if there is no
        # master
        master = _get_master()
        try:
            service_uri = master.getPid()
        except socket.error:
            raise ROSServiceIOException("Unable to communicate with master!")
        rospy.wait_for_service(service_name)

    # optimization: in order to prevent multiple probe calls against a service, lookup the service_class
    service_name = rosgraph.names.script_resolve_name('rosservice', args[0])
    service_class = get_service_class_by_name(service_name)

    # type-case using YAML
    service_args = []
    for arg in args[1:]:
        # convert empty args to YAML-empty strings
        if arg == '':
            arg = "''"
        service_args.append(yaml.load(arg))
    if not service_args and has_service_args(service_name,
                                             service_class=service_class):
        if sys.stdin.isatty():
            parser.error("Please specify service arguments")
        import rostopic
        for service_args in rostopic.stdin_yaml_arg():
            if service_args:
                # #2080: argument to _rosservice_call must be a list
                if type(service_args) != list:
                    service_args = [service_args]
                try:
                    _rosservice_call(service_name,
                                     service_args,
                                     verbose=options.verbose,
                                     service_class=service_class)
                except ValueError as e:
                    print(str(e), file=sys.stderr)
                    break
    else:
        _rosservice_call(service_name,
                         service_args,
                         verbose=options.verbose,
                         service_class=service_class)
Esempio n. 2
0
    # optimization: in order to prevent multiple probe calls against a service, lookup the service_class
    service_name = rosgraph.names.script_resolve_name('rosservice', args[0])
    service_class = get_service_class_by_name(service_name)
    
    # type-case using YAML 
    service_args = []
    for arg in args[1:]:
        # convert empty args to YAML-empty strings
        if arg == '':
            arg = "''" 
        service_args.append(yaml.load(arg))
    if not service_args and has_service_args(service_name, service_class=service_class):
        if sys.stdin.isatty():
            parser.error("Please specify service arguments")
        import rostopic
        for service_args in rostopic.stdin_yaml_arg():
            if service_args:
                # #2080: argument to _rosservice_call must be a list
                if type(service_args) != list:
                    service_args = [service_args]
                try:
                    _rosservice_call(service_name, service_args, verbose=options.verbose, service_class=service_class)
                except ValueError, e:
                    print(str(e), file=sys.stderr)
                    break
    else:
        _rosservice_call(service_name, service_args, verbose=options.verbose, service_class=service_class)

def _stdin_yaml_arg():
    """
    @return: iterator for next set of service args on stdin. Iterator returns a list of args for each call.
Esempio n. 3
0
def _rosservice_cmd_call(argv):
    """
    Parse 'call' command arguments and run command.  Will cause a system
    exit if command-line argument parsing fails.
    @param argv: command-line arguments
    @type  argv: [str]
    @raise ROSServiceException: if call command cannot be executed
    """
    try:
        import yaml
    except ImportError as e:
        raise ROSServiceException("Cannot import yaml. Please make sure the pyyaml system dependency is installed")

    args = argv[2:]
    parser = OptionParser(usage="usage: %prog call /service [args...]", prog=NAME)
    parser.add_option("-v", dest="verbose", default=False,
                      action="store_true",
                      help="print verbose output")
    parser.add_option("--wait", dest="wait", default=False,
                      action="store_true",
                      help="wait for service to be advertised")

    (options, args) = parser.parse_args(args)
    if len(args) == 0:
        parser.error("service must be specified")
    service_name = args[0]

    if options.wait:
        # have to make sure there is at least a master as the error
        # behavior of all ros online tools is to fail if there is no
        # master
        master = _get_master()
        try:
            service_uri = master.getPid()
        except socket.error:
            raise ROSServiceIOException("Unable to communicate with master!")
        rospy.wait_for_service(service_name)

    # optimization: in order to prevent multiple probe calls against a service, lookup the service_class
    service_name = rosgraph.names.script_resolve_name('rosservice', args[0])
    service_class = get_service_class_by_name(service_name)
    
    # type-case using YAML 
    service_args = []
    for arg in args[1:]:
        # convert empty args to YAML-empty strings
        if arg == '':
            arg = "''" 
        service_args.append(yaml.load(arg))
    if not service_args and has_service_args(service_name, service_class=service_class):
        if sys.stdin.isatty():
            parser.error("Please specify service arguments")
        import rostopic
        for service_args in rostopic.stdin_yaml_arg():
            if service_args:
                # #2080: argument to _rosservice_call must be a list
                if type(service_args) != list:
                    service_args = [service_args]
                try:
                    _rosservice_call(service_name, service_args, verbose=options.verbose, service_class=service_class)
                except ValueError as e:
                    print(str(e), file=sys.stderr)
                    break
    else:
        _rosservice_call(service_name, service_args, verbose=options.verbose, service_class=service_class)
Esempio n. 4
0
    service_name = roslib.scriptutil.script_resolve_name('rosservice', args[0])
    service_class = get_service_class_by_name(service_name)

    # type-case using YAML
    service_args = []
    for arg in args[1:]:
        # convert empty args to YAML-empty strings
        if arg == '':
            arg = "''"
        service_args.append(yaml.load(arg))
    if not service_args and has_service_args(service_name,
                                             service_class=service_class):
        if sys.stdin.isatty():
            parser.error("Please specify service arguments")
        import rostopic
        for service_args in rostopic.stdin_yaml_arg():
            if service_args:
                # #2080: argument to _rosservice_call must be a list
                if type(service_args) != list:
                    service_args = [service_args]
                try:
                    _rosservice_call(service_name,
                                     service_args,
                                     verbose=options.verbose,
                                     service_class=service_class)
                except ValueError, e:
                    print >> sys.stderr, str(e)
                    break
    else:
        _rosservice_call(service_name,
                         service_args,