예제 #1
0
    def start_screen(self,
                     poller,
                     env_data,
                     refresh,
                     mono=False,
                     default_table='split'):
        self.mono = mono
        self.env_data = env_data
        self.refresh = refresh
        term.hide_cursor()
        self.turn_on_table(default_table)

        # Timeout at 2 hours of inactivity
        self.idle_time = datetime.now()
        timediff = timedelta(hours=2)
        while (datetime.now() - self.idle_time) < timediff:
            try:
                self.get_data(poller)
                if not self.data:
                    return
                self.draw('instances')
                term.reset_terminal()
                if not refresh:
                    return
                should_exit = self.handle_input()
                if should_exit:
                    return

            except IOError as e:
                if e.errno == errno.EINTR:  # Sometimes thrown while sleeping
                    continue
                else:
                    raise
예제 #2
0
    def start_version_screen(self, data, table):
        """"Turn on and populate table 'versions' in screen with data"""
        pages = True
        term.hide_cursor()
        self.turn_on_table(table)
        self.data = data
        if not pages:
            self.draw('app_versions')
            term.reset_terminal()
        else:
            # Timeout at 19 minutes of inactivity since API's NextToken disappears at 20
            self.idle_time = datetime.now()
            timediff = timedelta(minutes=19)
            while (datetime.now() - self.idle_time) < timediff:
                try:
                    self.draw('app_versions')
                    term.reset_terminal()
                    should_exit = self.handle_input()
                    if should_exit:
                        return

                except IOError as e:
                    if e.errno == errno.EINTR:  # Sometimes thrown while sleeping
                        continue
                    else:
                        raise
예제 #3
0
    def start_version_screen(self, data, table):
        """"Turn on and populate table 'environments' in screen with data"""
        pages = True
        term.hide_cursor()
        self.turn_on_table(table)
        self.data = data
        if not pages:
            self.draw(TABLE_DATA_KEY)
            term.reset_terminal()
        else:
            # Timeout at 19 minutes of inactivity since API's NextToken disappears at 20
            self.idle_time = datetime.now()
            timediff = timedelta(minutes=19)
            while (datetime.now() - self.idle_time) < timediff:
                try:
                    self.draw(TABLE_DATA_KEY)
                    term.reset_terminal()
                    should_exit = self.handle_input()
                    if should_exit:
                        return

                except IOError as e:
                    if e.errno == errno.EINTR:  # Sometimes thrown while sleeping
                        continue
                    else:
                        raise
예제 #4
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