예제 #1
0
 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
예제 #2
0
파일: cli_view.py 프로젝트: HPCL/taucmdr
    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
예제 #3
0
 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
예제 #4
0
파일: help.py 프로젝트: zbeekman/taucmdr
 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
예제 #5
0
 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
예제 #6
0
 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
예제 #7
0
    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(), '']
예제 #8
0
 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
예제 #9
0
    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, '']