Skip to content

Commit

Permalink
utils: Wrap CSV in quotes
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Finucane <stephen@that.guru>
Closes: #46
  • Loading branch information
stephenfin committed Sep 16, 2019
1 parent 8aeec23 commit f3974aa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
17 changes: 12 additions & 5 deletions git_pw/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"""

from __future__ import print_function

import codecs
import csv
import os
import subprocess
import sys
Expand All @@ -12,6 +14,11 @@
from tabulate import tabulate


if sys.version_info < (3, 0):
from io import BytesIO # noqa
else:
from io import StringIO # noqa

if sys.version_info < (3, 0):
_text = unicode # noqa
else:
Expand Down Expand Up @@ -63,12 +70,12 @@ def _tabulate(output, headers, fmt):
elif fmt == 'simple':
return tabulate(output, headers, tablefmt='simple')
elif fmt == 'csv':
result = []
result.append(','.join(headers))
result = StringIO()
writer = csv.writer(result, quoting=csv.QUOTE_ALL)
writer.writerow(headers)
for item in output:
result.append(
','.join(_text(x if x is not None else '') for x in item))
return '\n'.join(result)
writer.writerow(_text(x if x is not None else '') for x in item)
return result.getvalue()

print('pw.format must be one of: table, simple, csv')
sys.exit(1)
Expand Down
4 changes: 4 additions & 0 deletions releasenotes/notes/issue-46-50933643cd5c8db0.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
upgrade:
- |
CSV-formatted output is now quoted by default.

0 comments on commit f3974aa

Please sign in to comment.