Skip to content

Commit f3974aa

Browse files
committed
utils: Wrap CSV in quotes
Signed-off-by: Stephen Finucane <stephen@that.guru> Closes: #46
1 parent 8aeec23 commit f3974aa

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

git_pw/utils.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
"""
44

55
from __future__ import print_function
6+
67
import codecs
8+
import csv
79
import os
810
import subprocess
911
import sys
@@ -12,6 +14,11 @@
1214
from tabulate import tabulate
1315

1416

17+
if sys.version_info < (3, 0):
18+
from io import BytesIO # noqa
19+
else:
20+
from io import StringIO # noqa
21+
1522
if sys.version_info < (3, 0):
1623
_text = unicode # noqa
1724
else:
@@ -63,12 +70,12 @@ def _tabulate(output, headers, fmt):
6370
elif fmt == 'simple':
6471
return tabulate(output, headers, tablefmt='simple')
6572
elif fmt == 'csv':
66-
result = []
67-
result.append(','.join(headers))
73+
result = StringIO()
74+
writer = csv.writer(result, quoting=csv.QUOTE_ALL)
75+
writer.writerow(headers)
6876
for item in output:
69-
result.append(
70-
','.join(_text(x if x is not None else '') for x in item))
71-
return '\n'.join(result)
77+
writer.writerow(_text(x if x is not None else '') for x in item)
78+
return result.getvalue()
7279

7380
print('pw.format must be one of: table, simple, csv')
7481
sys.exit(1)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
upgrade:
3+
- |
4+
CSV-formatted output is now quoted by default.

0 commit comments

Comments
 (0)