def list(self, args=None): table = prettytable.PrettyTable([ bcolors.BOLD + 'ID' + bcolors.ENDC, bcolors.BOLD + 'Status' + bcolors.ENDC, bcolors.BOLD + 'ExternalIP' + bcolors.ENDC, bcolors.BOLD + 'InternalIP' + bcolors.ENDC, bcolors.BOLD + 'OS' + bcolors.ENDC, bcolors.BOLD + 'Arch' + bcolors.ENDC, bcolors.BOLD + 'ComputerName' + bcolors.ENDC, bcolors.BOLD + 'Username' + bcolors.ENDC, bcolors.BOLD + 'PID' + bcolors.ENDC ]) table.border = False table.align = 'l' table.add_row([ '--', '------', '----------', '----------', '--', '----', '------------', '--------', '----' ]) for i in config.AGENTS: status = time.time() - config.TIME[i] table.add_row([ bcolors.OKBLUE + str(config.AGENTS[i][0]) + bcolors.ENDC, status, config.AGENTS[i][1], config.AGENTS[i][3], config.AGENTS[i][2].split('|')[0], config.AGENTS[i][4], config.AGENTS[i][5], config.AGENTS[i][6] + '\\' + config.AGENTS[i][7], config.AGENTS[i][8] ]) print table
def help(self,args=None): table = prettytable.PrettyTable([bcolors.BOLD + 'Command' + bcolors.ENDC,bcolors.BOLD + 'Description' + bcolors.ENDC]) table.border = False table.align = 'l' table.add_row(['-'*7,'-'*11]) for i in self.HELPCOMMANDS: table.add_row([bcolors.OKBLUE + i[0] + bcolors.ENDC,i[1]]) print table
def build_table(column_list, all_rows, line_length, args_dict): """ Builds (pretty)table and prints it to console. """ cl_length = len(column_list) - 1 result_table = prettytable.PrettyTable(column_list) if 'hline' not in args_dict: result_table.hrules = prettytable.ALL all_rows_as_list = [] field_length = (line_length - 10) / cl_length for row in all_rows: single_row = list(row) # row is a tuple and contains db query results. if not 'link' in args_dict: if len(single_row[cl_length]) > 50: appended_string = "..." else: appended_string = "" single_row[ cl_length] = single_row[cl_length][0:50] + appended_string for index in range(1, cl_length + 1): if not single_row[index]: single_row[index] = "" dedented_item = textwrap.dedent(single_row[index]).strip() single_row[index] = textwrap.fill(dedented_item, width=field_length) #add modified row to table, add original row to return-list result_table.add_row(single_row) all_rows_as_list.append(list(row)) return all_rows_as_list, result_table