cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bhais...@apache.org
Subject [2/3] cloudstack-cloudmonkey git commit: cloudmonkey: print csv rows based on what's available
Date Tue, 19 Jan 2016 14:27:36 GMT
cloudmonkey: print csv rows based on what's available

This fails if the row item has any additional key than the first row with error:
Error on parsing and printing dict contains fields not in fieldnames

The fix is to start with an empty dictionary fill it based on known keys and
then ask csv to print that row

Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/commit/5c7f906f
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/tree/5c7f906f
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/diff/5c7f906f

Branch: refs/heads/master
Commit: 5c7f906fae1656e1dc072097ee9061b0f3bbefd4
Parents: b463216
Author: Rohit Yadav <rohit.yadav@shapeblue.com>
Authored: Tue Jan 19 15:24:01 2016 +0100
Committer: Rohit Yadav <rohit.yadav@shapeblue.com>
Committed: Tue Jan 19 15:25:35 2016 +0100

----------------------------------------------------------------------
 cloudmonkey/cloudmonkey.py | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/blob/5c7f906f/cloudmonkey/cloudmonkey.py
----------------------------------------------------------------------
diff --git a/cloudmonkey/cloudmonkey.py b/cloudmonkey/cloudmonkey.py
index e7d3c53..fc43167 100644
--- a/cloudmonkey/cloudmonkey.py
+++ b/cloudmonkey/cloudmonkey.py
@@ -282,13 +282,16 @@ class CloudMonkeyShell(cmd.Cmd, object):
                     writer = csv.DictWriter(sys.stdout, keys)
                     print ','.join(keys)
                     for item in result:
+                        row = {}
                         for k in keys:
                             if k not in item:
-                                item[k] = None
+                                row[k] = None
                             else:
                                 if type(item[k]) is unicode:
-                                    item[k] = item[k].encode('utf8')
-                        writer.writerow(item)
+                                    row[k] = item[k].encode('utf8')
+                                else:
+                                    row[k] = item[k]
+                        writer.writerow(row)
             elif isinstance(result, dict):
                 keys = result.keys()
                 writer = csv.DictWriter(sys.stdout, keys)


Mime
View raw message