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%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\' """ from time import sleep s = 0.5 for line in msg.split('\n'): print line sleep(s) s = s / 1.2 print terminal.bold() + \ "Let there be CAKE!".center(80) + \ terminal.reset()
def _do_default(self, line): print terminal.bold() + "Added Logs:" + terminal.unbold(), index = 1 all_log_files = self.loghdlr.get_log_files(all_list=True) for key in sorted(all_log_files.keys()): print "\n" + str(index) + " : " + key.ljust(20) + all_log_files[key], index += 1 if index == 1: print " None", print "\n" print "\n" + terminal.bold() + "Selected Logs:" + terminal.unbold(), index = 1 selected_log_files = self.loghdlr.get_log_files(all_list=False) for key in sorted(selected_log_files.keys()): print "\n" + " ".ljust(5) + key.ljust(20) + selected_log_files[key], index += 1 if index == 1: print " None", print "\n"
def _do_default(self, line): print terminal.bold() + "Added Logs:" + terminal.unbold(), index = 1 all_log_files = self.loghdlr.get_log_files(all_list=True) for key in sorted(all_log_files.keys()): print "\n" + str(index) + " : " + key.ljust( 20) + all_log_files[key], index += 1 if index == 1: print " None", print "\n" print "\n" + terminal.bold() + "Selected Logs:" + terminal.unbold(), index = 1 selected_log_files = self.loghdlr.get_log_files(all_list=False) for key in sorted(selected_log_files.keys()): print "\n" + " ".ljust(5) + key.ljust( 20) + selected_log_files[key], index += 1 if index == 1: print " None", print "\n"
def execute_help(self, line, indent=0): self._init() method = self._find_method(line) if method: try: try: method_name = method.__name__ except Exception: method_name = None if method_name == DEFAULT: # Print controller help CommandHelp.display(self, indent=indent) if self.modifiers: CommandHelp.print_text( "%sModifiers%s: %s" % (terminal.underline(), terminal.reset(), ", ".join( sorted(self.modifiers))), indent=indent) if CommandHelp.has_help(method): CommandHelp.display(method, indent=indent) indent += 2 for command in sorted(self.commands.keys()): CommandHelp.print_text( "- %s%s%s:" % (terminal.bold(), command, terminal.reset()), indent=indent - 1) self.execute_help([command], indent=indent) return elif isinstance(method, ShellException): # Method not implemented pass elif method_name is None: # Nothing to print yet method.execute_help(line, indent=indent) else: # Print help for a command CommandHelp.display(method, indent=indent) return except IOError as e: raise ShellException(str(e)) else: raise ShellException("Method was not set? %s" % (line))
def execute_help(self, line, indent=0): self._init() method = self._find_method(line) if method: try: try: method_name = method.__name__ except Exception: method_name = None if method_name == DEFAULT: # Print controller help CommandHelp.display(self, indent=indent) if self.modifiers: CommandHelp.print_text( "%sModifiers%s: %s" % (terminal.underline(), terminal.reset(), ", ".join( sorted(self.modifiers))), indent=indent) if CommandHelp.has_help(method): CommandHelp.display(method, indent=indent) indent += 2 for command in sorted(self.commands.keys()): CommandHelp.print_text( "- %s%s%s:" % (terminal.bold(), command, terminal.reset()), indent=indent - 1) self.execute_help([command], indent=indent) return elif isinstance(method, ShellException): # Method not implemented pass elif method_name is None: # Nothing to print yet method.execute_help(line, indent=indent) else: # Print help for a command CommandHelp.display(method, indent=indent) return except IOError as e: raise ShellException(str(e)) else: raise ShellException( "Method was not set? %s" % (line))
def _get_horizontal_header(self, title_every_nth=0): width = sum(self._render_column_widths) total_repeat_titles = 0 if title_every_nth: total_columns = len(self._render_column_display_names ) - 1 # Ignoring first columns of Row Header total_repeat_titles = (total_columns - 1) / title_every_nth width += total_repeat_titles * self._render_column_widths[ 0] # Width is same as first column width += len(self._column_padding) * \ (len(self._render_column_widths) + total_repeat_titles - 1) column_name_lines = map(lambda h: h.split(" "), self._render_column_display_names) max_deep = max(map(len, column_name_lines)) output = [terminal.bold()] output.append(self._get_title(self._title, width=width)) output.append(terminal.reset()) output = [''.join(output)] output.extend(self.gen_description(width, width - 10)) for r in range(max_deep): row = [] for i, c in enumerate(column_name_lines): if title_every_nth and ( i - 1) > 0 and (i - 1) % title_every_nth == 0: try: row.append(column_name_lines[0][r].rjust( self._render_column_widths[0])) except IndexError: row.append(".".rjust(self._render_column_widths[0])) row.append(self._column_padding) try: row.append(c[r].rjust(self._render_column_widths[i])) except IndexError: row.append(".".rjust(self._render_column_widths[i])) row.append(self._column_padding) output.append(row) output = "\n".join(map(lambda r: "".join(r), output)) return output
def precmd(self, line, max_commands_to_print_header=1, command_index_to_print_from=1): lines = None try: lines = self.clean_line(line) if not lines: # allow empty lines return "" except Exception as e: logger.error(e) return "" for line in lines: if line[0] in self.commands: return " ".join(line) if len(lines) > max_commands_to_print_header: if len(line) > 1 and any( cmd.startswith(line[0]) for cmd in MULTILEVEL_COMMANDS): index = command_index_to_print_from else: # If single level command then print from first index. For example: health, features, grep etc. index = 0 print "\n~~~ %s%s%s ~~~" % (terminal.bold(), ' '.join( line[index:]), terminal.reset()) sys.stdout.write(terminal.reset()) try: response = self.ctrl.execute(line) if response == "EXIT": return "exit" except Exception as e: logger.error(e) return "" # line was handled by execute
def _get_horizontal_header(self, title_every_nth=0): width = sum(self._render_column_widths) total_repeat_titles = 0 if title_every_nth: total_columns = len(self._render_column_display_names) - 1 # Ignoring first columns of Row Header total_repeat_titles = (total_columns-1)/title_every_nth width += total_repeat_titles * self._render_column_widths[0] # Width is same as first column width += len(self._column_padding) * \ (len(self._render_column_widths) + total_repeat_titles - 1) column_name_lines = map( lambda h: h.split(" "), self._render_column_display_names) max_deep = max(map(len, column_name_lines)) output = [terminal.bold()] output.append(self._get_title(self._title, width=width)) output.append(terminal.reset()) output = [''.join(output)] output.extend(self.gen_description(width, width - 10)) for r in range(max_deep): row = [] for i, c in enumerate(column_name_lines): if title_every_nth and (i-1) >0 and (i-1)%title_every_nth == 0: try: row.append(column_name_lines[0][r].rjust(self._render_column_widths[0])) except IndexError: row.append(".".rjust(self._render_column_widths[0])) row.append(self._column_padding) try: row.append(c[r].rjust(self._render_column_widths[i])) except IndexError: row.append(".".rjust(self._render_column_widths[i])) row.append(self._column_padding) output.append(row) output = "\n".join(map(lambda r: "".join(r), output)) return output
def __init__(self, admin_version, seeds, user=None, password=None, use_services_alumni=False, use_services_alt=False, log_path="", log_analyser=False, collectinfo=False, ssl_context=None, only_connect_seed=False, execute_only_mode=False, timeout=5): # indicates shell created successfully and connected to cluster/collectinfo/logfile self.connected = True self.execute_only_mode = execute_only_mode if log_analyser: self.name = 'Aerospike Log Analyzer Shell' elif collectinfo: self.name = 'Aerospike Collectinfo Shell' else: self.name = 'Aerospike Interactive Shell' if not execute_only_mode: print terminal.bold() + self.name + ', version ' +\ admin_version + terminal.reset() + "\n" cmd.Cmd.__init__(self) try: if log_analyser: if not log_path: log_path = " " self.ctrl = LogRootController(admin_version, log_path) self.prompt = "Log-analyzer> " elif collectinfo: if not log_path: logger.error( "You have not specified any collectinfo path. Usage: asadm -c -f <collectinfopath>" ) self.do_exit('') exit(1) self.ctrl = CollectinfoRootController(admin_version, clinfo_path=log_path) self.prompt = "Collectinfo-analyzer> " if not execute_only_mode: self.intro = str(self.ctrl.loghdlr) else: if user is not None: if password == "prompt" or password is None: if sys.stdin.isatty(): password = getpass.getpass("Enter Password:"******"Not able to connect any cluster with " + str(seeds) + ".") self.connected = False return else: logger.critical( "Not able to connect any cluster with " + str(seeds) + ".") self.prompt = "Admin> " self.intro = "" if not execute_only_mode: self.intro += str(self.ctrl.cluster) + "\n" cluster_visibility_error_nodes = self.ctrl.cluster.get_visibility_error_nodes( ) if cluster_visibility_error_nodes: self.intro += terminal.fg_red( ) + "Cluster Visibility error (Please check services list): %s" % ( ", ".join(cluster_visibility_error_nodes) ) + terminal.fg_clear() + "\n" cluster_down_nodes = self.ctrl.cluster.get_down_nodes() if cluster_down_nodes: self.intro += terminal.fg_red( ) + "Extra nodes in alumni list: %s" % (", ".join( cluster_down_nodes)) + terminal.fg_clear() + "\n" if self.use_rawinput: self.prompt = "\001" + terminal.bold() + terminal.fg_red() + "\002" +\ self.prompt + "\001" +\ terminal.unbold() + terminal.fg_clear() + "\002" except Exception as e: self.do_exit('') logger.critical(str(e)) if not execute_only_mode: try: readline.read_history_file(ADMINHIST) except Exception: readline.write_history_file(ADMINHIST) self.commands = set() regex = re.compile("^do_(.*)$") commands = map(lambda v: regex.match(v).groups()[0], filter(regex.search, dir(self))) for command in commands: if command != 'help': self.commands.add(command)
def _str_vertical(self, title_every_nth=0): output = [] title_width = [] total_titles = 1 if title_every_nth: total_columns = len(self._render_column_widths) - 1 extra_header_columns = (total_columns - 1) / title_every_nth total_titles = extra_header_columns + 1 # 1 for default if total_titles > 1: slice_title_width = self._render_column_widths[0] + 1 n_columns = 0 for i, c_width in enumerate(self._render_column_widths[1:]): slice_title_width += c_width n_columns += 1 if (i + 1) % title_every_nth == 0: temp_width = slice_title_width temp_width += len(self._column_padding) * (n_columns) if i != len(self._render_column_widths) - 2: temp_width += len(self._column_padding) title_width.append(temp_width) slice_title_width = self._render_column_widths[0] + 1 n_columns = 0 if n_columns: temp_width = slice_title_width temp_width += len(self._column_padding) * (n_columns) title_width.append(temp_width) else: temp_width = sum(self._render_column_widths) + 1 # 1 for ":" temp_width += len(self._column_padding) * \ (len(self._render_column_widths) - 1) title_width.append(temp_width) output = [terminal.bold()] for t_width in title_width: output.append(self._get_title(self._title, width=t_width)) output.append(terminal.reset()) output = [''.join(output)] output.extend( self.gen_description(sum(title_width), sum(title_width) - 10)) for i, column_name in enumerate(self._render_column_names): row = [] row.append(terminal.style(terminal.bg_clear, terminal.fg_clear)) column_title = column_name if column_name == "NODE": row.append(terminal.bold()) row.append(column_title.ljust(self._render_column_widths[0])) row.append(":") row.append(self._column_padding) added_columns = 0 for j, (cell_format, cell) in enumerate( (raw_data[i] for raw_data in self._data), 1): if (title_every_nth and added_columns > 0 and added_columns % title_every_nth == 0): row.append( column_title.ljust(self._render_column_widths[0])) row.append(":") row.append(self._column_padding) cell = cell.ljust(self._render_column_widths[j]) row.append("%s%s" % (cell_format(), cell)) row.append(self._column_padding) added_columns += 1 if column_name == "NODE": row.append(terminal.reset()) output.append(''.join(row)) return '\n'.join(output) + '\n'
def _str_vertical(self, title_every_nth=0): output = [] title_width = [] total_titles = 1 if title_every_nth: total_columns = len(self._render_column_widths) - 1 extra_header_columns = (total_columns - 1) / title_every_nth total_titles = extra_header_columns + 1 # 1 for default if total_titles > 1: slice_title_width = self._render_column_widths[0] + 1 n_columns = 0 for i, c_width in enumerate(self._render_column_widths[1:]): slice_title_width += c_width n_columns += 1 if (i + 1) % title_every_nth == 0: temp_width = slice_title_width temp_width += len(self._column_padding) * (n_columns) if i != len(self._render_column_widths) - 2: temp_width += len(self._column_padding) title_width.append(temp_width) slice_title_width = self._render_column_widths[0] + 1 n_columns = 0 if n_columns: temp_width = slice_title_width temp_width += len(self._column_padding) * (n_columns) title_width.append(temp_width) else: temp_width = sum(self._render_column_widths) + 1 # 1 for ":" temp_width += len(self._column_padding) * \ (len(self._render_column_widths) - 1) title_width.append(temp_width) output = [terminal.bold()] for t_width in title_width: output.append(self._get_title(self._title, width=t_width)) output.append(terminal.reset()) output = [''.join(output)] output.extend( self.gen_description(sum(title_width), sum(title_width) - 10)) for i, column_name in enumerate(self._render_column_names): row = [] row.append(terminal.style( terminal.bg_clear, terminal.fg_clear)) column_title = column_name if column_name == "NODE": row.append(terminal.bold()) row.append(column_title.ljust(self._render_column_widths[0])) row.append(":") row.append(self._column_padding) added_columns = 0 for j, (cell_format, cell) in enumerate((raw_data[i] for raw_data in self._data), 1): if (title_every_nth and added_columns > 0 and added_columns % title_every_nth == 0): row.append( column_title.ljust(self._render_column_widths[0])) row.append(":") row.append(self._column_padding) cell = cell.ljust(self._render_column_widths[j]) row.append("%s%s" % (cell_format(), cell)) row.append(self._column_padding) added_columns += 1 if column_name == "NODE": row.append(terminal.reset()) output.append(''.join(row)) return '\n'.join(output) + '\n'