Esempio n. 1
0
    def connect(self, argv):
        def property_callback(option, opt, option_value, parser):
            if option_value.count('=') != 1:
                raise wasanbon.InvalidUsageException()
            key, equals, value = option_value.partition('=')
            if not getattr(parser.values, option.dest):
                setattr(parser.values, option.dest, {})
            if key in getattr(parser.values, option.dest):
                raise wasanbon.InvalidUsageException()
            getattr(parser.values, option.dest)[key] = value


        self.parser.add_option('-n', '--name', help='Name of connection. (Default: None)', 
                               type='string', default=None, dest='name')
        self.parser.add_option('-i', '--id', help='id of connection. (Default: "")', 
                               type='string', default='', dest='id')
        self.parser.add_option('-p', '--property', help='Properties of connection. Use A=B Format (Default:"")', 
                               type='string', dest='properties', action='callback', callback=property_callback)
        options, argv = self.parse_args(argv[:])
        verbose = options.verbose_flag # This is default option
        if not getattr(options, 'properties'):
            setattr(options, 'properties', {})
        
        from rtshell import path
        from rtshell.rtcon import connect_ports
        
        paths = [(arg, path.cmd_path_to_full_path(arg)) for arg in argv[3:]]
        try:
            connect_ports(paths, options, tree=None)
            sys.stdout.write('Success.\n')
        except:
            sys.stdout.write('Failed. Exception occurred.\n')
        
        return 0
Esempio n. 2
0
    def exit_all_rtcs(self, package, verbose=False, try_count=5, wait_time=1.0):
        """ Exit All RTCs on package. """
        if verbose: sys.stdout.write('## Exitting All RTCS on package %s\n' % package.name)
        mgr_addrs = admin.systeminstaller.get_rtcd_manager_addresses(package, verbose=verbose)
        if verbose: sys.stdout.write('# Parsing manager : %s\n' % mgr_addrs)
        for lang in ['C++', 'Java', 'Python']:
            sys.stdout.write('# Getting Manager for language (%s)\n' % lang)
            for mgr_addr in mgr_addrs[lang]:
                cleaned = False
                if not mgr_addr.startswith('/') : mgr_addr = '/' + mgr_addr
                from rtshell import path
                full_path = path.cmd_path_to_full_path(mgr_addr)
                mgr = None
                for i in range(0, try_count):
                    if verbose: sys.stdout.write('## Getting Manager [%s]\n' % mgr_addr)
                    from rtshell import rts_exceptions
                    from rtshell.rtmgr import get_manager
                    try:

                        tree, mgr = get_manager(mgr_addr, full_path)
                        break
                    except rts_exceptions.ZombieObjectError, e:
                        if i == try_count-1:
                            sys.stdout.write('# ZombieObjectError Occured when exit_all_rtcs\n')
                            traceback.print_exc()
                            return -1
                    except rts_exceptions.NoSuchObjectError, e:
                        break
                if mgr:
                    if len(mgr.components) == 0:
                        if verbose: sys.stdout.write('### Manager (%s) has no RTCs.\n' % mgr_addr)
                        cleaned = True
                    else:
                        for r in mgr.components:
                            if verbose: sys.stdout.write('### Exitting RTC (%s)\n' % r.instance_name)
                            r.exit()

                        for i in range(0, try_count):
                            time.sleep(wait_time)
                            if verbose: sys.stdout.write('## Getting Manager [%s] Again\n' % mgr_addr)
                            tree, mgr = get_manager(mgr_addr, full_path)
                            if len(mgr.components) == 0:
                                if verbose: sys.stdout.write('### Manager (%s) has no RTCs.\n' % mgr_addr)
                                cleaned = True
                                break
                            else:
                                if verbose: sys.stdout.write('### Manager (%s) still have RTCs.\n' % mgr_addr)
                                pass

                    if cleaned: break
                else:
                    if verbose: sys.stdout.write('## Getting Manager failed.\n')
                    break
Esempio n. 3
0
def rtactivate(nameserver, tags, tree):
    def activate_action(object, ec_index):
        object.activate_in_ec(ec_index)

    for tag in tags:

        # check if/unless attribute in rtactivate tags
        exec_flag = True
        if tag.attributes.get(u'if'):
            val = tag.attributes.get(u'if').value
            arg = val.split(" ")[1].strip(")")  # To "USE_WALKING"
            exec_flag = get_flag_from_argv(arg)
        if tag.attributes.get(u'unless'):
            val = tag.attributes.get(u'unless').value
            arg = val.split(" ")[1].strip(")")  # To "USE_WALKING"
            exec_flag = not get_flag_from_argv(arg)
        if not exec_flag:
            continue

        cmd_path = nameserver + "/" + tag.attributes.get("component").value
        full_path = path.cmd_path_to_full_path(cmd_path)
        full_path = replace_arg_tag_by_env(full_path)
        # print >>sys.stderr, "[rtmlaunch] activate %s"%(full_path)
        try:
            state = wait_component(full_path, tree)
            if state == 'Active':
                continue
            else:
                print >> sys.stderr, "[rtmlaunch] Activate <-", state, full_path
        except Exception, e:
            print >> sys.stderr, '\033[31m[rtmlaunch] Could not Activate (', cmd_path, ') : ', e, '\033[0m'
            return 1
        try:
            options = optparse.Values({"ec_index": 0, 'verbose': False})
            try:
                state_control_base.alter_component_state(activate_action,
                                                         cmd_path,
                                                         full_path,
                                                         options,
                                                         tree=tree)
            except Exception, e:  # openrtm 1.1.0
                state_control_base.alter_component_states(
                    activate_action, [(cmd_path, full_path)],
                    options,
                    tree=tree)
        except Exception, e:
            print >> sys.stderr, '[rtmlaunch] {0}: {1}'.format(
                os.path.basename(sys.argv[0]), e)
            return 1
Esempio n. 4
0
 def disconnect(self, argv):
     self.parser.add_option('-i', '--id', help='id of connection. (Default: "")', 
                            type='string', default='', dest='id')
     options, argv = self.parse_args(argv[:])
     verbose = options.verbose_flag # This is default option
     
     from rtshell import path
     from rtshell.rtdis import disconnect_ports
     
     paths = [(arg, path.cmd_path_to_full_path(arg)) for arg in argv[3:]]
     try:
         disconnect_ports(paths, options, tree=None)
         sys.stdout.write('Success.\n')
     except:
         sys.stdout.write('Failed. Exception occurred.\n')
     return 0
Esempio n. 5
0
def rtactivate(nameserver, tags, tree):
    def activate_action(object, ec_index):
        object.activate_in_ec(ec_index)
    for tag in tags:
        
        # check if/unless attribute in rtactivate tags
        exec_flag = True
        if tag.attributes.get(u'if'):
            val = tag.attributes.get(u'if').value
            arg = val.split(" ")[1].strip(")") # To "USE_WALKING"
            exec_flag =  get_flag_from_argv(arg)
        if tag.attributes.get(u'unless'):
            val = tag.attributes.get(u'unless').value
            arg = val.split(" ")[1].strip(")") # To "USE_WALKING"
            exec_flag = not get_flag_from_argv(arg)
        if not exec_flag:
            continue

        cmd_path  = nameserver+"/"+tag.attributes.get("component").value
        full_path = path.cmd_path_to_full_path(cmd_path)
        full_path = replace_arg_tag_by_env(full_path)
        # print >>sys.stderr, "[rtmlaunch] activate %s"%(full_path)
        try:
            state = wait_component(full_path, tree)
            if state == 'Active':
                continue
            else:
                print >>sys.stderr, "[rtmlaunch] Activate <-",state,full_path
        except Exception, e:
            print >>sys.stderr, '\033[31m[rtmlaunch] Could not Activate (', cmd_path, ') : ', e,'\033[0m'
            return 1
        try:
            options = optparse.Values({"ec_index": 0, 'verbose': False})
            try :
                state_control_base.alter_component_state(activate_action, cmd_path, full_path, options, tree=tree)
            except Exception, e: # openrtm 1.1.0
                state_control_base.alter_component_states(activate_action, [(cmd_path, full_path)], options, tree=tree)
        except Exception, e:
            print >>sys.stderr, '[rtmlaunch] {0}: {1}'.format(os.path.basename(sys.argv[0]), e)
            return 1
Esempio n. 6
0
def rtconnect(nameserver, tags, tree):
    for tag in tags:

        # check if/unless attribute in rtconnect tags
        exec_flag = True
        if tag.attributes.get(u'if'):
            val = tag.attributes.get(u'if').value
            arg = val.split(" ")[1].strip(")")  # To "USE_WALKING"
            exec_flag = get_flag_from_argv(arg)
        if tag.attributes.get(u'unless'):
            val = tag.attributes.get(u'unless').value
            arg = val.split(" ")[1].strip(")")  # To "USE_WALKING"
            exec_flag = not get_flag_from_argv(arg)
        if not exec_flag:
            continue

        source_path = nameserver + "/" + tag.attributes.get("from").value
        dest_path = nameserver + "/" + tag.attributes.get("to").value
        source_path = replace_arg_tag_by_env(source_path)
        dest_path = replace_arg_tag_by_env(dest_path)
        # print >>sys.stderr, "[rtmlaunch] Connecting from %s to %s"%(source_path,dest_path)
        source_full_path = path.cmd_path_to_full_path(source_path)
        dest_full_path = path.cmd_path_to_full_path(dest_path)
        if tag.attributes.get("subscription_type") != None:
            sub_type = tag.attributes.get("subscription_type").value
            sub_type = replace_arg_tag_by_env(sub_type)
            if not sub_type in ['flush', 'new', 'periodic']:
                print >> sys.stderr, sub_type + ' is not a subscription type'
                continue
        else:
            sub_type = 'flush'  # this is default value
        if sub_type == 'new':
            push_policy = 'all'
        # wait for proess
        try:
            wait_component(source_full_path, tree)
            wait_component(dest_full_path, tree)
            if check_connect(source_full_path, dest_full_path, tree):
                continue
        except Exception, e:
            print >> sys.stderr, '\033[31m[rtmlaunch] [ERROR] Could not Connect (', source_full_path, ',', dest_full_path, '): ', e, '\033[0m'
            return 1
        #print source_path, source_full_path, dest_path, dest_full_path;
        try:
            sub_type = str(sub_type)
            props = {'dataport.subscription_type': sub_type}
            if tag.attributes.get("push_policy") != None:
                push_policy = replace_arg_tag_by_env(
                    str(tag.attributes.get("push_policy").value))
            else:
                push_policy = 'all'
            if sub_type == 'new':
                props['dataport.publisher.push_policy'] = push_policy
            elif sub_type == 'periodic':
                props['dataport.publisher.push_policy'] = push_policy
                if tag.attributes.get("push_rate") != None:
                    props['dataport.push_rate'] = replace_arg_tag_by_env(
                        str(tag.attributes.get("push_rate").value))
                else:
                    props['dataport.push_rate'] = str('50.0')
            if tag.attributes.get("buffer_length") != None:
                props['dataport.buffer.length'] = replace_arg_tag_by_env(
                    str(tag.attributes.get("buffer_length").value))
            options = optparse.Values({
                'verbose': False,
                'id': '',
                'name': None,
                'properties': props
            })
            print >> sys.stderr, "[rtmlaunch] Connected from", source_path
            print >> sys.stderr, "[rtmlaunch]             to", dest_path
            print >> sys.stderr, "[rtmlaunch]           with", options
            try:
                rtcon.connect_ports(source_path,
                                    source_full_path,
                                    dest_path,
                                    dest_full_path,
                                    options,
                                    tree=tree)
            except Exception, e_1_1_0:  # openrtm 1.1.0
                try:
                    rtcon.connect_ports([(source_path, source_full_path),
                                         (dest_path, dest_full_path)],
                                        options,
                                        tree=tree)
                except Exception, e_1_0_0:  # openrtm 1.0.0
                    print >> sys.stderr, '\033[31m[rtmlaunch] {0} did not work on both OpenRTM 1.0.0 and 1.1.0'.format(
                        os.path.basename(sys.argv[1])), '\033[0m'
                    print >> sys.stderr, '\033[31m[rtmlaunch]    OpenRTM 1.0.0 {0}'.format(
                        e_1_0_0), '\033[0m'
                    print >> sys.stderr, '\033[31m[rtmlaunch]    OpenRTM 1.1.0 {0}'.format(
                        e_1_1_0), '\033[0m'
                    print >> sys.stderr, '\033[31m[rtmlaunch]  This is very weird situation, Please check your network\033[0m'
                    print >> sys.stderr, '\033[31m[rtmlaunch] configuration with `ifconfig` on both robot and client side. \033[0m'
                    print >> sys.stderr, '\033[31m[rtmlaunch]  Having multiple network interface sometimes causes problem, \033[0m'
                    print >> sys.stderr, '\033[31m[rtmlaunch] please see FAQ site http://www.openrtm.org/OpenRTM-aist/html/FAQ2FE38388E383A9E38396E383ABE382B7E383A5E383BCE38386E382A3E383B3E382B0.html#f2bc375d\033[0m'
                    print >> sys.stderr, '\033[31m[rtmlaunch]            Issue related to this https://github.com/start-jsk/rtmros_hironx/issues/33\033[0m'
                    print >> sys.stderr, '\033[31m[rtmlaunch]            ~/.ros/log may contains usefully informations\033[0m'
Esempio n. 7
0
def rtconnect(nameserver, tags, tree):
    for tag in tags:

        # check if/unless attribute in rtconnect tags
        exec_flag = True
        if tag.attributes.get(u'if'):
            val = tag.attributes.get(u'if').value
            arg = val.split(" ")[1].strip(")") # To "USE_WALKING"
            exec_flag =  get_flag_from_argv(arg)
        if tag.attributes.get(u'unless'):
            val = tag.attributes.get(u'unless').value
            arg = val.split(" ")[1].strip(")") # To "USE_WALKING"
            exec_flag = not get_flag_from_argv(arg)
        if not exec_flag:
            continue

        source_path = nameserver+"/"+tag.attributes.get("from").value
        dest_path   = nameserver+"/"+tag.attributes.get("to").value
        source_path = replace_arg_tag_by_env(source_path)
        dest_path = replace_arg_tag_by_env(dest_path)
        # print >>sys.stderr, "[rtmlaunch] Connecting from %s to %s"%(source_path,dest_path)
        source_full_path = path.cmd_path_to_full_path(source_path)
        dest_full_path = path.cmd_path_to_full_path(dest_path)
        if tag.attributes.get("subscription_type") != None:
            sub_type = tag.attributes.get("subscription_type").value
            if not sub_type in ['flush','new','periodic']:
                print >>sys.stderr, sub_type+' is not a subscription type'
                continue
        else:
            sub_type = 'flush' # this is default value
        if sub_type == 'new':
            push_policy = 'all'
        # wait for proess
        try:
            wait_component(source_full_path, tree)
            wait_component(dest_full_path, tree)
            if check_connect(source_full_path,dest_full_path, tree):
                continue
        except Exception, e:
            print >>sys.stderr, '\033[31m[rtmlaunch] [ERROR] Could not Connect (', source_full_path, ',', dest_full_path, '): ', e,'\033[0m'
            return 1
        #print source_path, source_full_path, dest_path, dest_full_path;
        try:
            sub_type = str(sub_type)
            props = {'dataport.subscription_type': sub_type}
            if sub_type == 'new':
                props['dataport.publisher.push_policy'] = 'all'
            elif sub_type == 'periodic':
                props['dataport.publisher.push_policy'] = 'all'
                if tag.attributes.get("push_rate") != None:
                    props['dataport.push_rate'] = str(tag.attributes.get("push_rate").value)
                else:
                    props['dataport.push_rate'] = str('50.0')
            options = optparse.Values({'verbose': False, 'id': '', 'name': None, 'properties': props})
            print >>sys.stderr, "[rtmlaunch] Connected from",source_path
            print >>sys.stderr, "[rtmlaunch]             to",dest_path
            print >>sys.stderr, "[rtmlaunch]           with",options
            try :
                rtcon.connect_ports(source_path, source_full_path, dest_path, dest_full_path, options, tree=tree)
            except Exception, e_1_1_0: # openrtm 1.1.0
                try:
                    rtcon.connect_ports([(source_path,source_full_path), (dest_path, dest_full_path)], options, tree=tree)
                except Exception, e_1_0_0: # openrtm 1.0.0
                    print >>sys.stderr, '\033[31m[rtmlaunch] {0} did not work on both OpenRTM 1.0.0 and 1.1.0'.format(os.path.basename(sys.argv[1])),'\033[0m'
                    print >>sys.stderr, '\033[31m[rtmlaunch]    OpenRTM 1.0.0 {0}'.format(e_1_0_0),'\033[0m'
                    print >>sys.stderr, '\033[31m[rtmlaunch]    OpenRTM 1.1.0 {0}'.format(e_1_1_0),'\033[0m'
                    print >>sys.stderr, '\033[31m[rtmlaunch]  This is very weird situation, Please check your network\033[0m'
                    print >>sys.stderr, '\033[31m[rtmlaunch] configuration with `ifconfig` on both robot and client side. \033[0m'
                    print >>sys.stderr, '\033[31m[rtmlaunch]  Having multiple network interface sometimes causes problem, \033[0m'
                    print >>sys.stderr, '\033[31m[rtmlaunch] please see FAQ site http://www.openrtm.org/OpenRTM-aist/html/FAQ2FE38388E383A9E38396E383ABE382B7E383A5E383BCE38386E382A3E383B3E382B0.html#f2bc375d\033[0m'
                    print >>sys.stderr, '\033[31m[rtmlaunch]            Issue related to this https://github.com/start-jsk/rtmros_hironx/issues/33\033[0m'
                    print >>sys.stderr, '\033[31m[rtmlaunch]            ~/.ros/log may contains usefully informations\033[0m'
Esempio n. 8
0
def rtconnect(nameserver, tags):
    import re
    for tag in tags:

        # check if/unless attribute in rtconnect tags
        exec_flag = True
        if tag.attributes.get(u'if'):
            val = tag.attributes.get(u'if').value
            arg = val.split(" ")[1].strip(")") # To "USE_WALKING"
            exec_flag =  get_flag_from_argv(arg)
        if tag.attributes.get(u'unless'):
            val = tag.attributes.get(u'unless').value
            arg = val.split(" ")[1].strip(")") # To "USE_WALKING"
            exec_flag = not get_flag_from_argv(arg)
        if not exec_flag:
            continue

        source_path = nameserver+"/"+tag.attributes.get("from").value
        dest_path   = nameserver+"/"+tag.attributes.get("to").value
        source_path = re.sub("\$\(arg SIMULATOR_NAME\)",simulator,source_path);
        dest_path = re.sub("\$\(arg SIMULATOR_NAME\)",simulator,dest_path);
        # print >>sys.stderr, "[rtmlaunch] Connecting from %s to %s"%(source_path,dest_path)
        source_full_path = path.cmd_path_to_full_path(source_path)
        dest_full_path = path.cmd_path_to_full_path(dest_path)
        if tag.attributes.get("subscription_type") != None:
            sub_type = tag.attributes.get("subscription_type").value
            if not sub_type in ['flush','new','periodic']:
                print >>sys.stderr, sub_type+' is not a subscription type'
                continue
        else:
            sub_type = 'flush' # this is default value
        if sub_type == 'new':
            push_policy = 'all'
        # wait for proess
        try:
            wait_component(source_full_path)
            wait_component(dest_full_path)
            if check_connect(source_full_path,dest_full_path):
                continue
        except Exception, e:
            print >>sys.stderr, '\033[31m[rtmlaunch] [ERROR] Could not Connect (', source_full_path, ',', dest_full_path, '): ', e,'\033[0m'
            return 1
        #print source_path, source_full_path, dest_path, dest_full_path;
        try:
            sub_type = str(sub_type)
            props = {'dataport.subscription_type': sub_type}
            if sub_type == 'new':
                props['dataport.publisher.push_policy'] = 'all'
            elif sub_type == 'periodic':
                props['dataport.publisher.push_policy'] = 'all'
                if tag.attributes.get("push_rate") != None:
                    props['dataport.push_rate'] = str(tag.attributes.get("push_rate").value)
                else:
                    props['dataport.push_rate'] = str('50.0')
            options = optparse.Values({'verbose': False, 'id': '', 'name': None, 'properties': props})
            print >>sys.stderr, "[rtmlaunch] Connected from",source_path
            print >>sys.stderr, "[rtmlaunch]             to",dest_path
            print >>sys.stderr, "[rtmlaunch]           with",options
            try :
                rtcon.connect_ports(source_path, source_full_path, dest_path, dest_full_path, options, tree=None)
            except Exception, e: # openrtm 1.1.0
                rtcon.connect_ports([(source_path,source_full_path), (dest_path, dest_full_path)], options, tree=None)
        except Exception, e:
            print >>sys.stderr, '\033[31m[rtmlaunch] {0}: {1}'.format(os.path.basename(sys.argv[1]), e),'\033[0m'