From 32c0d6daa4742911c999aff47a18e085f68769af Mon Sep 17 00:00:00 2001 From: rexlee8776 Date: Mon, 20 Nov 2017 03:28:31 +0000 Subject: pretty cli format: runner/scenario/testcase list JIRA: YARDSTICK-855 1. using prettytable to reformat cli below: yardstick runner list yardstick scenario list yardstick testcase list 2. remove redundant function print_hbar 3. fix pep8 problems, the framework using do_list dynamicly, so disable unused-argument check for now. Change-Id: I79e1226e21fca4624bf4436414917bd07ecabca0 Signed-off-by: rexlee8776 --- yardstick/benchmark/core/__init__.py | 12 +++++------- yardstick/benchmark/core/runner.py | 18 +++++++++--------- yardstick/benchmark/core/scenario.py | 16 ++++++++-------- yardstick/cmd/__init__.py | 16 ---------------- yardstick/cmd/commands/testcase.py | 17 +++++++---------- 5 files changed, 29 insertions(+), 50 deletions(-) (limited to 'yardstick') diff --git a/yardstick/benchmark/core/__init__.py b/yardstick/benchmark/core/__init__.py index 70036ea1e..3e3aa99a1 100644 --- a/yardstick/benchmark/core/__init__.py +++ b/yardstick/benchmark/core/__init__.py @@ -6,10 +6,15 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +""" +Yardstick benchmark core. +""" + from __future__ import print_function class Param(object): + """This class converts a parameter dictionary to an object.""" def __init__(self, kwargs): # list @@ -31,10 +36,3 @@ class Param(object): # list self.type = kwargs.get('type') - - -def print_hbar(barlen): - """print to stdout a horizontal bar""" - print("+") - print("-" * barlen) - print("+") diff --git a/yardstick/benchmark/core/runner.py b/yardstick/benchmark/core/runner.py index 64acdaa99..b5e457c41 100644 --- a/yardstick/benchmark/core/runner.py +++ b/yardstick/benchmark/core/runner.py @@ -10,9 +10,10 @@ """ Handler for yardstick command 'runner' """ from __future__ import absolute_import -from __future__ import print_function + +import prettytable + from yardstick.benchmark.runners.base import Runner -from yardstick.benchmark.core import print_hbar class Runners(object): # pragma: no cover @@ -21,16 +22,15 @@ class Runners(object): # pragma: no cover Set of commands to discover and display runner types. """ - def list_all(self, args): + def list_all(self, *args): """List existing runner types""" types = Runner.get_types() - print_hbar(78) - print("| %-16s | %-60s" % ("Type", "Description")) - print_hbar(78) + runner_table = prettytable.PrettyTable(['Type', 'Description']) + runner_table.align = 'l' for rtype in types: - print("| %-16s | %-60s" % (rtype.__execution_type__, - rtype.__doc__.split("\n")[0])) - print_hbar(78) + runner_table.add_row([rtype.__execution_type__, + rtype.__doc__.split("\n")[0]]) + print(runner_table) def show(self, args): """Show details of a specific runner type""" diff --git a/yardstick/benchmark/core/scenario.py b/yardstick/benchmark/core/scenario.py index 28eb65230..3366172a5 100644 --- a/yardstick/benchmark/core/scenario.py +++ b/yardstick/benchmark/core/scenario.py @@ -10,8 +10,9 @@ """ Handler for yardstick command 'scenario' """ from __future__ import absolute_import +import prettytable + from yardstick.benchmark.scenarios.base import Scenario -from yardstick.benchmark.core import print_hbar class Scenarios(object): # pragma: no cover @@ -20,16 +21,15 @@ class Scenarios(object): # pragma: no cover Set of commands to discover and display scenario types. """ - def list_all(self, args): + def list_all(self, *args): """List existing scenario types""" types = Scenario.get_types() - print_hbar(78) - print("| %-16s | %-60s" % ("Type", "Description")) - print_hbar(78) + scenario_table = prettytable.PrettyTable(['Type', 'Description']) + scenario_table.align = 'l' for scenario_class in types: - print("| %-16s | %-60s" % (scenario_class.get_scenario_type(), - scenario_class.get_description())) - print_hbar(78) + scenario_table.add_row([scenario_class.get_scenario_type(), + scenario_class.get_description()]) + print(scenario_table) def show(self, args): """Show details of a specific scenario type""" diff --git a/yardstick/cmd/__init__.py b/yardstick/cmd/__init__.py index 3756d9ebb..e69de29bb 100644 --- a/yardstick/cmd/__init__.py +++ b/yardstick/cmd/__init__.py @@ -1,16 +0,0 @@ -############################################################################## -# Copyright (c) 2015 Ericsson AB and others. -# -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -############################################################################## -from __future__ import print_function - - -def print_hbar(barlen): - """print to stdout a horizontal bar""" - print(("+"), end=' ') - print(("-" * barlen), end=' ') - print("+") diff --git a/yardstick/cmd/commands/testcase.py b/yardstick/cmd/commands/testcase.py index a151871b3..7bdcdf003 100644 --- a/yardstick/cmd/commands/testcase.py +++ b/yardstick/cmd/commands/testcase.py @@ -8,11 +8,11 @@ ############################################################################## """ Handler for yardstick command 'testcase' """ -from __future__ import print_function from __future__ import absolute_import +import prettytable + from yardstick.benchmark.core.testcase import Testcase -from yardstick.benchmark.core import print_hbar from yardstick.common.utils import cliargs from yardstick.cmd.commands import change_osloobj_to_paras from yardstick.cmd.commands import Commands @@ -24,7 +24,7 @@ class TestcaseCommands(Commands): Set of commands to discover and display test cases. """ - def do_list(self, args): + def do_list(self, *args): """List existing test cases""" testcase_list = self.client.get('/yardstick/testcases')['result'] self._format_print(testcase_list) @@ -37,11 +37,8 @@ class TestcaseCommands(Commands): def _format_print(self, testcase_list): """format output""" - - print_hbar(88) - print("| %-21s | %-60s" % ("Testcase Name", "Description")) - print_hbar(88) + case_table = prettytable.PrettyTable(['Testcase Name', 'Description']) + case_table.align = 'l' for testcase_record in testcase_list: - print("| %-16s | %-60s" % (testcase_record['Name'], - testcase_record['Description'])) - print_hbar(88) + case_table.add_row([testcase_record['Name'], testcase_record['Description']]) + print(case_table) -- cgit 1.2.3-korg