Support csv-delimiter for csv-header

This commit is contained in:
Matt Martz 2017-10-16 09:28:35 -05:00
parent 6603954e45
commit 20e5d12a5c
1 changed files with 11 additions and 7 deletions

View File

@ -36,7 +36,7 @@ except ImportError:
gzip = None
GZIP_BASE = object
__version__ = '1.0.6'
__version__ = '1.0.7'
class FakeShutdownEvent(object):
@ -1212,11 +1212,15 @@ def version():
sys.exit(0)
def csv_header():
def csv_header(delimiter=','):
"""Print the CSV Headers"""
print_('Server ID,Sponsor,Server Name,Timestamp,Distance,Ping,Download,'
'Upload')
row = ['Server ID', 'Sponsor', 'Server Name', 'Timestamp', 'Distance',
'Ping', 'Download', 'Upload']
out = StringIO()
writer = csv.writer(out, delimiter=delimiter, lineterminator='')
writer.writerow([to_utf8(v) for v in row])
print_(out.getvalue())
sys.exit(0)
@ -1349,12 +1353,12 @@ def shell():
raise SpeedtestCLIError('Cannot supply both --no-download and '
'--no-upload')
if args.csv_header:
csv_header()
if len(args.csv_delimiter) != 1:
raise SpeedtestCLIError('--csv-delimiter must be a single character')
if args.csv_header:
csv_header(args.csv_delimiter)
validate_optional_args(args)
socket.setdefaulttimeout(args.timeout)