Repository: cloudstack-cloudmonkey Updated Branches: refs/heads/master fda310293 -> 4d656edb4
cloudmonkey: aggregate keys from response items to print table's header In case a response item lacks sufficient keys, cloudmonkey's tabular output would print multiple table headers. The fix finds superset of keys of the items and prints it before proceeding. For items which lack a key, empty values are printed Signed-off-by: Rohit Yadav <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/commit/4d656edb Tree: http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/tree/4d656edb Diff: http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/diff/4d656edb Branch: refs/heads/master Commit: 4d656edb456dd2515f595014b90e8c4cc8d9fa34 Parents: fda3102 Author: Rohit Yadav <[email protected]> Authored: Mon Jun 29 23:40:14 2015 +0200 Committer: Rohit Yadav <[email protected]> Committed: Mon Jun 29 23:40:14 2015 +0200 ---------------------------------------------------------------------- cloudmonkey/cloudmonkey.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/blob/4d656edb/cloudmonkey/cloudmonkey.py ---------------------------------------------------------------------- diff --git a/cloudmonkey/cloudmonkey.py b/cloudmonkey/cloudmonkey.py index 51cf2c2..cf7fe67 100644 --- a/cloudmonkey/cloudmonkey.py +++ b/cloudmonkey/cloudmonkey.py @@ -291,12 +291,19 @@ class CloudMonkeyShell(cmd.Cmd, object): if printer: self.monkeyprint(printer.get_string()) return PrettyTable(toprow) - toprow = None printer = None + toprow = [] + if not result: + return + toprow = set(reduce(lambda x, y: x + y, map(lambda x: x.keys(), + filter(lambda x: isinstance(x, dict), result)))) + printer = print_table(printer, toprow) for node in result: - if toprow != node.keys(): - toprow = node.keys() - printer = print_table(printer, toprow) + if not node: + continue + for key in toprow: + if key not in node: + node[key] = '' row = map(lambda x: node[x], toprow) if printer and row: printer.add_row(row)
