From 3fe184f4ba1f55f29f9475dd0b776ab6bc33852c Mon Sep 17 00:00:00 2001 From: liusheng Date: Sat, 25 Feb 2017 16:23:50 +0800 Subject: [PATCH] Make the output of "event list" more pretty Change-Id: I122d7dc7517f640bc5c109c1293045936217c0c4 --- pankoclient/osc/v2/events.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/pankoclient/osc/v2/events.py b/pankoclient/osc/v2/events.py index 36a07cb..e0883c5 100644 --- a/pankoclient/osc/v2/events.py +++ b/pankoclient/osc/v2/events.py @@ -19,7 +19,6 @@ import copy import json from osc_lib.command import command -from osc_lib import utils class EventList(command.Lister): @@ -60,11 +59,22 @@ class EventList(command.Lister): events = ac.event.list( filters=filters, sorts=parsed_args.sort, limit=parsed_args.limit, marker=parsed_args.marker) - columns = ('event_type', 'generated', 'message_id', 'traits') - formatters = {'traits': lambda s: json.dumps(s, indent=4)} - return (columns, - (utils.get_item_properties( - s, columns, formatters=formatters) for s in events)) + columns = ('event_type', 'generated', 'message_id', 'traits:name', + 'traits:value', 'traits:type') + rows = [] + for event in events: + traits_type = [t['type'] for t in event.traits] + traits_name = [t['name'] for t in event.traits] + traits_value = [t['value'] for t in event.traits] + [getattr(event, item, '') for item in columns] + row = (getattr(event, 'event_type', ''), + getattr(event, 'generated', ''), + getattr(event, 'message_id', ''), + '\n'.join(traits_name), + '\n'.join(traits_value), + '\n'.join(traits_type),) + rows.append(row) + return columns, tuple(rows) class EventShow(command.ShowOne):