示例#1
0
    def get_state_string(self, add_colour=True):
        """Get the state of this component as an optionally-coloured string.

        @param add_colour If True, ANSI colour codes will be added to the
                          string.
        @return A string describing the state of this component.

        """
        with self._mutex:
            if self.state == self.INACTIVE:
                result = "Inactive", ["bold", "blue"]
            elif self.state == self.ACTIVE:
                result = "Active", ["bold", "green"]
            elif self.state == self.ERROR:
                result = "Error", ["bold", "white", "bgred"]
            elif self.state == self.UNKNOWN:
                result = "Unknown", ["bold", "red"]
            elif self.state == self.CREATED:
                result = "Created", ["reset"]
        if add_colour:
            return (
                utils.build_attr_string(result[1], supported=add_colour)
                + result[0]
                + utils.build_attr_string("reset", supported=add_colour)
            )
        else:
            return result[0]
示例#2
0
文件: rtconf.py 项目: gbiggs/rtcshell
def format_conf_sets(sets, active_set_name, use_colour, long):
    result = []
    indent = 0
    set_keys = sets.keys()
    set_keys.sort()
    for set_name in set_keys:
        if long:
            tag = '-'
        else:
            tag = '+'
        if set_name == active_set_name:
            title = tag + build_attr_string(['bold', 'green'],
                                            supported=use_colour) + \
                    set_name + '*' + build_attr_string('reset',
                                                       supported=use_colour)
            if sets[set_name].description:
                title += ' ({0})'.format(sets[set_name].description)
        else:
            title = tag + build_attr_string('bold', supported=use_colour) + \
                    set_name + build_attr_string('reset', supported=use_colour)
            if sets[set_name].description:
                title += '  ({0})'.format(sets[set_name].description)
        result.append(title)

        if long:
            params = sets[set_name].data.keys()
            if params:
                params.sort()
                padding = len(max(params, key=len)) + 2
                indent += 2
                for param in params:
                    result.append('{0}{1}{2}'.format(''.ljust(indent),
                            param.ljust(padding), sets[set_name].data[param]))
                indent -= 2
    return result
示例#3
0
    def running_as_string(self, add_colour=True):
        '''Get the state of this context as an optionally coloured string.

        @param add_colour If True, ANSI colour codes will be added.
        @return A string describing this context's running state.

        '''
        with self._mutex:
            if self.running:
                result = 'Running', ['bold', 'green']
            else:
                result = 'Stopped', ['reset']
        if add_colour:
            return build_attr_string(result[1], supported=add_colour) + \
                    result[0] + build_attr_string('reset', supported=add_colour)
        else:
            return result[0]
示例#4
0
    def running_as_string(self, add_colour=True):
        '''Get the state of this context as an optionally coloured string.

        @param add_colour If True, ANSI colour codes will be added.
        @return A string describing this context's running state.

        '''
        with self._mutex:
            if self.running:
                result = 'Running', ['bold', 'green']
            else:
                result = 'Stopped', ['reset']
        if add_colour:
            return utils.build_attr_string(result[1], supported=add_colour) + \
                    result[0] + utils.build_attr_string('reset', supported=add_colour)
        else:
            return result[0]
示例#5
0
    def kind_as_string(self, add_colour=True):
        '''Get the type of this context as an optionally coloured string.

        @param add_colour If True, ANSI colour codes will be added.
        @return A string describing the kind of execution context this is.

        '''
        with self._mutex:
            if self.kind == self.PERIODIC:
                result = 'Periodic', ['reset']
            elif self.kind == self.EVENT_DRIVEN:
                result = 'Event-driven', ['reset']
            elif self.kind == self.OTHER:
                result = 'Other', ['reset']
        if add_colour:
            return build_attr_string(result[1], supported=add_colour) + \
                    result[0] + build_attr_string('reset', supported=add_colour)
        else:
            return result[0]
示例#6
0
    def polarity_as_string(self, add_colour=True):
        '''Get the polarity of this interface as a string.

        @param add_colour If True, ANSI colour codes will be added to the
                          string.
        @return A string describing the polarity of this interface.

        '''
        with self._mutex:
            if self.polarity == self.PROVIDED:
                result = 'Provided', ['reset']
            elif self.polarity == self.REQUIRED:
                result = 'Required', ['reset']
            if add_colour:
                return build_attr_string(result[1], supported=add_colour) + \
                        result[0] + build_attr_string('reset',
                                supported=add_colour)
            else:
                return result[0]
示例#7
0
    def kind_as_string(self, add_colour=True):
        '''Get the type of this context as an optionally coloured string.

        @param add_colour If True, ANSI colour codes will be added.
        @return A string describing the kind of execution context this is.

        '''
        with self._mutex:
            if self.kind == self.PERIODIC:
                result = 'Periodic', ['reset']
            elif self.kind == self.EVENT_DRIVEN:
                result = 'Event-driven', ['reset']
            elif self.kind == self.OTHER:
                result = 'Other', ['reset']
        if add_colour:
            return utils.build_attr_string(result[1], supported=add_colour) + \
                    result[0] + utils.build_attr_string('reset', supported=add_colour)
        else:
            return result[0]
示例#8
0
    def polarity_as_string(self, add_colour=True):
        '''Get the polarity of this interface as a string.

        @param add_colour If True, ANSI colour codes will be added to the
                          string.
        @return A string describing the polarity of this interface.

        '''
        with self._mutex:
            if self.polarity == self.PROVIDED:
                result = 'Provided', ['reset']
            elif self.polarity == self.REQUIRED:
                result = 'Required', ['reset']
            if add_colour:
                return utils.build_attr_string(result[1], supported=add_colour) + \
                        result[0] + utils.build_attr_string('reset',
                                supported=add_colour)
            else:
                return result[0]
示例#9
0
文件: rtls.py 项目: gbiggs/rtcshell
def list_directory(dir_node, long=False):
    listing = dir_node.children
    use_colour = colour_supported(sys.stdout)
    if long:
        lines = get_node_long_lines(listing, use_colour=use_colour)
        return lines
    else:
        items = []
        for entry in listing:
            if entry.is_directory:
                items.append((build_attr_string(['bold', 'blue'],
                                supported=use_colour) + \
                              entry.name + '/' + \
                              build_attr_string(['reset'],
                                supported=use_colour),
                             entry.name))
            elif entry.is_component:
                items.append((entry.name, entry.name))
            elif entry.is_manager:
                items.append((build_attr_string(['bold', 'green'],
                                supported=use_colour) + \
                              entry.name + \
                              build_attr_string(['reset'],
                                  supported=use_colour),
                             entry.name))
            else:
                items.append((build_attr_string(['faint', 'white'],
                                supported=use_colour) + \
                              entry.name + \
                              build_attr_string(['reset'],
                                  supported=use_colour),
                             entry.name))
        return format_items_list(items)
示例#10
0
    def get_state_in_ec_string(self, ec_index, add_colour=True):
        """Get the state of the component in an execution context as a string.

        @param ec_index The index of the execution context to check the state
                        in. This index is into the total array of contexts,
                        that is both owned and participating contexts. If the
                        value of ec_index is greater than the length of @ref
                        owned_ecs, that length is subtracted from ec_index and
                        the result used as an index into @ref
                        participating_ecs.

        """
        with self._mutex:
            if ec_index >= len(self.owned_ecs):
                ec_index -= len(self.owned_ecs)
                if ec_index >= len(self.participating_ecs):
                    raise exceptions.BadECIndexError(ec_index)
                state = self.participating_ec_states[ec_index]
            else:
                state = self.owned_ec_states[ec_index]
        if state == self.INACTIVE:
            result = "Inactive", ["bold", "blue"]
        elif state == self.ACTIVE:
            result = "Active", ["bold", "green"]
        elif state == self.ERROR:
            result = "Error", ["bold", "white", "bgred"]
        elif state == self.UNKNOWN:
            result = "Unknown", ["bold", "red"]
        elif state == self.CREATED:
            result = "Created", ["reset"]
        if add_colour:
            return (
                utils.build_attr_string(result[1], supported=add_colour)
                + result[0]
                + utils.build_attr_string("reset", supported=add_colour)
            )
        else:
            return result[0]
示例#11
0
    def get_state_in_ec_string(self, ec_index, add_colour=True):
        '''Get the state of the component in an execution context as a string.

        @param ec_index The index of the execution context to check the state
                        in. This index is into the total array of contexts,
                        that is both owned and participating contexts. If the
                        value of ec_index is greater than the length of @ref
                        owned_ecs, that length is subtracted from ec_index and
                        the result used as an index into @ref
                        participating_ecs.

        '''
        with self._mutex:
            if ec_index >= len(self.owned_ecs):
                ec_index -= len(self.owned_ecs)
                if ec_index >= len(self.participating_ecs):
                    raise BadECIndexError(ec_index)
                state = self.participating_ec_states[ec_index]
            else:
                state = self.owned_ec_states[ec_index]
        if state == self.INACTIVE:
            result = 'Inactive', ['bold', 'blue']
        elif state == self.ACTIVE:
            result = 'Active', ['bold', 'green']
        elif state == self.ERROR:
            result = 'Error', ['bold', 'white', 'bgred']
        elif state == self.UNKNOWN:
            result = 'Unknown', ['bold', 'red']
        elif state == self.CREATED:
            result = 'Created', ['reset']
        if add_colour:
            return build_attr_string(result[1], supported=add_colour) + \
                    result[0] + build_attr_string('reset',
                    supported=add_colour)
        else:
            return result[0]
示例#12
0
    def get_state_string(self, add_colour=True):
        '''Get the state of this component as an optionally-coloured string.

        @param add_colour If True, ANSI colour codes will be added to the
                          string.
        @return A string describing the state of this component.

        '''
        with self._mutex:
            if self.state == self.INACTIVE:
                result = 'Inactive', ['bold', 'blue']
            elif self.state == self.ACTIVE:
                result = 'Active', ['bold', 'green']
            elif self.state == self.ERROR:
                result = 'Error', ['bold', 'white', 'bgred']
            elif self.state == self.UNKNOWN:
                result = 'Unknown', ['bold', 'red']
            elif self.state == self.CREATED:
                result = 'Created', ['reset']
        if add_colour:
            return build_attr_string(result[1], supported=add_colour) + \
                    result[0] + build_attr_string('reset', supported=add_colour)
        else:
            return result[0]
示例#13
0
    def get_state_in_ec_string(self, ec_index, add_colour=True):
        '''Get the state of the component in an execution context as a string.

        @param ec_index The index of the execution context to check the state
                        in. This index is into the total array of contexts,
                        that is both owned and participating contexts. If the
                        value of ec_index is greater than the length of @ref
                        owned_ecs, that length is subtracted from ec_index and
                        the result used as an index into @ref
                        participating_ecs.

        '''
        with self._mutex:
            if ec_index >= len(self.owned_ecs):
                ec_index -= len(self.owned_ecs)
                if ec_index >= len(self.participating_ecs):
                    raise exceptions.BadECIndexError(ec_index)
                state = self.participating_ec_states[ec_index]
            else:
                state = self.owned_ec_states[ec_index]
        if state == self.INACTIVE:
            result = 'Inactive', ['bold', 'blue']
        elif state == self.ACTIVE:
            result = 'Active', ['bold', 'green']
        elif state == self.ERROR:
            result = 'Error', ['bold', 'white', 'bgred']
        elif state == self.UNKNOWN:
            result = 'Unknown', ['bold', 'red']
        elif state == self.CREATED:
            result = 'Created', ['reset']
        if add_colour:
            return utils.build_attr_string(result[1], supported=add_colour) + \
                    result[0] + utils.build_attr_string('reset',
                    supported=add_colour)
        else:
            return result[0]
示例#14
0
    def get_state_string(self, add_colour=True):
        '''Get the state of this component as an optionally-coloured string.

        @param add_colour If True, ANSI colour codes will be added to the
                          string.
        @return A string describing the state of this component.

        '''
        with self._mutex:
            if self.state == self.INACTIVE:
                result = 'Inactive', ['bold', 'blue']
            elif self.state == self.ACTIVE:
                result = 'Active', ['bold', 'green']
            elif self.state == self.ERROR:
                result = 'Error', ['bold', 'white', 'bgred']
            elif self.state == self.UNKNOWN:
                result = 'Unknown', ['bold', 'red']
            elif self.state == self.CREATED:
                result = 'Created', ['reset']
        if add_colour:
            return utils.build_attr_string(result[1], supported=add_colour) + \
                    result[0] + utils.build_attr_string('reset', supported=add_colour)
        else:
            return result[0]
示例#15
0
文件: rtcat.py 项目: gbiggs/rtcshell
def format_component(object, use_colour=True, long=False, really_long=False):
    result = []
    result.append('{0}  {1}'.format(object.name,
            object.get_state_string(add_colour=use_colour)))

    indent = 2
    profile_items = [('Category', object.category),
                     ('Description', object.description),
                     ('Instance name', object.instance_name),
                     ('Type name', object.type_name),
                     ('Vendor', object.vendor),
                     ('Version', object.version)]
    if object.parent:
        profile_items.append(('Parent', object.parent_object))
    pad_length = max([len(item[0]) for item in profile_items]) + 2
    for item in profile_items:
        result.append('{0}{1}{2}'.format(''.ljust(indent),
                                         item[0].ljust(pad_length),
                                         item[1]))

    if object.properties:
        result.append('{0}Extra properties:'.format(''.ljust(indent)))
        indent += 2
        extra_props = object.properties
        keys = extra_props.keys()
        keys.sort()
        pad_length = max([len(key) for key in keys]) + 2
        for key in keys:
            result.append('{0}{1}{2}'.format(''.ljust(indent),
                                             key.ljust(pad_length),
                                             extra_props[key]))
        indent -= 2

    for ec in object.owned_ecs:
        if long:
            result.append('{0}Execution Context {1}'.format(\
                    '-'.rjust(indent), ec.handle))
            padding = 7 # = len('State') + 2
            indent += 2
            result.append('{0}{1}{2}'.format(''.ljust(indent),
                'State'.ljust(padding),
                ec.running_as_string(add_colour=use_colour)))
            result.append('{0}{1}{2}'.format(''.ljust(indent),
                'Kind'.ljust(padding),
                ec.kind_as_string(add_colour=use_colour)))
            result.append('{0}{1}{2}'.format(''.ljust(indent),
                'Rate'.ljust(padding), ec.rate))
            if ec.owner_name:
                result.append('{0}{1}{2}'.format(''.ljust(indent),
                    'Owner'.ljust(padding), ec.owner_name))
            if ec.participant_names:
                if really_long:
                        result.append('{0}{1}'.format('-'.rjust(indent),
                            'Participants'.ljust(padding)))
                        indent += 2
                        for pn in ec.participant_names:
                            result.append('{0}{1}'.format(''.ljust(indent),
                                pn))
                        indent -= 2
                else:
                    result.append('{0}{1}'.format('+'.rjust(indent),
                        'Participants'.ljust(padding)))
            if ec.properties:
                if really_long:
                    result.append('{0}{1}'.format('-'.rjust(indent),
                        'Extra properties'.ljust(padding)))
                    indent += 2
                    keys = ec.properties.keys()
                    keys.sort()
                    pad_length = max([len(key) for key in keys]) + 2
                    for key in keys:
                        result.append('{0}{1}{2}'.format(''.ljust(indent),
                             key.ljust(pad_length), ec.properties[key]))
                    indent -= 2
                else:
                    result.append('{0}{1}'.format('+'.rjust(indent),
                        'Extra properties'.ljust(padding)))
            indent -= 2
        else:
            result.append('{0}Execution Context {1}'.format(\
                    '+'.rjust(indent), ec.handle))

    for port in object.ports:
        if long:
            tag = '-'
        else:
            tag = '+'
        name_string = build_attr_string('bold', supported=use_colour) + \
                port.name + build_attr_string('reset', supported=use_colour)
        result.append('{0}{1}: {2}'.format(tag.rjust(indent), port.porttype,
                                           name_string))
        if long:
            indent += 2
            keys = port.properties.keys()
            keys.sort()
            pad_length = max([len(key) for key in keys]) + 2
            for key in keys:
                result.append('{0}{1}{2}'.format(''.ljust(indent),
                        key.ljust(pad_length), port.properties[key]))
            if port.porttype == 'CorbaPort' and port.interfaces:
                for intf in port.interfaces:
                    result.append('{0}Interface:'.format(''.ljust(indent)))
                    pad_length = 15 # = len('Instance name') + 2
                    indent += 2
                    result.append('{0}{1}{2}'.format(''.ljust(indent),
                            'Instance name'.ljust(pad_length),
                            intf.instance_name))
                    result.append('{0}{1}{2}'.format(''.ljust(indent),
                            'Type name'.ljust(pad_length),
                            intf.type_name))
                    result.append('{0}{1}{2}'.format(''.ljust(indent),
                            'Polarity'.ljust(pad_length),
                            intf.polarity_as_string(add_colour=use_colour)))
                    indent -= 2
            num_conns = len(port.connections)
            for conn in port.connections:
                if really_long:
                    tag2 = '-'
                else:
                    tag2 = '+'
                dest_ports = []
                for name, p in conn.ports:
                    # Handle the case of unknown port owners
                    if not p:
                        dest_ports.append(name)
                        num_conns -= 1
                    # Filter out ports belonging to this object
                    elif not object.get_port_by_ref(p.object):
                        dest_ports.append(name)
                        num_conns -= 1
                if dest_ports:
                    result.append('{0}Connected to  {1}'.format(\
                            tag2.rjust(indent),
                            build_attr_string('bold', supported=use_colour) +\
                            dest_ports[0] + \
                            build_attr_string('reset', supported=use_colour)))
                    if len(dest_ports) > 1:
                        for dp in dest_ports[1:]:
                            result.append('{0}{1}{2}'.format(''.ljust(indent),
                                                             ''.ljust(14),
                            build_attr_string('bold', supported=use_colour) +\
                            dp + \
                            build_attr_string('reset', supported=use_colour)))
                    if really_long:
                        indent += 2
                        keys = [k for k in conn.properties.keys() \
                                if not k.endswith('inport_ref') \
                                if not k.endswith('inport_ior')]
                        pad_length = max([len('Name')] + \
                                         [len(key) for key in keys]) + 2
                        result.append('{0}{1}{2}'.format(''.ljust(indent),
                                'Name'.ljust(pad_length), conn.name))
                        result.append('{0}{1}{2}'.format(''.ljust(indent),
                                'ID'.ljust(pad_length), conn.id))
                        for key in keys:
                            result.append('{0}{1}{2}'.format(''.ljust(indent),
                                    key.ljust(pad_length),
                                    conn.properties[key]))
                        indent -= 2
            if num_conns > 0:
                if num_conns > 1:
                    plural = 's'
                else:
                    plural = ''
                result.append('{0}({1} other connection{2})'.format(\
                        ''.rjust(indent), num_conns, plural))
            indent -= 2

    return result
示例#16
0
文件: rtls.py 项目: gbiggs/rtcshell
def get_node_long_lines(nodes, use_colour=True):
    info_strings = []
    state_width = 0
    total_width = 0
    in_width = 0
    out_width = 0
    svc_width = 0
    for node in nodes:
        if node.is_directory:
            if state_width == 0:
                state_width = 1
            if total_width == 0:
                total_width = 1
            if in_width == 0:
                in_width = 1
            if out_width == 0:
                out_width = 1
            if svc_width == 0:
                svc_width = 1
            name = build_attr_string(['bold', 'blue'],
                        supported=use_colour) + \
                    node.name + build_attr_string(['reset'],
                        supported=use_colour)
            info_strings.append((('-', 0), ('-', 0), ('-', 0),
                                 ('-', 0), ('-', 0), name))
        elif node.is_manager:
            # Managers are not handled yet
            if state_width == 0:
                state_width = 1
            if total_width == 0:
                total_width = 1
            if in_width == 0:
                in_width = 1
            if out_width == 0:
                out_width = 1
            if svc_width == 0:
                svc_width = 1
            name = build_attr_string(['bold', 'green'],
                        supported=use_colour) + \
                    node.name + build_attr_string(['reset'],
                        supported=use_colour)
            info_strings.append((('-', 0), ('-', 0), ('-', 0),
                                 ('-', 0), ('-', 0), name))
        elif node.is_component:
            state = node.state
            state_string = node.plain_state_string
            if len(state_string) > state_width:
                state_width = len(state_string)
            state_string = (node.get_state_string(add_colour=use_colour),
                    len(node.get_state_string(add_colour=use_colour)) - \
                            len(state_string))

            num_ports = len(node.ports)
            num_connected = len(node.connected_ports)
            total_string = '{0}/{1}'.format(num_ports, num_connected)
            if len(total_string) > total_width:
                total_width = len(total_string)
            coloured_string = build_attr_string('bold',
                                supported=use_colour) + \
                              str(num_ports) + \
                              build_attr_string('reset',
                                supported=use_colour) + '/' + \
                              str(num_connected)
            total_string = (coloured_string, len(coloured_string) - \
                                len(total_string))

            num_ports = len(node.inports)
            num_connected = len(node.connected_inports)
            in_string = '{0}/{1}'.format(num_ports, num_connected)
            if len(in_string) > in_width:
                in_width = len(in_string)
            coloured_string = build_attr_string('bold',
                                supported=use_colour) + \
                              str(num_ports) + \
                              build_attr_string('reset',
                                supported=use_colour) + '/' + \
                              str(num_connected)
            in_string = (coloured_string, len(coloured_string) - \
                                len(in_string))

            num_ports = len(node.outports)
            num_connected = len(node.connected_outports)
            out_string = '{0}/{1}'.format(num_ports, num_connected)
            if len(out_string) > out_width:
                out_width = len(out_string)
            coloured_string = build_attr_string('bold',
                                supported=use_colour) + \
                              str(num_ports) + \
                              build_attr_string('reset',
                                supported=use_colour) + '/' + \
                              str(num_connected)
            out_string = (coloured_string, len(coloured_string) - \
                                len(out_string))

            num_ports = len(node.svcports)
            num_connected = len(node.connected_svcports)
            svc_string = '{0}/{1}'.format(num_ports, num_connected)
            if len(svc_string) > svc_width:
                svc_width = len(svc_string)
            coloured_string = build_attr_string('bold',
                                supported=use_colour) + \
                              str(num_ports) + \
                              build_attr_string('reset',
                                supported=use_colour) + '/' + \
                              str(num_connected)
            svc_string = (coloured_string, len(coloured_string) - \
                                len(svc_string))

            info_strings.append((state_string, total_string, in_string,
                                 out_string, svc_string, node.name))
        else:
            # Other types are unknowns
            if state_width == 0:
                state_width = 1
            if total_width == 0:
                total_width = 1
            if in_width == 0:
                in_width = 1
            if out_width == 0:
                out_width = 1
            if svc_width == 0:
                svc_width = 1
            name = build_attr_string(['faint', 'white'],
                        supported=use_colour) + \
                    node.name + build_attr_string(['reset'],
                        supported=use_colour)
            info_strings.append((('-', 0), ('-', 0), ('-', 0),
                                 ('-', 0), ('-', 0), name))
    state_width += 2
    total_width += 2
    in_width += 2
    out_width += 2
    svc_width += 2

    result = []
    for string in info_strings:
        result.append('{0}{1}{2}{3}{4}{5}'.format(
                string[0][0].ljust(state_width + string[0][1]),
                string[1][0].ljust(total_width + string[1][1]),
                string[2][0].ljust(in_width + string[2][1]),
                string[3][0].ljust(out_width + string[3][1]),
                string[4][0].ljust(svc_width + string[4][1]),
                string[5]))
    return result