Skip to content

Commit

Permalink
Fix the vPoller csvhelper module
Browse files Browse the repository at this point in the history
  • Loading branch information
dnaeon committed Apr 29, 2014
1 parent 8178589 commit fb62ecb
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions src/vpoller/helpers/csvhelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __init__(self, msg, data):
"""
self.msg = msg
self.data = json.loads(data)
self.data = data

def run(self):
"""
Expand All @@ -62,23 +62,14 @@ def run(self):
if self.data['success'] != 0:
return json.dumps(self.data, indent=4)

data = self.data['result']
result = cStringIO.StringIO()

multi_entries = isinstance(data, (tuple, list))

if multi_entries:
headers = data[0].keys()
else:
headers = data.keys()
data = self.data['result']
result = cStringIO.StringIO()
headers = data[0].keys()

writer = csv.DictWriter(result, headers, restval='None', extrasaction='ignore', quotechar='"')
writer.writeheader()

if multi_entries:
for eachItem in data:
writer.writerow(eachItem)
else:
writer.writerow(data)
for item in data:
writer.writerow(item)

return result.getvalue()

0 comments on commit fb62ecb

Please sign in to comment.