Пример #1
0
def cat_target(cmd_path, full_path, options, tree=None):
    use_colour = rtctree.utils.colour_supported(sys.stdout)

    path, port = rtctree.path.parse_path(full_path)
    if not path[-1]:
        # There was a trailing slash
        trailing_slash = True
        path = path[:-1]
    else:
        trailing_slash = False

    if not tree:
        if options.long > 0:
            # Longer output needs to look around the tree, so don't filter
            filter = []
        else:
            filter = [path]
        tree = rtctree.tree.RTCTree(paths=path, filter=filter)

    if not tree.has_path(path):
        raise rts_exceptions.NoSuchObjectError(cmd_path)
    object = tree.get_node(path)
    if port:
        if not object.is_component:
            raise rts_exceptions.NotAComponentError(cmd_path)
        if trailing_slash:
            raise rts_exceptions.NoSuchObjectError(cmd_path)
        p = object.get_port_by_name(port)
        if not p:
            raise rts_exceptions.PortNotFoundError(path, port)
        return format_port(p,
                           object,
                           start_indent=0,
                           use_colour=use_colour,
                           long=options.long)
    else:
        if object.is_component:
            if trailing_slash:
                raise rts_exceptions.NoSuchObjectError(cmd_path)
            return format_component(object,
                                    tree,
                                    use_colour=use_colour,
                                    long=options.long)
        elif object.is_manager:
            return format_manager(object,
                                  use_colour=use_colour,
                                  long=options.long)
        elif object.is_zombie:
            raise rts_exceptions.ZombieObjectError(cmd_path)
        else:
            raise rts_exceptions.NoSuchObjectError(cmd_path)
Пример #2
0
def disconnect_ports(paths, options, tree=None):
    cmd_paths, fps = list(zip(*paths))
    pathports = [rtctree.path.parse_path(fp) for fp in fps]
    for ii, p in enumerate(pathports):
        if not p[1]:
            raise rts_exceptions.NotAPortError(cmd_paths[ii])
        if not p[0][-1]:
            raise rts_exceptions.NotAPortError(cmd_paths[ii])
    paths, ports = list(zip(*pathports))

    if not tree:
        tree = rtctree.tree.RTCTree(paths=paths, filter=paths)

    port_objs = []
    for ii, p in enumerate(pathports):
        obj = tree.get_node(p[0])
        if not obj:
            raise rts_exceptions.NoSuchObjectError(cmd_paths[ii])
        if obj.is_zombie:
            raise rts_exceptions.ZombieObjectError(cmd_paths[ii])
        if not obj.is_component:
            raise rts_exceptions.NotAComponentError(cmd_paths[ii])
        port_obj = obj.get_port_by_name(p[1])
        if not port_obj:
            raise rts_exceptions.PortNotFoundError(p[0], p[1])
        port_objs.append(port_obj)
    if len(port_objs) < 2:
        raise rts_exceptions.NoDestPortError

    if options.id:
        all_conns = port_objs[0].get_connections_by_dests(port_objs[1:])
        conns = []
        for c in all_conns:
            if c.id == options.id:
                conns.append(c)
    else:
        conns = port_objs[0].get_connections_by_dests(port_objs[1:])

    if not conns:
        if options.id:
            raise rts_exceptions.ConnectionIDNotFoundError(options.id,
                    cmd_paths[0])
        else:
            raise rts_exceptions.MultiConnectionNotFoundError
    for c in conns:
        c.disconnect()
Пример #3
0
def find_port(rtc, port, tree=None, orb=None):
    '''Get a rtctree.Port object from an rtctree.RTCTree.

    Get the port object by searching the RTCTree for the specified RTC, then
    looking for the specified port on that component.

    @param rtc Path to the component that should have a port. This should be in
               the format used by rtctree, i.e. a list of path entries, with
               the first being a /. e.g. ['/', 'localhost', 'comp0.rtc'].
    @param port Name of the port.
    @param tree An already-populated rtctree.RTCTree object, or None if one
                should be created.
    @param orb An ORB to use if the tree must be created, or None to make one.

    '''
    comp = get_comp(rtc, tree=tree, orb=orb)
    port_obj = comp.get_port_by_name(port)
    if not port_obj:
        raise rts_exceptions.PortNotFoundError(rtc, port)
    return port_obj
Пример #4
0
def disconnect_all(cmd_path, full_path, options, tree=None):
    path, port = rtctree.path.parse_path(full_path)
    if not path[-1]:
        raise rts_exceptions.NoSuchObjectError(cmd_path)
    if not tree:
        tree = rtctree.tree.RTCTree(paths=path, filter=[path])

    object = tree.get_node(path)
    if not object:
        raise rts_exceptions.NoSuchObjectError(cmd_path)
    if not object.is_component:
        raise rts_exceptions.NotAComponentError(cmd_path)

    if port:
        # Disconnect a single port
        port_obj = object.get_port_by_name(port)
        if not port_obj:
            raise rts_exceptions.PortNotFoundError(path, port)
        if options.id:
            conn = port_obj.get_connection_by_id(options.id)
            if not conn:
                raise rts_exceptions.ConnectionIDNotFoundError(options.id,
                        cmd_path)
            conn.disconnect()
        else:
            port_obj.disconnect_all()
    else:
        if options.id:
            # Hunt through the ports for the connection ID
            for p in object.ports:
                conn = p.get_connection_by_id(options.id)
                if not conn:
                    continue
                conn.disconnect()
                return
            raise rts_exceptions.ConnectionIDNotFoundError(options.id,
                    cmd_path)
        else:
            # Disconnect all ports
            object.disconnect_all()
Пример #5
0
 def find_local_port(name, ports):
     for p in ports:
         if p.get_port_profile().name.split('.')[-1] == name:
             return p
     raise rts_exceptions.PortNotFoundError(comp.getTypeName(), name)
Пример #6
0
def manage_composition(tgt_raw_path, tgt_full_path, options, tree=None):
    # Parse paths of components to add/remove
    add_paths = parse_member_paths(options.add)
    rem_paths = parse_member_paths(options.remove)

    # The target, either a manager or a component
    tgt_path, tgt_suffix = rtctree.path.parse_path(tgt_full_path)

    # Make a tree
    if not tree:
        paths = [tgt_path] + [y for x, y, z in add_paths + rem_paths]
        tree = rtctree.tree.RTCTree(paths=paths, filter=paths)
    tgt_obj = tree.get_node(tgt_path)
    if not tgt_obj:
        raise rts_exceptions.NoSuchObjectError(tgt_raw_path)

    # Input sanity check: ensure all components and ports to be added exist
    add_rtcs = get_comp_objs(add_paths, tree)
    for rtc in add_rtcs:
        for p in add_rtcs[rtc][1]:
            if not add_rtcs[rtc][0].get_port_by_name(p):
                raise rts_exceptions.PortNotFoundError(rtc, p)
    # Ensure all ports to be removed that are on components that are alive
    # exist
    rem_rtcs, rem_zombies = get_potential_comp_objs(rem_paths, tree)
    for rtc in rem_rtcs:
        for p in rem_rtcs[rtc][1]:
            if not rem_rtcs[rtc][0].get_port_by_name(p):
                raise rts_exceptions.PortNotFoundError(rtc, p)

    if tgt_obj.is_manager:
        # Create composition
        if not tgt_suffix:
            tgt_suffix = 'CompositeRTC'
            tgt_raw_path += ':' + tgt_suffix
        # Check if this composition already exists
        comp = tgt_obj.get_node([tgt_obj.name, tgt_suffix + '.rtc'])
        if not comp:
            # Cannot remove components when creating a new composition
            if options.remove:
                raise rts_exceptions.CannotRemoveFromNewCompositionError()
            # No composition exists in this manager; make a new one
            if options.verbose:
                print('Creating new composition {0}'.format(tgt_raw_path),
                      file=sys.stderr)
            comp = create_composition(tgt_obj, tgt_suffix, options.options,
                                      options.type)
        elif options.verbose:
            print('Editing existing composition {0}'.format(tgt_raw_path),
                  file=sys.stderr)
    elif tgt_obj.is_component:
        # Edit composition - there should be no suffix
        if tgt_suffix:
            raise rts_exceptions.NotAComponentError(tgt_raw_path)
        comp = tgt_obj
        if options.verbose:
            print('Editing existing composition {0}'.format(tgt_raw_path),
                  file=sys.stderr)
    else:
        raise rts_exceptions.NotAComponentOrManagerError(tgt_raw_path)
    if not comp.is_composite:
        raise rts_exceptions.NotACompositeComponentError(tgt_raw_path)

    if add_paths:
        add_to_composition(comp, add_rtcs, tree, options.verbose)
    if rem_paths:
        rem_rtcs.update(rem_zombies)
        rem_from_composition(comp, rem_rtcs, tree, options.verbose)
    if not comp.members[comp.organisations[0].org_id]:
        if options.verbose:
            print('Composition {0} has no members'.format(tgt_raw_path),
                  file=sys.stderr)
Пример #7
0
def connect_ports(paths, options, tree=None):
    '''connect_ports

    This should raise exception:

    >>> connect_ports([
    ...   ('Std0.rtc', '/localhost/local.host_cxt/Std0.rtc'),
    ...   ('Output0.rtc:out', '/localhost/local.host_cxt/Output0.rtc:out')
    ... ], {})
    Traceback (most recent call last):
    ...
    NoSourcePortError: No source port specified.

    >>> connect_ports([
    ...   ('Std0.rtc:in', '/localhost/local.host_cxt/Std0.rtc:in'),
    ...   ('Output0.rtc', '/localhost/local.host_cxt/Output0.rtc')
    ... ], {})
    Traceback (most recent call last):
    ...
    NoDestPortError: No destination port specified.
    '''
    cmd_paths, fps = list(zip(*paths))
    pathports = [rtctree.path.parse_path(fp) for fp in fps]
    for ii, p in enumerate(pathports):
        if not p[1]:
            if ii == 0:
                raise rts_exceptions.NoSourcePortError(cmd_paths[ii])
            else:
                raise rts_exceptions.NoDestPortError(cmd_paths[ii])
        if not p[0][-1]:
            raise rts_exceptions.NotAPortError(cmd_paths[ii])
    paths, ports = list(zip(*pathports))

    if not tree:
        tree = rtctree.tree.RTCTree(paths=paths, filter=paths)

    port_objs = []
    for ii, p in enumerate(pathports):
        obj = tree.get_node(p[0])
        if not obj:
            raise rts_exceptions.NoSuchObjectError(cmd_paths[ii])
        if obj.is_zombie:
            raise rts_exceptions.ZombieObjectError(cmd_paths[ii])
        if not obj.is_component:
            raise rts_exceptions.NotAComponentError(cmd_paths[ii])
        port_obj = obj.get_port_by_name(p[1])
        if not port_obj:
            raise rts_exceptions.PortNotFoundError(p[0], p[1])
        port_objs.append(port_obj)

    conn_name = options.name if options.name else None

    if options.no_dups:
        for p in port_objs:
            if p.get_connection_by_name(conn_name):
                raise rts_exceptions.DuplicateConnectionNameError(
                    conn_name, p.name)
            if options.id:
                if p.get_connection_by_id(options.id):
                    raise rts_exceptions.DuplicateConnectionIDError(options.id)
        if port_objs[0].get_connections_by_dests(port_objs[1:]):
            raise rts_exceptions.DuplicateConnectionError(cmd_paths)

    port_objs[0].connect(port_objs[1:],
                         name=conn_name,
                         id=options.id,
                         props=options.properties)