def _str_vertical(self): output = [] title_width = sum(self._render_column_widths) + 1 # 1 for ":" title_width += len(self._column_padding) * (len(self._render_column_widths) - 1) output = [terminal.bold()] output.append(self._title.center(title_width, "~")) output.append(terminal.reset()) output = ["".join(output)] output.extend(self.genDescription(title_width, 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) for j, (cell_format, cell) in enumerate((raw_data[i] for raw_data in self._data), 1): cell = cell.ljust(self._render_column_widths[j]) row.append("%s%s" % (cell_format(), cell)) row.append(self._column_padding) if column_name == "NODE": row.append(terminal.reset()) output.append("".join(row)) return "\n".join(output) + "\n"
def asinfo(results, line_sep, cluster, **kwargs): like = set(kwargs['like']) for node_id, value in results.iteritems(): prefix = cluster.getPrefixes()[node_id] node = cluster.getNode(node_id)[0] print "%s%s (%s) returned%s:"%(terminal.bold() , prefix , node.ip , terminal.reset()) if isinstance(value, Exception): print "%s%s%s"%(terminal.fg_red() , value , terminal.reset()) print "\n" else: # most info commands return a semicolon delimited list of key=value. # Assuming this is the case here, later we may want to try to detect # the format. value = value.split(';') likes = CliView.compileLikes(like) value = filter(likes.search, value) if not line_sep: value = [";".join(value)] for line in sorted(value): print line print
def _getHorizontalHeader(self): width = sum(self._render_column_widths) width += len(self._column_padding) * (len(self._render_column_widths) - 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._title.center(width, "~")) output.append(terminal.reset()) output = ["".join(output)] output.extend(self.genDescription(width, width - 10)) for r in range(max_deep): row = [] for i, c in enumerate(column_name_lines): 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 asinfo(results, line_sep, cluster, **kwargs): like = set(kwargs['like']) for node_id, value in results.iteritems(): prefix = cluster.getPrefixes()[node_id] node = cluster.getNode(node_id)[0] print "%s%s (%s) returned%s:" % (terminal.bold(), prefix, node.ip, terminal.reset()) if isinstance(value, Exception): print "%s%s%s" % (terminal.fg_red(), value, terminal.reset()) print "\n" else: # most info commands return a semicolon delimited list of key=value. # Assuming this is the case here, later we may want to try to detect # the format. value = value.split(';') likes = CliView.compileLikes(like) value = filter(likes.search, value) if not line_sep: value = [";".join(value)] for line in sorted(value): print line print
def do_cake(self, line): msg = """ * * * * * * ( ) (*) (*) ) | | ( * (*) |~| |~| (*) | |S| |A| | * |~| |P| |D| |~| |A| |I| |M| |U| ,|E|a@@@@|K|@@@@@@@@@@@|I|@@@@a|T|. .,a@@@|R|@@@@@|E|@@@@@@@@@@@|N|@@@@@|I|@@@@a,. ,a@@@@@@|O|@@@@@@@@@@@@.@@@@@@@@@@@@@@|L|@@@@@@@a, a@@@@@@@@@@@@@@@@@@@@@\' . `@@@@@@@@@@@@@@@@@@@@@@@@a ;`@@@@@@@@@@@@@@@@@@\' . `@@@@@@@@@@@@@@@@@@@@@\'; ;@@@`@@@@@@@@@@@@@\' . `@@@@@@@@@@@@@@@@\'@@@; ;@@@;,.aaaaaaaaaa . aaaaa,,aaaaaaa,;@@@; ;;@;;;;@@@@@@@@;@ @.@ ;@@@;;;@@@@@@;;;;@@; ;;;;;;;@@@@;@@;;@ @@ . @@ ;;@;;;;@@;@@@;;;;;;; ;;;;;;;;@@;;;;;;; @@ . @@ ;;;;;;;;;;;@@;;;;@;; ;;;;;;;;;;;;;;;;;@@ . @@;;;;;;;;;;;;;;;;@@@; ,%%%;;;;;;;;@;;;;;;;; . ;;;;;;;;;;;;;;;;@@;;%%%, .%%%%%%;;;;;;;@@;;;;;;;; ,%%%, ;;;;;;;;;;;;;;;;;;;;%%%%%%, .%%%%%%%;;;;;;;@@;;;;;;;; ,%%%%%%%, ;;;;;;;;;;;;;;;;;;;;%%%%%%%, %%%%%%%%`;;;;;;;;;;;;;;;; %%%%%%%%%%% ;;;;;;;;;;;;;;;;;;;\'%%%%%%%% %%%%%%%%%%%%`;;;;;;;;;;;;,%%%%%%%%%%%%%,;;;;;;;;;;;;;;;\'%%%%%%%%%%%% `%%%%%%%%%%%%%%%%%,,,,,,,%%%%%%%%%%%%%%%,,,,,,,%%%%%%%%%%%%%%%%%%%%\' `%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\' `%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\' """ 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 dun(results, cluster, **kwargs): for node_id, command_result in results.iteritems(): prefix = cluster.getPrefixes()[node_id] node = cluster.getNode(node_id)[0] print "%s%s (%s) returned%s:" % (terminal.bold(), prefix, node.ip, terminal.reset()) if isinstance(command_result, Exception): print "%s%s%s" % (terminal.fg_red(), command_result, terminal.reset()) print "\n" else: command, result = command_result print "asinfo -v '%s'" % (command) print result
def executeHelp(self, line, indent=0): self._init() method = self._findMethod(line) if method: try: try: method_name = method.__name__ except: #method_name = method.__class__.__name__ method_name = None if method_name == DEFAULT: # Print controller help CommandHelp.display(self, indent=indent) if self.modifiers: CommandHelp.printText( "%sModifiers%s: %s"%(terminal.underline() , terminal.reset() , ", ".join( sorted(self.modifiers))) , indent=indent) if CommandHelp.hasHelp(method): CommandHelp.display(method, indent=indent) indent += 2 for command in sorted(self.commands.keys()): CommandHelp.printText("- %s%s%s:"%(terminal.bold() , command , terminal.reset()) , indent=indent-1) self.executeHelp([command], indent=indent) return elif isinstance(method, ShellException): # Method not implemented pass elif method_name is None: # Nothing to print yet method.executeHelp(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 executeHelp(self, line, indent=0): self._init() method = self._findMethod(line) if method: try: try: method_name = method.__name__ except: #method_name = method.__class__.__name__ method_name = None if method_name == DEFAULT: # Print controller help CommandHelp.display(self, indent=indent) if self.modifiers: CommandHelp.printText( "%sModifiers%s: %s" % (terminal.underline(), terminal.reset(), ", ".join( sorted(self.modifiers))), indent=indent) if CommandHelp.hasHelp(method): CommandHelp.display(method, indent=indent) indent += 2 for command in sorted(self.commands.keys()): CommandHelp.printText( "- %s%s%s:" % (terminal.bold(), command, terminal.reset()), indent=indent - 1) self.executeHelp([command], indent=indent) return elif isinstance(method, ShellException): # Method not implemented pass elif method_name is None: # Nothing to print yet method.executeHelp(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 dun(results, cluster, **kwargs): for node_id, command_result in results.iteritems(): prefix = cluster.getPrefixes()[node_id] node = cluster.getNode(node_id)[0] print "%s%s (%s) returned%s:"%(terminal.bold() , prefix , node.ip , terminal.reset()) if isinstance(command_result, Exception): print "%s%s%s"%(terminal.fg_red() , command_result , terminal.reset()) print "\n" else: command, result = command_result print "asinfo -v '%s'"%(command) print result
def precmd(self, line): lines = self.cleanLine(line) if not lines: # allow empty lines return "" for line in lines: if line[0] in self.commands: return " ".join(line) if len(lines) > 1: print "~~~ %s%s%s ~~~" % (terminal.bold(), " ".join(line[1:]), terminal.reset()) sys.stdout.write(terminal.reset()) try: response = self.ctrl.execute(line) if response == "EXIT": return "exit" except ShellException as e: print "%sERR: %s%s" % (terminal.fg_red(), e, terminal.fg_clear()) return "" # line was handled by execute