Exemple #1
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)
Exemple #2
0
 def show_help_line(self):
     if self.help_table.visible:
         text = '(press Q or ESC to exit)'
     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())
Exemple #3
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())
Exemple #4
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
Exemple #5
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
 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
    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
Exemple #8
0
 def add_help_text(self, keys, action_text):
     line = ','.join(keys)
     justify_length = self.columns[0].size - len(line)
     for index, key in enumerate(keys):
         keys[index] = io.bold(key)
     line = ','.join(keys) + ' ' * justify_length
     self.add_help_line(line, action_text)
Exemple #9
0
    def draw_banner_info_lines(self, lines, data):
        if lines > 2:
            tier_type = self.env_data['Tier']['Name']
            tier = '{}'.format(tier_type)
            solutionstack = SolutionStack(self.env_data['SolutionStackName'])
            platform = ' {}'.format(solutionstack.version)
            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
 def test_bold(
         self,
         term_is_colorable_mock,
         init_mock
 ):
     term_is_colorable_mock.return_value = True
     self.assertEqual('\x1b[1mßßßßß\x1b[22m', io.bold(u'ßßßßß'))
     init_mock.assert_called_once()
 def test_bold__term_is_not_colorable(
         self,
         term_is_colorable_mock,
         init_mock
 ):
     term_is_colorable_mock.return_value = False
     self.assertEqual('ßßßßß', io.bold(u'ßßßßß'))
     init_mock.assert_not_called()
Exemple #12
0
    def prompt_and_action(self, prompt_string, action):
        id = ''
        t = term.get_terminal()
        io.echo(t.normal_cursor(), end='')
        # Move cursor to specified empty row
        with t.location(y=self.empty_row, x=2), t.cbreak():
            io.echo(io.bold(prompt_string), end=' ')
            sys.stdout.flush()
            val = None
            while not val or val.name not in {'KEY_ESCAPE', 'KEY_ENTER'}:
                val = t.inkey(timeout=.5)
                if val is None:
                    continue
                elif val.is_sequence is False:
                    id += str(val)
                    sys.stdout.write(str(val))
                    sys.stdout.flush()
                elif val.name == 'KEY_DELETE':  # Backspace
                    if len(id) > 0:
                        id = id[:-1]
                        sys.stdout.write(str(t.move_left) + t.clear_eol)
                        sys.stdout.flush()

        term.hide_cursor()
        if val.name == 'KEY_ESCAPE' or not id:
            return False
        with t.location(y=self.empty_row, x=2):
            sys.stdout.flush()
            io.echo(t.clear_eol(), end='')
            try:
                should_exit_display = action(id)
                if should_exit_display is None:
                    should_exit_display = True
                return should_exit_display
            except (ServiceError, ValidationError, NotFoundError) as e:
                # Error messages that should be shown directly to user
                io.log_error(e.message)
                time.sleep(4)  # Leave screen stable for a little
                return False
            except (IndexError, InvalidOperation, ValueError) as e:
                if self.poller.all_app_versions:  # Error thrown in versions table
                    max_input = len(self.poller.all_app_versions)
                    io.log_error("Enter a number between 1 and " + str(max_input) + ".")
                else:
                    io.log_error(e)
                time.sleep(4)
                return False
            except CaughtSignal as sig:
                if sig.signum == 2:
                    LOG.debug("Caught SIGINT and exiting gracefully from action")
                    return True
            except Exception as e:  # Should never get thrown
                LOG.debug("Exception thrown: {0},{1}. Something strange happened and the request could not be completed."
                             .format(type(e), e.message))
                io.log_error("Something strange happened and the request could not be completed.")
                time.sleep(4)
                return False
Exemple #13
0
    def prompt_and_action(self, prompt_string, action):
        id = ''
        t = term.get_terminal()
        io.echo(t.normal_cursor(), end='')
        # Move cursor to specified empty row
        with t.location(y=self.empty_row, x=2), t.cbreak():
            io.echo(io.bold(prompt_string), end=' ')
            sys.stdout.flush()
            val = None
            while not val or val.name not in {'KEY_ESCAPE', 'KEY_ENTER'}:
                val = t.inkey(timeout=.5)
                if val is None:
                    continue
                elif val.is_sequence is False:
                    id += str(val)
                    sys.stdout.write(str(val))
                    sys.stdout.flush()
                elif val.name == 'KEY_DELETE':  # Backspace
                    if len(id) > 0:
                        id = id[:-1]
                        sys.stdout.write(str(t.move_left) + t.clear_eol)
                        sys.stdout.flush()

        term.hide_cursor()
        if val.name == 'KEY_ESCAPE' or not id:
            return False
        with t.location(y=self.empty_row, x=2):
            sys.stdout.flush()
            io.echo(t.clear_eol(), end='')
            try:
                should_exit_display = action(id)
                if should_exit_display is None:
                    should_exit_display = True
                return should_exit_display
            except (ServiceError, ValidationError, NotFoundError) as e:
                # Error messages that should be shown directly to user
                io.log_error(e.message)
                time.sleep(4)  # Leave screen stable for a little
                return False
            except (IndexError, InvalidOperation, ValueError) as e:
                if self.poller.all_app_versions:  # Error thrown in versions table
                    max_input = len(self.poller.all_app_versions)
                    io.log_error("Enter a number between 1 and " + str(max_input) + ".")
                else:
                    io.log_error(e)
                time.sleep(4)
                return False
            except CaughtSignal as sig:
                if sig.signum == 2:
                    LOG.debug("Caught SIGINT and exiting gracefully from action")
                    return True
            except Exception as e:  # Should never get thrown
                LOG.debug("Exception thrown: {0},{1}. Something strange happened and the request could not be completed."
                             .format(type(e), e.message))
                io.log_error("Something strange happened and the request could not be completed.")
                time.sleep(4)
                return False
    def test_rescue_generic_exception__no_args(self, echo_mock):
        dummy_ebcli_app = MagicMock()
        dummy_ebcli_app.setup = MagicMock(
            side_effect=TestEbRun.MyDummyGenericException(''))

        ebrun.run_app(dummy_ebcli_app)

        echo_mock.assert_called_with(
            io.bold(io.color('red', 'ERROR: MyDummyGenericException')))
        dummy_ebcli_app.close.assert_called_once_with(code=4)
Exemple #15
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)))
Exemple #16
0
    def snapshot_file_view(self):
        data_repr = self.data
        current_time = datetime.now().strftime("%y%m%d-%H%M%S")
        filename = 'health-snapshot-' + current_time + '.json'
        filelocation = fileoperations.get_eb_file_full_location(filename)
        fileoperations.write_json_dict(data_repr, filelocation)

        t = term.get_terminal()
        with t.location(y=self.empty_row, x=2):
            io.echo(io.bold('Snapshot file saved at: .elasticbeanstalk/'
                            + filename), end=' ')
            sys.stdout.flush()
            time.sleep(4)
Exemple #17
0
    def snapshot_file_view(self):
        data_repr = self.data
        current_time = datetime.now().strftime("%y%m%d-%H%M%S")
        filename = 'health-snapshot-' + current_time + '.json'
        filelocation = fileoperations.get_eb_file_full_location(filename)
        fileoperations.write_json_dict(data_repr, filelocation)

        t = term.get_terminal()
        with t.location(y=self.empty_row, x=2):
            io.echo(io.bold('Snapshot file saved at: .elasticbeanstalk/'
                            + filename), end=' ')
            sys.stdout.flush()
            time.sleep(4)
    def test_rescue_EBCLIException__without_verbose_or_debug_flag(
            self, echo_mock):
        dummy_ebcli_app = MagicMock()
        dummy_ebcli_app.setup = MagicMock(
            side_effect=TestEbRun.MyDummyEBCLIException(
                'My Exception Message'))
        ebrun.run_app(dummy_ebcli_app)

        echo_mock.assert_called_with(
            io.bold(
                io.color(
                    'red', 'ERROR: {}'.format(
                        'MyDummyEBCLIException - My Exception Message'))))
        dummy_ebcli_app.close.assert_called_once_with(code=4)
    def test_rescue_AttributeError(self, echo_mock):
        dummy_ebcli_app = MagicMock()
        dummy_ebcli_app.setup = MagicMock(side_effect=AttributeError(
            'This is my error', 'This is my error as well'))

        ebrun.run_app(dummy_ebcli_app)

        echo_mock.assert_called_with(
            io.bold(
                io.color(
                    'red',
                    "ERROR: {error_type} - ('{argument_1}', '{argument_2}')".
                    format(error_type='AttributeError',
                           linesep=os.linesep,
                           argument_1='This is my error',
                           argument_2='This is my error as well'))))
        dummy_ebcli_app.close.assert_called_once_with(code=4)
Exemple #20
0
    def get_column_data(self, data, column):
        if data.get('Copy', False) and column.key != 'Cause':
            d = ' '
        else:
            d = str(data.get(column.key, '-'))

        if column.key == 'Cause'\
            and self.screen.horizontal_offset > self.screen.max_columns:
            cause_scroll = (
                self.screen.horizontal_offset -
                self.screen.max_columns) * StatusTable.CAUSE_SCROLL_FACTOR
            d = d[cause_scroll:]

        c_data = justify_and_trim(d, column.size or column.fit_size,
                                  column.justify)
        if 'Overall' in data.get('InstanceId'):
            c_data = io.bold(c_data)
        return c_data
Exemple #21
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
Exemple #22
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
Exemple #23
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
Exemple #24
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
Exemple #25
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)
Exemple #26
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)
 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)
def color_green(message):
    io.echo(io.bold(io.color('green', message)))
def color_red(message):
    io.echo(io.bold(io.color('red', message)))