Exemple #1
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("Usage: " + command),
              cmd_obj.usage,
              "", util.hline("Help: " + command),
              cmd_obj.help_page]
     print '\n'.join(parts)
     return EXIT_SUCCESS
Exemple #2
0
 def dashboard_format(self, models):
     """Format modeled records in dashboard format.
     
     Args:
         models: Modeled records to format.
     
     Returns:
         str: Record data in dashboard format.
     """
     self.logger.debug("Dashboard format")
     title = util.hline("%s Configurations (%s)" %
                        (models[0].name.capitalize(), 
                         models[0].storage),
                        'cyan')
     header_row = [col['header'] for col in self.dashboard_columns]
     rows = [header_row]
     for model in models:
         populated = model.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)
             color_attrs = col.get('color_attrs', None)
             if color_attrs:
                 cell = termcolor.colored(cell, **color_attrs)
             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 _print_experiments(self, proj):
     parts = []
     experiments = proj.populate('experiments')
     if not experiments:
         label = util.color_text('%s: No experiments' % proj['name'], color='red', attrs=['bold'])
         msg = "%s.  Use `%s` to create a new experiment." % (label, select_cmd) 
         parts.append(msg)
     if experiments:
         title = util.hline("Experiments in project '%s'" % proj['name'], 'cyan')
         header_row = ['Experiment', 'Trials', 'Data Size']
         rows = [header_row]
         for expr in experiments:
             rows.append([expr.title(), len(expr['trials']), util.human_size(expr.data_size())])
         table = Texttable(logger.LINE_WIDTH)
         table.add_rows(rows)
         parts.extend([title, table.draw(), ''])
     try:
         expr = proj.experiment()
     except ExperimentSelectionError:
         pass
     else:
         current = util.color_text('Current experiment: ', 'cyan') + expr.title()
         parts.append(current)
     print '\n'.join(parts)