示例#1
0
    def draw_banner_first_line(self, lines, data):
        status = data.get('HealthStatus', 'Unknown')
        refresh_time = data.get('RefreshedAt', None)
        if refresh_time is None:
            timestamp = '-'
            countdown = ' ( now )'
        else:
            timestamp = utils.get_local_time_as_string(refresh_time)
            delta = utils.get_delta_from_now_and_datetime(refresh_time)
            diff = 11 - delta.seconds
            if not self.refresh:
                countdown = ''
            elif self.frozen:
                countdown = ' (frozen +{})'.format(delta.seconds)
            elif diff < 0:
                countdown = ' ( now )'
            else:
                countdown = " ({} secs)".format(diff)
        env_name = data.get('EnvironmentName')
        pad_length = (term.width() - len(env_name) - len(timestamp) -
                      len(countdown) - 1)
        if lines > 2:
            banner = io.bold(' {env_name}{status}{time}{cd} ') \
                .format(env_name=env_name,
                        status=status.center(pad_length),
                        time=timestamp,
                        cd=countdown,
                        )
            if not self.mono:
                banner = io.on_color(data.get('Color', 'Grey'), banner)
            term.echo_line(banner)

            lines -= 1
        return lines
示例#2
0
    def draw_rows(self):
        first_row_index = self.first_row_index()
        last_row_index = self.last_row_index()

        for r in range(first_row_index, last_row_index):
            row_data = self.get_row_data(self.data[r])
            term.echo_line(' '.join(row_data))

        self.draw_info_line(first_row_index, last_row_index)
示例#3
0
 def show_help_line(self):
     text = u' (Commands: {q}uit, {d}elete, {l}ifecycle, {down} {up} {left} {right})'.format(
         q=io.bold('Q'),
         d=io.bold('D'),
         l=io.bold('L'),
         down=term.DOWN_ARROW,
         up=term.UP_ARROW,
         left=term.LEFT_ARROW,
         right=term.RIGHT_ARROW)
     term.echo_line(text)
示例#4
0
    def draw_header_row(self):
        super(RequestTable, self).draw_header_row()

        # now draw overall summary
        full_data = self.screen.data
        totals = full_data.get('environment')

        totals['InstanceId'] = '  Overall'
        # We can just draw a single row, but use environment data
        row_data = self.get_row_data(totals)
        term.echo_line(io.bold(' '.join(row_data)))
示例#5
0
 def draw_info_line(self, first_row_index, last_row_index):
     line = u' '
     if last_row_index < len(self.data):
         # Show down arrow
         line += u' {}'.format(term.DOWN_ARROW)
     else:
         line += u'  '
     if first_row_index != 0:
         # Show up arrow
         line += u' {}'.format(term.UP_ARROW)
     term.echo_line(line)
示例#6
0
 def show_help_line(self):
     if self.help_table.visible:
         text = '(press Q or ESC to return)'
     elif self.refresh:
         text = u' (Commands: {h}elp,{q}uit, {down} {up} {left} {right})'\
             .format(h=io.bold('H'), q=io.bold('Q'),
                     down=term.DOWN_ARROW, up=term.UP_ARROW,
                     left=term.LEFT_ARROW, right=term.RIGHT_ARROW)
     else:
         text = u''
     term.echo_line(text)
     term.echo_line(term.clear_eos())
示例#7
0
    def draw_banner_info_lines(self, lines, data):
        if lines > 2:
            status = data.get('Status', 'Unknown')
            term.echo_line('Environment Status:', io.bold(status),
                           'Health', io.bold(data.get('Color', 'Unknown')))
            lines -= 1
        if lines > 2:
            term.echo_line('Current version # deployed:',
                           io.bold(data.get('CurrDeployNum', None)),
                           )
            lines -= 1

        return lines
示例#8
0
 def draw_banner_info_lines(self, lines, data):
     if lines > 2:
         term.echo_line('instances:',
                        io.bold(data.get('Total', 0)), 'Total,',
                        io.bold(data.get('InService', 0)), 'InService,',
                        io.bold(data.get('Other', 0)), 'Other',
                        )
         lines -= 1
     if lines > 2:
         status = data.get('Status', 'Unknown')
         term.echo_line(' Status:', io.bold(status),
                        'Health', io.bold(data.get('Color', 'Grey')))
         lines -= 1
     return lines
示例#9
0
 def draw_banner_info_lines(self, lines, data):
     if lines > 2:
         # Get instance health count
         term.echo_line('instances:',
                        io.bold(data.get('Total', 0)), 'Total,',
                        io.bold(data.get('InService', 0)), 'InService,',
                        io.bold(data.get('Other', 0)), 'Other',
                        )
         lines -= 1
     if lines > 2:
         status = data.get('Status', 'Unknown')
         term.echo_line(' Status:', io.bold(status),
                        'Health', io.bold(data.get('Color', 'Grey')))
         lines -= 1
     return lines
示例#10
0
    def draw_banner_first_line(self, lines, data):
        if lines > 2:
            app_name = 'Application Name: {}'.format(self.poller.app_name)
            env_name = self.poller.env_name

            if env_name is None:
                env_name = 'No Environment Specified'

            pad_length = term.width() - len(env_name)

            banner = io.bold(' {env_name}{app_name} ') \
                .format(env_name=env_name,
                        app_name=app_name.center(pad_length),
                        )
            if not self.mono:
                banner = io.on_color(data.get('Color', 'Grey'), banner)
            term.echo_line(banner)

            lines -= 1
        return lines
示例#11
0
    def draw_banner_first_line(self, lines, data):
        if lines > 2:
            app_name = 'Application Name: {}'.format(self.poller.app_name)
            env_name = self.poller.env_name

            if env_name is None:
                env_name = 'No Environment Specified'

            pad_length = term.width() - len(env_name)

            banner = io.bold(' {env_name}{app_name} ') \
                .format(env_name=env_name,
                        app_name=app_name.center(pad_length),
                        )
            if not self.mono:
                banner = io.on_color(data.get('Color', 'Grey'), banner)
            term.echo_line(banner)

            lines -= 1
        return lines
示例#12
0
文件: table.py 项目: mschmutz1/jokic
    def draw_header_row(self):
        # Print headers
        t = term.get_terminal()
        labels = [' ']
        width = self.width
        for c in [0] + list(range(self.first_column, len(self.columns))):
            column = self.columns[c]
            column_size = column.size
            if column_size is None:
                column_size = self.get_widest_data_length_in_column(
                    self.columns[c]) + 2
                # special case for Description column this should be the same for all description columns, allows very
                #   large descriptions that we are able to scroll through.
                if column.name == 'Description' and column_size > self.MAX_DESCRIPTION:
                    column_size = self.MAX_DESCRIPTION
                column.fit_size = column_size
            header = justify_and_trim(column.name, column_size, column.justify)
            if (self.screen.sort_index and  # We are sorting
                    self.screen.sort_index[1] == c and  # Sort column
                    self.name == self.screen.sort_index[0] and  # sort table
                    len(' '.join(labels)) < width):  # Column is on screen
                format_string = '{n}{b}{u}{data}{n}{r}'
                header = format_string.replace('{data}', header)
                width += len(format_string) - 6
            labels.append(header)

        header_text = justify_and_trim(' '.join(labels), width, 'left')

        # header title
        if header_text[-Table.HEADER_SPACE_NEEDED:].isspace():
            header_text = (
                header_text[:-Table.HEADER_SPACE_NEEDED] + '  {n}{b} ' +
                justify_and_trim(self.name, Table.HEADER_WIDTH, 'right') +
                ' {r} ')
        header_text = header_text.format(n=t.normal,
                                         b=t.bold,
                                         u=term.underline(),
                                         r=term.reverse_())
        header_text += t.normal

        term.echo_line(term.reverse_colors(header_text))
示例#13
0
    def draw(self, key):
        """Formats and draws banner and tables in screen.
        :param key is 'instances' for health tables and 'app_versions' for versions table.
        """
        self.data = self.sort_data(self.data)
        n = term.height() - 1
        n = self.draw_banner(n, self.data)
        term.echo_line()
        n -= 2  # Account for empty lines before and after tables
        visible_count = 0
        for table in self.tables:
            if table.visible:
                visible_count += 1
                n -= table.header_size
        if visible_count != 0:
            visible_rows = n // visible_count
            if visible_rows > 0:  # Dont show tables if no visible rows.
                self.max_columns = max(
                    [len(t.columns) for t in self.tables if t.visible]) - 1
                for table in self.tables:
                    table.draw(visible_rows, self.data[key])

        self.show_help_line()
示例#14
0
    def draw_banner_info_lines(self, lines, data):
        if lines > 2:
            tier_type = self.env_data['Tier']['Name']
            tier = '{}'.format(tier_type)

            try:
                platform_arn = self.env_data['PlatformArn']
                platform_version = PlatformVersion(platform_arn)
                platform = ' {}/{}'.format(platform_version.platform_shorthand,
                                           platform_version.platform_version)
            except KeyError:
                solutionstack = SolutionStack(
                    self.env_data['SolutionStackName'])
                platform = ' {}'.format(solutionstack.platform_shorthand)

            term.echo_line('{tier}{pad}{platform} '.format(
                tier=tier,
                platform=platform,
                pad=' ' * (term.width() - len(tier) - len(platform))))

            lines -= 1
        if lines > 3:
            # Get instance health count
            instance_counts = OrderedDict([
                ('total', data.get('Total', 0)),
                ('ok', data.get('Ok', 0)),
                ('warning', data.get('Warning', 0)),
                ('degraded', data.get('Degraded', 0)),
                ('severe', data.get('Severe', 0)),
                ('info', data.get('Info', 0)),
                ('pending', data.get('Pending', 0)),
                ('unknown', data.get('Unknown', 0) + data.get('NoData', 0)),
            ])
            column_size = max(len(k) for k in instance_counts) + 1
            term.echo_line(''.join(
                (s.center(column_size) for s in instance_counts)))
            term.echo_line(''.join(
                (io.bold((str(v).center(column_size)))
                 for k, v in six.iteritems(instance_counts))))
            lines -= 2

        return lines
示例#15
0
 def draw_banner_info_lines(self, lines):
     if lines > 2:
         term.echo_line(self.header_text)
         lines -= 1
     return lines
示例#16
0
 def show_help_line(self):
     text = u' (Commands: {q}uit, {d}elete, {l}ifecycle, {down} {up} {left} {right})' \
         .format(q=io.bold('Q'), d=io.bold('D'), l=io.bold('L'),
                 down=term.DOWN_ARROW, up=term.UP_ARROW,
                 left=term.LEFT_ARROW, right=term.RIGHT_ARROW)
     term.echo_line(text)
示例#17
0
 def draw_banner_info_lines(self, lines):
     if lines > 2:
         term.echo_line(self.header_text)
         lines -= 1
     return lines
示例#18
0
 def show_help_line(self):
     text = u' (Commands: {q}uit, {r}estore, {down} {up})' \
         .format(q=io.bold('Q'), r=io.bold('R'),
                 down=term.DOWN_ARROW, up=term.UP_ARROW)
     term.echo_line(text)
示例#19
0
 def show_help_line(self):
     text = u' (Commands: {q}uit, {r}estore, {down} {up})' \
         .format(q=io.bold('Q'), r=io.bold('R'),
                 down=term.DOWN_ARROW, up=term.UP_ARROW)
     term.echo_line(text)