def handle_input(self): t = term.get_terminal() with t.cbreak(): # Get input val = t.inkey(timeout=.5) if val: char = str(val).upper() LOG.debug('Got val: {0}, {1}, {2}.'.format( val, val.name, val.code)) if char == 'Q': # Quit return True # Exit command elif val.code == 361: return True # elif char == 'R': # return self.redeploy(t) elif char == 'D': return self.delete(t) elif char == 'L': return self.interactive_lifecycle(t) elif val.name == 'KEY_DOWN': # Down arrow self._get_more_pages(t) elif val.name == 'KEY_UP': # Up arrow self._get_less_pages(t) elif val.name == 'KEY_LEFT': # Left arrow self.scroll_over(reverse=True) elif val.name == 'KEY_RIGHT': # Right arrow self.scroll_over()
def handle_input(self): t = term.get_terminal() with t.cbreak(): # Get input val = t.inkey(timeout=.5) if val: char = str(val).upper() LOG.debug('Got val: {0}, {1}, {2}.' .format(val, val.name, val.code)) if char == 'Q': # Quit return True # Exit command elif val.code == 361: return True # elif char == 'R': # return self.redeploy(t) elif char == 'D': return self.delete(t) elif char == 'L': return self.interactive_lifecycle(t) elif val.name == 'KEY_DOWN': # Down arrow self._get_more_pages(t) elif val.name == 'KEY_UP': # Up arrow self._get_less_pages(t) elif val.name == 'KEY_LEFT': # Left arrow self.scroll_over(reverse=True) elif val.name == 'KEY_RIGHT': # Right arrow self.scroll_over()
def restore_environment_num(self, environment_number): """Take in user input as a string, convert it to a decimal, get the environment that the user input matches, and attempt to restore that environment. """ environment_number = int( environment_number) # raises InvalidOperation Exception environments = self.poller.all_environments e_len = len(environments) if environment_number > e_len or environment_number < 1: raise IndexError environment = environments[e_len - environment_number] env_id = environment.get(u'EnvironmentId') should_exit_display = True if env_id: try: self.flusher(term.get_terminal()) io.validate_action( prompts['restore.selectedenv'].replace( '{env_id}', env_id).replace( '{app}', utils.encode_to_ascii( environment.get('ApplicationName'))).replace( '{desc}', utils.encode_to_ascii( environment.get('Description'))). replace('{cname}', utils.encode_to_ascii( environment.get('CNAME'))).replace( '{version}', utils.encode_to_ascii( environment.get('VersionLabel'))). replace( '{platform}', utils.encode_to_ascii( environment.get('SolutionStackName'))).replace( '{dat_term}', environment.get('DateUpdated')), 'y') from ebcli.operations import restoreops # restore specified environment self.request_id = restoreops.restore(env_id) return should_exit_display except ValidationError: io.echo(responses['restore.norestore']) time.sleep(1) should_exit_display = False return should_exit_display # Exception should never get thrown else: raise Exception
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 handle_input(self): t = term.get_terminal() with t.cbreak(): # Get input val = t.inkey(timeout=.5) if val: char = str(val).upper() LOG.debug('Got val: {0}, {1}, {2}.' .format(val, val.name, val.code)) if char == 'Q': # Quit return True # Exit command elif val.code == 361: return True elif char == 'R': return self.restore(t) elif val.name == 'KEY_DOWN': # Down arrow self._get_more_pages(t) elif val.name == 'KEY_UP': # Up arrow self._get_less_pages(t)
def handle_input(self): t = term.get_terminal() with t.cbreak(): # Get input val = t.inkey(timeout=.5) if val: char = str(val).upper() LOG.debug('Got val: {0}, {1}, {2}.' .format(val, val.name, val.code)) if char == 'Q': # Quit return True # Exit command elif val.code == 361: return True elif char == 'R': return self.restore(t) elif val.name == 'KEY_DOWN': # Down arrow self._get_more_pages(t) elif val.name == 'KEY_UP': # Up arrow self._get_less_pages(t)
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))
def restore_environment_num(self, environment_number): """Take in user input as a string, convert it to a decimal, get the environment that the user input matches, and attempt to restore that environment. """ environment_number = int(environment_number) # raises InvalidOperation Exception environments = self.poller.all_environments e_len = len(environments) if environment_number > e_len or environment_number < 1: raise IndexError environment = environments[e_len - environment_number] env_id = environment.get(u'EnvironmentId') should_exit_display = True if env_id: self.flusher(term.get_terminal()) prompt_text = prompts['restore.selectedenv'].format( env_id=env_id, app=utils.encode_to_ascii(environment.get('ApplicationName')), desc=utils.encode_to_ascii(environment.get('Description')), cname=utils.encode_to_ascii(environment.get('CNAME')), version=utils.encode_to_ascii(environment.get('VersionLabel')), platform=utils.encode_to_ascii(environment.get('SolutionStackName')), dat_term=environment.get('DateUpdated')) should_restore = io.get_boolean_response(prompt_text, default=True) if not should_restore: io.echo(responses['restore.norestore']) time.sleep(1) should_exit_display = False return should_exit_display from ebcli.operations import restoreops # restore specified environment self.request_id = restoreops.restore(env_id) return should_exit_display # Exception should never get thrown else: raise Exception
def restore_environment_num(self, environment_number): """Take in user input as a string, convert it to a decimal, get the environment that the user input matches, and attempt to restore that environment. """ environment_number = int(environment_number) # raises InvalidOperation Exception environments = self.poller.all_environments e_len = len(environments) if environment_number > e_len or environment_number < 1: raise IndexError environment = environments[e_len - environment_number] env_id = environment.get(u'EnvironmentId') should_exit_display = True if env_id: try: self.flusher(term.get_terminal()) io.validate_action(prompts['restore.selectedenv'].replace('{env_id}', env_id) .replace('{app}', utils.encode_to_ascii(environment.get('ApplicationName'))) .replace('{desc}', utils.encode_to_ascii(environment.get('Description'))) .replace('{cname}', utils.encode_to_ascii(environment.get('CNAME'))) .replace('{version}', utils.encode_to_ascii(environment.get('VersionLabel'))) .replace('{platform}', utils.encode_to_ascii(environment.get('SolutionStackName'))) .replace('{dat_term}', environment.get('DateUpdated')), 'y') from ebcli.operations import restoreops # restore specified environment self.request_id = restoreops.restore(env_id) return should_exit_display except ValidationError: io.echo(responses['restore.norestore']) time.sleep(1) should_exit_display = False return should_exit_display # Exception should never get thrown else: raise Exception
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 handle_input(self): t = term.get_terminal() with t.cbreak(): # Get input val = t.inkey(timeout=.5) if val: self.idle_time = datetime.now() char = str(val).upper() LOG.debug('Got val: {0}, {1}, {2}.'.format( val, val.name, val.code)) # io.echo('Got val: {},, {}, {}.'.format(val, val.name, val.code)) # time.sleep(3) if char == 'Q': if self.help_table.visible: self.turn_on_table(self.last_table) else: return True # Exit command elif char == 'X': self.replace_instance_view() elif char == 'B': self.reboot_instance_view() elif char == '1': self.turn_on_table('split') elif char == '2': self.turn_on_table('health') elif char == '3': self.turn_on_table('requests') elif char == '4': self.turn_on_table('cpu') elif char == '5': self.turn_on_table('deployments') elif char == 'H': self.show_help() elif char == 'F': self.toggle_freeze() elif char == 'P': self.snapshot_file_view() elif char == 'Z': self.mono = not self.mono elif char == '>': self.move_sort_column_right() elif char == '<': self.move_sort_column_left() elif char == '-': self.sort_reversed = True elif char == '+': self.sort_reversed = False # Scrolling elif val.name == 'KEY_DOWN': # Down arrow self.scroll_down() elif val.name == 'KEY_UP': # Up arrow self.scroll_down(reverse=True) elif val.name == 'KEY_LEFT': # Left arrow self.scroll_over(reverse=True) elif val.name == 'KEY_RIGHT': # Right arrow self.scroll_over() elif val.name == 'KEY_END': # End for table in self.tables: table.scroll_to_end() elif val.name == 'KEY_HOME': # Home for table in self.tables: table.scroll_to_beginning() # If in help window (not main screen) these keys exit elif self.help_table.visible and val.code == 361: # ESC KEY self.turn_on_table(self.last_table)