def long_format(self, records): """Format records in long format. Args: records: Controlled records to format. Returns: str: Record data in long format. """ title = util.hline(self.title_fmt % {'model_name': records[0].name.capitalize(), 'storage_path': records[0].storage}, 'cyan') retval = [title] for record in records: rows = [['Attribute', 'Value', 'Command Flag', 'Description']] populated = record.populate() for key, val in sorted(populated.iteritems()): if key != self.model.key_attribute: rows.append(self._format_long_item(key, val)) table = Texttable(logger.LINE_WIDTH) table.set_cols_align(['r', 'c', 'l', 'l']) table.set_deco(Texttable.HEADER | Texttable.VLINES) table.add_rows(rows) retval.append(util.hline(populated[self.model.key_attribute], 'cyan')) retval.extend([table.draw(), '']) return retval
def long_format(self, records): """Format records in long format. Args: records: Controlled records to format. Returns: str: Record data in long format. """ title = util.hline( self.title_fmt % { 'model_name': records[0].name.capitalize(), 'storage_path': records[0].storage }, 'cyan') retval = [title] for record in records: rows = [['Attribute', 'Value', 'Command Flag', 'Description']] populated = record.populate() for key, val in sorted(populated.iteritems()): if key != self.model.key_attribute: rows.append(self._format_long_item(key, val)) table = Texttable(logger.LINE_WIDTH) table.set_cols_align(['r', 'c', 'l', 'l']) table.set_deco(Texttable.HEADER | Texttable.VLINES) table.add_rows(rows) retval.append( util.hline(populated[self.model.key_attribute], 'cyan')) retval.extend([table.draw(), '']) return retval
def exit_with_help(name): """Show a subcommands help page and exit.""" cmd_obj = cli.find_command(name) command = cmd_obj.command parts = [ "", util.hline("Help: " + command), cmd_obj.help_page, "", util.hline("Usage: " + command), cmd_obj.usage ] util.page_output('\n'.join(parts)) return EXIT_SUCCESS
def exit_with_help(name): """Show a subcommands help page and exit.""" cmd_obj = cli.find_command(name) command = cmd_obj.command parts = [ "", util.hline("Help: " + command), cmd_obj.help_page, "", util.hline("Usage: " + command), cmd_obj.usage] util.page_output('\n'.join(parts)) return EXIT_SUCCESS
def exit_with_fullhelp(): """Show a recursive help page for all commands and exit.""" help_output = '' for cmd_name in cli.get_all_commands(): name = cli.command_from_module_name(cmd_name) cmd_obj = cli.find_command(name.split()[1:]) command = cmd_obj.command parts = ["", util.hline("Help: " + command), cmd_obj.help_page, "", util.hline("Usage: " + command), cmd_obj.usage] help_output += '\n'.join(parts) util.page_output(help_output) return EXIT_SUCCESS
def exit_with_fullhelp(): """Show a recursive help page for all commands and exit.""" help_output = '' for cmd_name in cli.get_all_commands(): name = cli.command_from_module_name(cmd_name) cmd_obj = cli.find_command(name.split()[1:]) command = cmd_obj.command parts = [ "", util.hline("Help: " + command), cmd_obj.help_page, "", util.hline("Usage: " + command), cmd_obj.usage ] help_output += '\n'.join(parts) util.page_output(help_output) return EXIT_SUCCESS
def dashboard_format(self, records): """Format modeled records in dashboard format. Args: records: Modeled records to format. Returns: str: Record data in dashboard format. """ title = util.hline(self.title_fmt % {'model_name': records[0].name.capitalize(), 'storage_path': records[0].storage}, 'cyan') header_row = [col['header'] for col in self.dashboard_columns] rows = [header_row] for record in records: populated = record.populate() row = [] for col in self.dashboard_columns: if 'value' in col: try: cell = populated[col['value']] except KeyError: cell = 'N/A' elif 'yesno' in col: cell = 'Yes' if populated.get(col['yesno'], False) else 'No' elif 'function' in col: cell = col['function'](populated) else: raise InternalError("Invalid column definition: %s" % col) row.append(cell) rows.append(row) table = Texttable(logger.LINE_WIDTH) table.set_cols_align([col.get('align', 'c') for col in self.dashboard_columns]) table.add_rows(rows) return [title, table.draw(), '']
def _draw_table(self, targ, metric, rows): parts = [util.hline("%s Metrics on Target '%s'" % (metric, targ['name']), 'cyan')] table = Texttable(logger.LINE_WIDTH) table.set_cols_align(['r', 'l']) name_width = max([len(row[0]) for row in rows]) table.set_cols_width([name_width+1, logger.LINE_WIDTH-name_width-4]) table.set_deco(Texttable.HEADER | Texttable.VLINES) table.add_rows(rows) parts.extend([table.draw(), '']) return parts
def dashboard_format(self, records): """Format modeled records in dashboard format. Args: records: Modeled records to format. Returns: str: Record data in dashboard format. """ self.logger.debug("Dashboard format") title = util.hline( self.title_fmt % { 'model_name': records[0].name.capitalize(), 'storage_path': records[0].storage }, 'cyan') expr = Project.selected().experiment() subtitle = util.color_text("Selected experiment: ", 'cyan') + expr['name'] header_row = [col['header'] for col in self.dashboard_columns] rows = [header_row] for record in records: populated = record.populate() row = [] for col in self.dashboard_columns: if 'value' in col: try: cell = populated[col['value']] except KeyError: cell = 'N/A' elif 'yesno' in col: cell = 'Yes' if populated.get(col['yesno'], False) else 'No' elif 'function' in col: cell = col['function'](populated) else: raise InternalError("Invalid column definition: %s" % col) row.append(cell) rows.append(row) table = Texttable(logger.LINE_WIDTH) table.set_cols_align( [col.get('align', 'c') for col in self.dashboard_columns]) table.add_rows(rows) return [title, table.draw(), '', subtitle, '']