示例#1
0
 def __init__(self, source_path, source_port, dest_path, dest_port,
              callbacks=[]):
     super(DisconnectPortsAct, self).__init__(callbacks=callbacks)
     self._source_path_str = source_path
     self._source_path = parse_path(source_path)[0]
     self._source_port = source_port
     self._dest_path_str = dest_path
     self._dest_path = parse_path(dest_path)[0]
     self._dest_port = dest_port
示例#2
0
 def __init__(self, source_path, source_port, dest_path, dest_port,
              name, id, properties, callbacks=[]):
     super(ConnectPortsAct, self).__init__(callbacks=callbacks)
     self._source_path_str = source_path
     self._source_path = parse_path(source_path)[0]
     self._source_port = source_port
     self._dest_path_str = dest_path
     self._dest_path = parse_path(dest_path)[0]
     self._dest_port = dest_port
     self._name = name
     self._id = id
     self._properties = properties.copy()
示例#3
0
 def refresh(self, verbose=False, force=False, try_count=5):
     from rtctree import path as rtctree_path
     from rtctree import tree as rtctree_tree
     import omniORB
     for i in range(0, try_count):
         try:
             #if self.tree and force:
             #    del(self.tree)
             #    del(self.dir_node)
             #    self.tree = None
             if self.tree:
                 orb = self.tree.orb
                 self.tree.give_away_orb()
             else:
                 orb = None
             if not self.tree or force:
                 sys.stdout.write('# Refreshing tree... for %s\n' % self.path)
                 self.__path, self.__port = rtctree_path.parse_path('/' + self.path)
                 self.tree = rtctree_tree.RTCTree(paths=self.__path, filter=[self.__path], orb=orb)
                 self.dir_node = self.tree.get_node(self.__path)
                 sys.stdout.write('## Success.\n')
                 return 
         except omniORB.CORBA.OBJECT_NOT_EXIST, e:
             print 'omniORB.CORBA.OBJECT_NOT_EXIST'
         except omniORB.OBJECT_NOT_EXIST_NoMatch, e:
             print 'omniORB.OBJECT_NOT_EXIST_NoMatch'
示例#4
0
文件: rtmgr.py 项目: gbiggs/rtcshell
def get_manager(cmd_path, full_path, tree=None):
    path, port = parse_path(full_path)
    if port:
        # Can't configure a port
        print >>sys.stderr, '{0}: Cannot access {1}: No such \
object.'.format(sys.argv[0], cmd_path)
        return None

    if not path[-1]:
        # There was a trailing slash - ignore it
        path = path[:-1]

    if not tree:
        tree = create_rtctree(paths=path)
    if not tree:
        return None

    object = tree.get_node(path)
    if not object:
        print >>sys.stderr, '{0}: Cannot access {1}: No such \
object.'.format(sys.argv[0], cmd_path)
        return tree, None
    if not object.is_manager:
        print >>sys.stderr, '{0}: Cannot access {1}: Not a \
manager.'.format(sys.argv[0], cmd_path)
        return tree, None

    return tree, object
示例#5
0
文件: rtcwd.py 项目: gbiggs/rtcshell
def cd(cmd_path, full_path):
    path, port = parse_path(full_path)
    if port:
        # Can't change dir to a port
        print >> sys.stderr, "rtcd: {0}: Not a \
directory".format(
            cmd_path
        )
        return 1

    if not path[-1]:
        # Remove trailing slash part
        path = path[:-1]

    tree = create_rtctree(paths=path)
    if not tree:
        return 1

    if not tree.has_path(path):
        print >> sys.stderr, "rtcd: {0}: No such directory or \
object".format(
            cmd_path
        )
        return 1
    if not tree.is_directory(path):
        print >> sys.stderr, "rtcd: {0}: Not a directory".format(cmd_path)
        return 1

    print make_cmd_line(full_path)
    return 0
示例#6
0
 def __init__(self, path_str, set, parameter, new_value, callbacks=[]):
     super(SetConfigParamValueAct, self).__init__(callbacks=callbacks)
     self._path_str = path_str
     self._path = parse_path(path_str)[0]
     self._set = str(set) # Cannot send unicode strings to CORBA
     self._param = str(parameter)
     self._new_value = str(new_value)
示例#7
0
 def __init__(self, path_str, comp_id, instance_name, ec_id, callbacks=[]):
     super(StateChangeAct, self).__init__(callbacks=callbacks)
     self._path_str = path_str
     self._comp_id = comp_id
     self._instance_name = instance_name
     self._path = parse_path(path_str)[0]
     self._ec_id = ec_id
示例#8
0
    def components(self, instanceName=None, verbose=False, try_count=5):
        from rtctree import tree as rtctree_tree
        from rtctree import path as rtctree_path
        comps = []
        if verbose:
            sys.stdout.write('## get components from nameserver(%s)\n' % self.path)

        def func(node, comps, instanceName=instanceName):
            if instanceName:
                if node.instanceName == instanceName:
                    comps.append(node)
            else:
                comps.append(node)

        def filter_func(node):
            if node.is_component and not node.parent.is_manager:
                return True
            return False

        for i in range(0, try_count):
            try:
                if not self.tree:
                    self.__path, self.__port = rtctree_path.parse_path('/' + self.path)
                    self.tree = rtctree_tree.RTCTree(paths=self.__path, filter=[self.__path])
                    self.dir_node = self.tree.get_node(self.__path)

                self.dir_node.iterate(func, comps, [filter_func])
                break
            except Exception, e:
                sys.stdout.write('## Exception occurred when getting component information from nameserver(%s)\n' % self.path)
                if verbose:
                    traceback.print_exc()
                self.tree = None
                pass
            time.sleep(0.5)
示例#9
0
 def rtcs(self, try_count=5):
     from rtctree import path as rtctree_path
     from rtctree import tree as rtctree_tree
     for i in range(0, try_count):
         try:
             if not self.tree:
                 self.__path, self.__port = rtctree_path.parse_path('/' + self.path)
                 self.tree = rtctree_tree.RTCTree(paths=self.__path, filter=[self.__path])
                 self.dir_node = self.tree.get_node(self.__path)
             break
         except Exception, e:
             pass
示例#10
0
    def is_running(self, ns, verbose=False, try_count=3, interval=5.0):
        """ Check NameServer (specified by NameServer class object) is running or not.
        :param NameServer ns: NameServer class object.
        :param bool verbose: Verbosity.
        :param int try_count: Retry in this count if connecting nameserver failed.
        :param float interval: Interval between retry.
        :rtype bool:
        :return: True if success
        """
        for i in range(0, try_count):
            if verbose: sys.stdout.write('## Checking Nameservice(%s) is running\n' % ns.path)
            from rtctree import path as rtctree_path
            import rtctree, omniORB
            try:
                if not ns.tree:
                    if verbose: sys.stdout.write('### Parsing path....\n')

                    path, port = rtctree_path.parse_path('/' + ns.path)
                    if verbose: sys.stdout.write('### Initializing rtctree...\n')


                    ns.tree = None
                    from wasanbon.util import task
                    from rtctree import tree as rtctree_tree
                    def task_func(args):
                        try:
                            if verbose: sys.stdout.write('#### Checking RTCTree.....\n')
                            ns.tree = rtctree_tree.RTCTree(paths=path, filter=[path])
                            if verbose: sys.stdout.write('#### Done.\n')
                        except:
                            if verbose: sys.stdout.write('#### Exception.\n')
                            pass

                    args = None
                    task.task_with_wdt(task_func, args, interval)
                    if not ns.tree:
                        if verbose: sys.stdout.write('### RTCTree Failed.\n')
                        continue
                    else:
                        if verbose: sys.stdout.write('### RTCTree Success.\n')

                if verbose: sys.stdout.write('### Getting Node...\n')
                self. dir_node = ns.tree.get_node(path)
                if verbose: sys.stdout.write('### Success.\n')
                if verbose: sys.stdout.write('### Nameservice(%s) is found.\n' % ns.path)
                return True
            except rtctree.exceptions.InvalidServiceError, e:
                continue
            except omniORB.CORBA.OBJECT_NOT_EXIST, e:
                continue
示例#11
0
    def dataports(self, data_type="any", port_type=['DataInPort', 'DataOutPort'], try_count=5, polarity="any", verbose=False):
        from rtctree import tree as rtctree_tree
        from rtctree import path as rtctree_path
        ports = []
        if verbose:
            sys.stdout.write('## get dataports from nameserver(%s)\n' % self.path)

        def func(node, ports, data_type=data_type, port_type=port_type):
            ports__ = []
            if 'DataInPort' in port_type:
                ports__ = ports__ + node.inports
            if 'DataOutPort' in port_type:
                ports__ = ports__ + node.outports
            if data_type == 'any':
                for port in ports__:
                    ports.append(port)
            else:
                for port in ports__:
                    if port.properties['dataport.data_type'] == data_type:
                        ports.append(port)
                #for port in [port for port in ports__ if port.properties['dataport.data_type'] == data_type]:
                #    ports.append(port)

        def filter_func(node):
            if node.is_component and not node.parent.is_manager:
                return True
            return False

        for i in range(0, try_count):
            try:
                if not self.tree:
                    self.__path, self.__port = rtctree_path.parse_path('/' + self.path)
                    self.tree = rtctree_tree.RTCTree(paths=self.__path, filter=[self.__path])
                    self.dir_node = self.tree.get_node(self.__path)

                self.dir_node.iterate(func, ports, [filter_func])
                break
            except Exception, e:
                sys.stdout.write('## Exception occurred when getting dataport information from nameserver(%s)\n' % self.path)
                if verbose:
                    traceback.print_exc()
                self.tree = None
                pass
            time.sleep(0.5)
示例#12
0
文件: rtdel.py 项目: gbiggs/rtcshell
def delete_object_reference(cmd_path, full_path, options, tree=None):
    path, port = parse_path(full_path)
    if port:
        # Can't delete a port
        print >>sys.stderr, '{0}: Cannot access {1}: Cannot delete \
ports.'.format(sys.argv[0], cmd_path)
        return 1

    trailing_slash = False
    if not path[-1]:
        path = path[:-1]

    # Cannot delete name servers
    if len(path) == 2:
        print >>sys.stderr, '{0}: {1}: Cannot delete name servers.'.format(\
                sys.argv[0], cmd_path)
        return 1

    if not tree:
        tree = create_rtctree(paths=path)
    if not tree:
        return 1

    # There is no point in doing path checks for the path, as the path we are
    # deleting may not be in the tree if it's a zombie. Instead, we need to
    # find its parent, and use that to remove the name.
    parent = tree.get_node(path[:-1])
    if parent.is_manager:
        print >>sys.stderr, '{0}: {1}: Use rtmgr to delete components from \
managers.'.format(sys.argv[0], cmd_path)
        return 1
    if not parent.is_directory:
        print >>sys.stderr, '{0}: {1}: Parent is not a directory.'.format(\
                sys.argv[0], cmd_path)
        return 1

    try:
        parent.unbind(path[-1])
    except BadPathError:
        print >>sys.stderr, '{0}: {1}: No such name registered.'.format(\
                sys.argv[0], cmd_path)
        return 1
    return 0
示例#13
0
文件: rtcat.py 项目: gbiggs/rtcshell
def cat_target(cmd_path, full_path, options, tree=None):
    use_colour = sys.stdout.isatty()

    path, port = parse_path(full_path)
    if port:
        # Can't cat a port
        print >>sys.stderr, '{0}: Cannot access {1}: No such \
object.'.format(sys.argv[0], cmd_path)
        return 1

    trailing_slash = False
    if not path[-1]:
        # There was a trailing slash
        print >>sys.stderr, '{0}: {1}: Not an \
object'.format(sys.argv[0], cmd_path)
        return 1

    if not tree:
        tree = create_rtctree(paths=path)
    if not tree:
        return tree

    if not tree.has_path(path):
        print >>sys.stderr, '{0}: Cannot access {1}: No such \
object.'.format(sys.argv[0], cmd_path)
        return 1
    object = tree.get_node(path)
    if object.is_component:
        for l in format_component(object, use_colour=sys.stdout.isatty(),
                                  long=options.long,
                                  really_long=options.really_long):
            print l
    elif object.is_manager:
        for l in format_manager(object, use_colour=sys.stdout.isatty(),
                                long=options.long):
            print l
    else:
        print >>sys.stderr, '{0}: Cannot access {1}: No such \
object.'.format(sys.argv[0], cmd_path)
        return 1

    return 0
示例#14
0
文件: rtconf.py 项目: gbiggs/rtcshell
def set_conf_value(set, param, new_value, cmd_path, full_path, options,
                   tree=None):
    path, port = parse_path(full_path)
    if port:
        # Can't configure a port
        print >>sys.stderr, '{0}: Cannot access {1}: No such \
object.'.format(sys.argv[0], cmd_path)
        return 1

    trailing_slash = False
    if not path[-1]:
        # There was a trailing slash
        print >>sys.stderr, '{0}: {1}: Not an \
object'.format(sys.argv[0], cmd_path)
        return 1

    if not tree:
        tree = create_rtctree(paths=path)
    if not tree:
        return 1

    object = tree.get_node(path)
    if not object:
        print >>sys.stderr, '{0}: Cannot access {1}: No such \
object.'.format(sys.argv[0], cmd_path)
        return 1
    if not object.is_component:
        print >>sys.stderr, '{0}: Cannot access {1}: Not a \
component.'.format(sys.argv[0], cmd_path)
        return 1

    if not set:
        set = object.active_conf_set_name
    try:
        object.set_conf_set_value(set, param, new_value)
    except NoSuchConfSetError, e:
        print >>sys.stderr, '{0}: {1}: No such configuration \
set'.format(sys.argv[0], e)
        return 1
示例#15
0
def listen_to_port(cmd_path, full_path, options, tree=None):
    global index
    path, port = parse_path(full_path)
    if not port:
        # Need a port to connect to
        print >>sys.stderr, '{0}: No port specified'.format(sys.argv[0])
        return 1
    if not path[-1]:
        # Trailing slashes are bad
        print >>sys.stderr, '{0}: Bad path'.format(sys.argv[0])
        return 1

    result, port_string = get_port_type_string(cmd_path, path, port, options, tree)
    if result:
        return result
    result, index = select_index(path, tree)
    if result:
        return result
    result, manager = create_listener_comp(port_string)
    if result:
        return result
    result = connect_listener(cmd_path, path, port, options, manager.getORB())
    if result:
        return result
    result = activate_listener(options, manager.getORB())
    if result:
        return result
    try:
        while True:
            raw_input('')
    except KeyboardInterrupt:
        pass
    except EOFError:
        pass
    manager.shutdown()
    manager.join()

    return 0
示例#16
0
    def svcports(self, interface_type="any", try_count=5, polarity="any"):
        from rtctree import tree as rtctree_tree
        from rtctree import path as rtctree_path

        ports = []
        def func(node, ports, interface_type=interface_type, polarity=polarity):
            for port in node.svcports:
                for intf in port.interfaces:
                    if interface_type != 'any':
                        if not intf.type_name == interface_type:
                            continue
                        pass
                    if polarity != 'any':
                        if not intf.polarity_as_string(False) == polarity:
                            continue
                    ports.append(port)

        def filter_func(node):
            if node.is_component and not node.parent.is_manager:
                return True
            return False


        for i in range(0, try_count):
            try:
                if not self.tree:
                    if verbose: sys.stdout.write('## Refreshing Name Server Tree.\n')
                    self.__path, self.__port = rtctree_path.parse_path('/' + self.path)
                    self.tree = rtctree_tree.RTCTree(paths=self.__path, filter=[self.__path])
                    self.dir_node = self.tree.get_node(self.__path)
                self.dir_node.iterate(func, ports, [filter_func])
                break
            except Exception, e:
                sys.stdout.write('## Exception occurred when getting service port information from nameserver(%s)\n' % self.path)
                if verbose:
                    traceback.print_exc()
                pass
            time.sleep(0.5)
示例#17
0
文件: rtconf.py 项目: gbiggs/rtcshell
def print_conf_sets(cmd_path, full_path, options, tree=None):
    use_colour = sys.stdout.isatty()

    path, port = parse_path(full_path)
    if port:
        # Can't configure a port
        print >>sys.stderr, '{0}: Cannot access {1}: No such \
object.'.format(sys.argv[0], cmd_path)
        return 1

    trailing_slash = False
    if not path[-1]:
        # There was a trailing slash
        print >>sys.stderr, '{0}: {1}: Not an \
object'.format(sys.argv[0], cmd_path)
        return 1

    if not tree:
        tree = create_rtctree(paths=path)
    if not tree:
        return 1

    object = tree.get_node(path)
    if not object:
        print >>sys.stderr, '{0}: Cannot access {1}: No such \
object.'.format(sys.argv[0], cmd_path)
        return 1
    if not object.is_component:
        print >>sys.stderr, '{0}: Cannot access {1}: Not a \
component.'.format(sys.argv[0], cmd_path)
        return 1

    for l in format_conf_sets(object.conf_sets, object.active_conf_set_name,
                              use_colour, options.long):
        print l

    return 0
示例#18
0
文件: rtdis.py 项目: gbiggs/rtcshell
def disconnect_all(cmd_path, full_path, options, tree=None):
    path, port = parse_path(full_path)
    if not path[-1]:
        # Trailing slashes are bad
        print >>sys.stderr, '{0}: Not a directory: {1}'.format(sys.argv[0],
                                                               cmd_path)
        return 1

    if not tree:
        tree = create_rtctree(paths=path)
    if not tree:
        return 1

    object = tree.get_node(path)
    if not object:
        print >>sys.stderr, '{0}: Cannot access {1}: No such \
object.'.format(sys.argv[0], cmd_path)
        return 1
    if not object.is_component:
        print >>sys.stderr, '{0}: Cannot access {1}: No such \
object'.format(sys.argv[0], cmd_path)
        return 1

    if port:
        # Disconnect a single port
        port_obj = object.get_port_by_name(port)
        if not port_obj:
            print >>sys.stderr, '{0}: Cannot access {1}: No such \
    port'.format(sys.argv[0], cmd_path)
            return 1
        port_obj.disconnect_all()
    else:
        # Disconnect all ports
        object.disconnect_all()
        pass

    return 0
示例#19
0
    def component(self, path, func, verbose=False, try_count=5):
        from rtctree import tree as rtctree_tree
        from rtctree import path as rtctree_path
        comps = []
        if verbose:
            sys.stdout.write('## get components from nameserver(%s)\n' % path)

        for i in range(0, try_count):
            try:
                path_, port_ = rtctree_path.parse_path('/' + path)
                tree = rtctree_tree.RTCTree(paths=path_, filter=[path_])
                dir_node = tree.get_node(path_)
                if dir_node.is_component:
                    if func:
                        func(dir_node)
                    return dir_node
                break
            except Exception, e:
                sys.stdout.write('## Exception occurred when getting component information from nameserver(%s)\n' % path)
                if verbose:
                    traceback.print_exc()
                self.tree = None
                pass
            time.sleep(0.5)
示例#20
0
def alter_component_state(action, cmd_path, full_path, options, tree=None):
    path, port = parse_path(full_path)
    if port:
        # Can't cat a port
        print >>sys.stderr, '{0}: Cannot access {1}: No such \
object.'.format(sys.argv[0], cmd_path)
        return 1

    trailing_slash = False
    if not path[-1]:
        # There was a trailing slash
        print >>sys.stderr, '{0}: {1}: Not an \
object'.format(sys.argv[0], cmd_path)
        return 1

    if not tree:
        tree = create_rtctree(paths=path)
    if not tree:
        return 1

    if not tree.has_path(path):
        print >>sys.stderr, '{0}: Cannot access {1}: No such \
object.'.format(sys.argv[0], cmd_path)
        return 1
    object = tree.get_node(path)
    if not object.is_component:
        print >>sys.stderr, '{0}: Cannot access {1}: Not an \
object'.format(sys.argv[0], cmd_path)
        return 1

    try:
        action(object, options.ec_index)
    except BadECIndexError, e:
        print >>sys.stderr, '{0}: No execution context at index \
{1}'.format(sys.argv[0], e.args[0])
        return 1
示例#21
0
 def __init__(self, path_str, set, callbacks=[]):
     super(SetActiveConfigSetAct, self).__init__(callbacks=callbacks)
     self._path_str = path_str
     self._path = parse_path(path_str)[0]
     self._set = str(set) # Cannot send unicode strings to CORBA
示例#22
0
文件: rtcon.py 项目: gbiggs/rtcshell
def connect_ports(source_cmd_path, source_full_path,
                  dest_cmd_path, dest_full_path,
                  options, tree=None):
    source_path, source_port = parse_path(source_full_path)
    if not source_port:
        # Need a port to connect to
        print >>sys.stderr, '{0}: No source port specified'.format(sys.argv[0])
        return 1
    if not source_path[-1]:
        # Trailing slashes are bad
        print >>sys.stderr, '{0}: Bad source path'.format(sys.argv[0])
        return 1

    dest_path, dest_port = parse_path(dest_full_path)
    if not dest_port:
        # Need a port to connect to
        print >>sys.stderr, '{0}: No destination port \
specified'.format(sys.argv[0])
        return 1
    if not dest_path[-1]:
        # Trailing slashes are bad
        print >>sys.stderr, '{0}: Bad destination path'.format(sys.argv[0])
        return 1

    if not tree:
        tree = create_rtctree(paths=[source_path, dest_path])
    if not tree:
        return 1

    if not tree.has_path(source_path):
        print >>sys.stderr, '{0}: Cannot access {1}: No such \
object.'.format(sys.argv[0], source_cmd_path)
        return 1
    if not tree.has_path(dest_path):
        print >>sys.stderr, '{0}: Cannot access {1}: No such \
object.'.format(sys.argv[0], dest_cmd_path)
        return 1

    source_comp = tree.get_node(source_path)
    if not source_comp or not source_comp.is_component:
        print >>sys.stderr, '{0}: Cannot access {1}: No such \
object'.format(sys.argv[0], source_cmd_path)
        return 1
    source_port_obj = source_comp.get_port_by_name(source_port)
    if not source_port_obj:
        print >>sys.stderr, '{0}: Cannot access {1}: No such \
port'.format(sys.argv[0], source_cmd_path)
        return 1
    dest_comp = tree.get_node(dest_path)
    if not dest_comp or not dest_comp.is_component:
        print >>sys.stderr, '{0}: Cannot access {1}: No such \
object'.format(sys.argv[0], dest_cmd_path)
        return 1
    dest_port_obj = dest_comp.get_port_by_name(dest_port)
    if not dest_port_obj:
        print >>sys.stderr, '{0}: Cannot access {1}: No such \
port'.format(sys.argv[0], dest_cmd_path)
        return 1

    conn_name = options.name if options.name else None
    try:
        source_port_obj.connect(dest_port_obj, name=conn_name, id=options.id,
                                props=options.properties)
    except IncompatibleDataPortConnectionPropsError:
        print >>sys.stderr, '{0}: An incompatible data port property or \
property value was given.'.format(sys.argv[0])
        return 1
    except WrongPortTypeError:
        print >>sys.stderr, '{0}: Mismatched port types.'.format(sys.argv[0])
        return 1
    except MismatchedPolarityError:
        print >>sys.stderr, '{0}: Service port polarities do not \
match.'.format(sys.argv[0])
        return 1
    except MismatchedInterfacesError:
        print >>sys.stderr, '{0}: Service port interfaces do not \
match.'.format(sys.argv[0])
        return 1
    except FailedToConnectError:
        print >>sys.stderr, '{0}: Failed to connect.'.format(sys.argv[0])
        return 1
    return 0
示例#23
0
文件: rtdis.py 项目: gbiggs/rtcshell
def disconnect_ports(source_cmd_path, source_full_path,
                  dest_cmd_path, dest_full_path,
                  options, tree=None):
    source_path, source_port = parse_path(source_full_path)
    if not source_port:
        # Need a port to disconnect
        print >>sys.stderr, '{0}: No source port specified'.format(sys.argv[0])
        return 1
    if not source_path[-1]:
        # Trailing slashes are bad
        print >>sys.stderr, '{0}: Bad source path'.format(sys.argv[0])
        return 1

    dest_path, dest_port = parse_path(dest_full_path)
    if not dest_port:
        # Need a port to disconnect
        print >>sys.stderr, '{0}: No destination port \
specified'.format(sys.argv[0])
        return 1
    if not dest_path[-1]:
        # Trailing slashes are bad
        print >>sys.stderr, '{0}: Bad destination path'.format(sys.argv[0])
        return 1

    if not tree:
        tree = create_rtctree(paths=[source_path, dest_path])
    if not tree:
        return 1

    source_comp = tree.get_node(source_path)
    if not source_comp:
        print >>sys.stderr, '{0}: Cannot access {1}: No such \
object.'.format(sys.argv[0], source_cmd_path)
        return 1
    if not source_comp.is_component:
        print >>sys.stderr, '{0}: Cannot access {1}: No such \
object'.format(sys.argv[0], source_cmd_path)
        return 1
    source_port_obj = source_comp.get_port_by_name(source_port)
    if not source_port_obj:
        print >>sys.stderr, '{0}: Cannot access {1}: No such \
port'.format(sys.argv[0], source_cmd_path)
        return 1
    dest_comp = tree.get_node(dest_path)
    if not dest_comp:
        print >>sys.stderr, '{0}: Cannot access {1}: No such \
object.'.format(sys.argv[0], dest_cmd_path)
        return 1
    if not dest_comp.is_component:
        print >>sys.stderr, '{0}: Cannot access {1}: No such \
object'.format(sys.argv[0], dest_cmd_path)
        return 1
    dest_port_obj = dest_comp.get_port_by_name(dest_port)
    if not dest_port_obj:
        print >>sys.stderr, '{0}: Cannot access {1}: No such \
port'.format(sys.argv[0], dest_cmd_path)
        return 1

    conn = source_port_obj.get_connection_by_dest(dest_port_obj)
    if not conn:
        print >>sys.stderr, '{0}: No connection between {1} and \
{2}'.format(sys.argv[0], source_cmd_path, dest_cmd_path)
        return 1

    conn.disconnect()

    return 0
示例#24
0
    def yaml_dump(self, long=False, detail=False, verbose=False):
        from rtctree import tree as rtctree_tree
        from rtctree import path as rtctree_path
        ports = []
        tab = '  '
        ns_only = True

        def show_func(node, tablevel, long=False, detail=False):

            if node.is_nameserver:
                full_path  = node.full_path[1]
                if full_path.startswith('/'): full_path = full_path[1:]
                sys.stdout.write(tab * tablevel + '"' + full_path + '":' + '\n')
            elif node.is_manager:
                sys.stdout.write(tab * tablevel + '' + node.name + ': {}\n')                
            elif node.is_directory:
                sys.stdout.write(tab * tablevel + '' + node.name + ':\n')
            elif node.is_zombie:
                sys.stdout.write(tab * tablevel + '' + node.name + '* : {}\n')                
            elif node.is_component:
                if not long and not detail:
                    sys.stdout.write(tab * tablevel + '' + node.name + '\n')
                else:
                    sys.stdout.write(tab * tablevel + '' + node.name + ':\n')
                    sys.stdout.write(tab * (tablevel + 1) + 'DataOutPorts:\n')
                    if len(node.outports) == 0:
                        sys.stdout.write(tab * (tablevel + 2) + '{}\n')
                    else:
                        for p in node.outports:
                            self._print_port(p, long, detail, 4)

                    sys.stdout.write(tab * (tablevel + 1) + 'DataInPorts:\n')
                    if len(node.inports) == 0:
                        sys.stdout.write(tab * (tablevel + 2) + '{}\n')
                    else:
                        for p in node.inports:
                            self._print_port(p, long, detail, 4)
                    sys.stdout.write(tab * (tablevel + 1) + 'ServicePorts:\n')
                    if len(node.svcports) == 0:
                        sys.stdout.write(tab * (tablevel + 2) + '{}\n')
                    else:
                        for p in node.svcports:
                            self._print_port(p, long, detail, 4)
                    sys.stdout.write(tab * (tablevel + 1) + 'ConfigurationSets:\n')
                    if len(node.conf_sets) == 0:
                        sys.stdout.write(tab * (tablevel + 2) + '{}\n')
                    else:
                        for cs in node.conf_sets:
                            self._print_conf_set(cs, node.conf_sets[cs], long, detail, 3+1)

                    sys.stdout.write(tab * (tablevel + 1) + 'properties:\n')
                    for key in sorted(node.properties.keys()):
                        value = node.properties[key]
                        sys.stdout.write(tab * (tablevel + 2) + key + ' : "' + value + '"\n')
                    sys.stdout.write(tab * (tablevel + 1) + 'state : ' + node.get_state_string(add_colour=False) + '\n')
                    sys.stdout.write(tab * (tablevel + 1) + 'exec_cxts:\n')
                    ec = node.get_ec(0)
                    for ec1 in node.owned_ecs:
                        #sys.stdout.write(tab * (tablevel + 2) + 'owner : ' + str(ec.participants) + '\n')
                        #sys.stdout.write(tab * (tablevel + 2) + 'state : ' + str(ec.get_component_state(node)) + '\n')
                        sys.stdout.write(tab * (tablevel + 2) + 'properties:\n')
                        for key in sorted(ec.properties.keys()):
                            value = ec.properties[key]
                            sys.stdout.write(tab * (tablevel + 3) + key + ' : "' + value + '"\n')

            if not node.is_manager:
                for c in node.children:
                    show_func(c, tablevel+1, long, detail)
                if not node.is_component and not node.is_zombie:
                    if len(node.children) == 0:
                        sys.stdout.write(tab * tablevel + tab  + '{}\n');
            
        try_count = 5
        import omniORB
        for i in range(0, try_count):
            try:
                if not self.tree:
                    if verbose: sys.stdout.write('## Refreshing Name Server Tree.\n')
                    self.__path, self.__port = rtctree_path.parse_path('/' + self.path)
                    self.tree = rtctree_tree.RTCTree(paths=self.__path, filter=[self.__path])
                    self.dir_node = self.tree.get_node(self.__path)
                sys.stdout.write('"' + self.path + '":\n')
                for c in self.dir_node.children:
                    show_func(c, 1, long, detail)
                if len(self.dir_node.children) == 0:
                    sys.stdout.write('  {}\n')
                
                break
            except Exception, e:
                sys.stdout.write('## Exception occurred when getting tree information from nameserver(%s)\n' % self.path)
                if verbose:
                    traceback.print_exc()
                pass
            except omniORB.CORBA.OBJECT_NOT_EXIST_NoMatch, e:
                sys.stdout.write('## CORBA.OBJECT_NOT_EXIST\n')
示例#25
0
def alive_component(cxtname,ns=["localhost"]):
    rtree=RTCTree(ns)
    cxtpath,ret=parse_path(cxtname)
    return rtree.has_path(cxtpath)
示例#26
0
文件: plan.py 项目: gbiggs/rtsshell
 def cb(rtctree=None, *args, **kwargs):
     comp = rtsprofile.find_comp_by_target(target_comp)
     path = pathsep + comp.path_uri
     comp = rtctree.get_node(parse_path(path)[0])
     return comp.refresh_state_in_ec(comp.get_ec_index(target_comp.id))
示例#27
0
文件: rtls.py 项目: gbiggs/rtcshell
def list_target(cmd_path, full_path, options, tree=None):
    path, port = parse_path(full_path)
    if port:
        # Can't list a port
        print >>sys.stderr, '{0}: Cannot access {1}: No such directory or \
object.'.format(sys.argv[0], cmd_path)
        return 1

    trailing_slash = False
    if not path[-1]:
        # There was a trailing slash
        trailing_slash = True
        path = path[:-1]

    if not tree:
        tree = create_rtctree(paths=path)
    if not tree:
        return 1

    if not tree.has_path(path):
        print >>sys.stderr, '{0}: Cannot access {1}: No such directory or \
object.'.format(sys.argv[0], cmd_path)
        return 1
    if tree.is_component(path):
        # Path points to a single component: print it like 'ls <file>'.
        if trailing_slash:
            # If there was a trailing slash, complain that a component is not a
            # directory.
            print >>sys.stderr, '{0}: cannot access {1}: Not a \
directory.'.format(sys.argv[0], address)
            return 1
        if options.long:
            lines = get_node_long_lines([tree.get_node(path)],
                                        sys.stdout.isatty())
            for l in lines:
                print l
        else:
            print path[-1]
    elif tree.is_directory(path):
        # If recursing, need to list this directory and all its children
        if options.recurse:
            recurse_root = tree.get_node(path)
            recurse_root_path = recurse_root.full_path
            def get_name(node, args):
                if node.full_path.startswith(recurse_root_path):
                    result = node.full_path[len(recurse_root_path):]
                else:
                    result = node.full_path
                return result.lstrip('/')
            dir_names = ['.'] + recurse_root.iterate(get_name,
                    args=options.long, filter=['is_directory'])[1:]
            listings = recurse_root.iterate(list_directory,
                    args=options.long, filter=['is_directory'])
            for dir, listing in zip(dir_names, listings):
                if dir == '.':
                    print '.:'
                else:
                    print './' + dir + ':'
                for l in listing:
                    print l
                print
        else:
            dir_node = tree.get_node(path)
            lines = list_directory(dir_node, options.long)
            for l in lines:
                print l
    else:
        print >>sys.stderr, '{0}: cannot access {1}: Unknown object \
type.'.format(sys.argv[0], cmd_path)
        return 1

    return 0
示例#28
0
 def __init__(self, path_str, id, instance_name, callbacks=[]):
     super(CheckForRequiredCompAct, self).__init__(callbacks=callbacks)
     self._path_str = path_str
     self._path = parse_path(path_str)[0]
     self._id = id
     self._instance_name = instance_name
示例#29
0
文件: rtfind.py 项目: gbiggs/rtcshell
def search(cmd_path, full_path, options, tree=None, returnvalue=None):
    path, port = parse_path(full_path)
    if port:
        # Can't search in a port
        print >>sys.stderr, '{0}: Cannot access {1}: No such directory or \
object.'.format(sys.argv[0], cmd_path)
        if returnvalue == 'list':
            return None
        else:
            return 1

    trailing_slash = False
    if not path[-1]:
        # There was a trailing slash
        trailing_slash = True
        path = path[:-1]

    if not tree:
        tree = create_rtctree(paths=path)
    if not tree:
        if returnvalue == 'list':
            return None
        else :
            return 1        

    # Find the root node of the search
    root = tree.get_node(path)
    if not root:
        print >>sys.stderr, '{0}: Cannot access {1}: No such directory or \
object.'.format(sys.argv[0], cmd_path)
        if returnvalue == 'list':
            return None
        else :
            return 1
    if root.is_component and trailing_slash:
        # If there was a trailing slash, complain that a component is not a
        # directory.
        print >>sys.stderr, '{0}: cannot access {1}: Not a directory.'.format(\
                sys.argv[0], address)
        if returnvalue == 'list':
            return None
        else :
            return 1

    name_res = []
    for name in options.name:
        # Replace regex special characters
        name = re.escape (name)
        # * goes to .*?
        name = name.replace (r'\*', '.*?')
        # ? goes to .
        name = name.replace (r'\?', r'.')
        name_res.append(re.compile(name))
    for name in options.iname:
        # Replace regex special characters
        name = re.escape (name)
        # * goes to .*?
        name = name.replace (r'\*', '.*?')
        # ? goes to .
        name = name.replace (r'\?', r'.')
        name_res.append(re.compile(name, re.IGNORECASE))

    def get_result(node, args):
        if node.full_path.startswith(cmd_path):
            result = node.full_path[len(cmd_path):]
            if not result:
                # This will happen if the search root is a component
                return node.name
            return node.full_path
        else:
            return node.full_path
    def matches_search(node):
        # Filter out types
        if node.is_component and 'c' not in options.type:
            return False
        if node.is_manager and 'm' not in options.type and \
                'd' not in options.type:
            return False
        if node.is_nameserver and 'n' not in options.type and \
                'd' not in options.type:
            return False
        if node.is_directory and 'd' not in options.type and \
                (not node.is_nameserver and not node.is_manager):
            return False
        if not name_res:
            return True
        # Check for name matches
        for name_re in name_res:
            if name_re.search(node.full_path):
                return True
        return False
    matches = root.iterate(get_result, filter=[matches_search])
    
    if returnvalue == 'list':
        return matches
    else :
        for m in matches:
            print m
        return 0
示例#30
0
 def __init__(self, path_str, port_name, callbacks=[]):
     super(CheckForPortAct, self).__init__(callbacks=callbacks)
     self._path_str = path_str
     self._path = parse_path(path_str)[0]
     self._port_name = port_name