summaryrefslogtreecommitdiffstats
path: root/testapi/testapi-client/testapiclient/utils/command.py
diff options
context:
space:
mode:
authorSerenaFeng <feng.xiaowei@zte.com.cn>2018-03-12 21:05:51 +0800
committerSerenaFeng <feng.xiaowei@zte.com.cn>2018-03-13 10:08:32 +0800
commit12b7a2b54f4e3c36d49dec2b2620826aa7029a3e (patch)
tree000db4ce860a939214c218f9961fceb2380905c7 /testapi/testapi-client/testapiclient/utils/command.py
parentc22ede1f489a6b8df123c657a6a0001103eb7ba4 (diff)
format output
JIRA: RELENG-348 Change-Id: I8f6edae6ed70542f5dde45d81601c35d32af96d9 Signed-off-by: SerenaFeng <feng.xiaowei@zte.com.cn>
Diffstat (limited to 'testapi/testapi-client/testapiclient/utils/command.py')
-rw-r--r--testapi/testapi-client/testapiclient/utils/command.py44
1 files changed, 30 insertions, 14 deletions
diff --git a/testapi/testapi-client/testapiclient/utils/command.py b/testapi/testapi-client/testapiclient/utils/command.py
index f9c75a7..c99a3f3 100644
--- a/testapi/testapi-client/testapiclient/utils/command.py
+++ b/testapi/testapi-client/testapiclient/utils/command.py
@@ -1,9 +1,27 @@
+import abc
+import logging
+
from cliff import command
+from cliff import lister
+from cliff import show
+import six
+from testapiclient import utils
from testapiclient.utils import url_parse
+class CommandMeta(abc.ABCMeta):
+
+ def __new__(mcs, name, bases, cls_dict):
+ if 'log' not in cls_dict:
+ cls_dict['log'] = logging.getLogger(
+ cls_dict['__module__'] + '.' + name)
+ return super(CommandMeta, mcs).__new__(mcs, name, bases, cls_dict)
+
+
+@six.add_metaclass(CommandMeta)
class Command(command.Command):
+
def get_parser(self, prog_name):
parser = super(Command, self).get_parser(prog_name)
parser.add_argument('-u',
@@ -12,17 +30,14 @@ class Command(command.Command):
parser.add_argument('-p',
type=str,
help='Password for authentication')
-
return parser
- def show(self, request, response):
- print ' '.join([request,
- 'success' if response.status_code < 300
- else 'failed: {}'.format(response.reason)])
-
+ def run(self, parsed_args):
+ self.log.debug('run(%s)', parsed_args)
+ return super(Command, self).run(parsed_args)
-class Lister(command.Command):
+class Lister(Command, lister.Lister):
@staticmethod
def filter_by_name(url, parsed_args):
def query_url():
@@ -30,12 +45,13 @@ class Lister(command.Command):
return query_url() if parsed_args.name else url
- def show(self, response):
- print response.json() if response.status_code < 300 \
- else 'Get failed: {}'.format(response.reason)
+ @staticmethod
+ def format_output(columns, data):
+ return (columns,
+ (utils.get_item_properties(s, columns) for s in data))
-class ShowOne(command.Command):
- def show(self, response):
- print response.json() if response.status_code < 300 \
- else 'Get failed: {}'.format(response.reason)
+class ShowOne(Command, show.ShowOne):
+ @staticmethod
+ def format_output(body):
+ return zip(*sorted(six.iteritems(body)))