Merge d6feef88b8
into 9c2977acfc
This commit is contained in:
commit
b36c46f275
35
speedtest.py
35
speedtest.py
|
@ -1690,6 +1690,21 @@ def validate_optional_args(args):
|
||||||
'unavailable' % (info[0], arg))
|
'unavailable' % (info[0], arg))
|
||||||
|
|
||||||
|
|
||||||
|
def format_speed(speed_bytes_per_second, unit):
|
||||||
|
if unit[0] == 'byte':
|
||||||
|
base = 1024
|
||||||
|
else:
|
||||||
|
base = 1000
|
||||||
|
|
||||||
|
seq = ['', 'K', 'M', 'G']
|
||||||
|
i = 0
|
||||||
|
speed = speed_bytes_per_second / unit[1]
|
||||||
|
while not (1 < speed < base):
|
||||||
|
i += 1
|
||||||
|
speed /= base
|
||||||
|
return '%0.2f %s%s/s' % (speed, seq[i], unit[0])
|
||||||
|
|
||||||
|
|
||||||
def printer(string, quiet=False, debug=False, error=False, **kwargs):
|
def printer(string, quiet=False, debug=False, error=False, **kwargs):
|
||||||
"""Helper function print a string with various features"""
|
"""Helper function print a string with various features"""
|
||||||
|
|
||||||
|
@ -1827,10 +1842,10 @@ def shell():
|
||||||
printer('Testing download speed', quiet,
|
printer('Testing download speed', quiet,
|
||||||
end=('', '\n')[bool(debug)])
|
end=('', '\n')[bool(debug)])
|
||||||
speedtest.download(callback=callback)
|
speedtest.download(callback=callback)
|
||||||
printer('Download: %0.2f M%s/s' %
|
printer('Download: %s' %
|
||||||
((results.download / 1000.0 / 1000.0) / args.units[1],
|
format_speed(results.download, args.units),
|
||||||
args.units[0]),
|
|
||||||
quiet)
|
quiet)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
printer('Skipping download test', quiet)
|
printer('Skipping download test', quiet)
|
||||||
|
|
||||||
|
@ -1838,9 +1853,8 @@ def shell():
|
||||||
printer('Testing upload speed', quiet,
|
printer('Testing upload speed', quiet,
|
||||||
end=('', '\n')[bool(debug)])
|
end=('', '\n')[bool(debug)])
|
||||||
speedtest.upload(callback=callback, pre_allocate=args.pre_allocate)
|
speedtest.upload(callback=callback, pre_allocate=args.pre_allocate)
|
||||||
printer('Upload: %0.2f M%s/s' %
|
printer('Upload: %s' %
|
||||||
((results.upload / 1000.0 / 1000.0) / args.units[1],
|
format_speed(results.upload, args.units),
|
||||||
args.units[0]),
|
|
||||||
quiet)
|
quiet)
|
||||||
else:
|
else:
|
||||||
printer('Skipping upload test', quiet)
|
printer('Skipping upload test', quiet)
|
||||||
|
@ -1851,12 +1865,9 @@ def shell():
|
||||||
results.share()
|
results.share()
|
||||||
|
|
||||||
if args.simple:
|
if args.simple:
|
||||||
printer('Ping: %s ms\nDownload: %0.2f M%s/s\nUpload: %0.2f M%s/s' %
|
print_('Ping: %s ms\nDownload: %s\nUpload: %s' %
|
||||||
(results.ping,
|
(results.ping, format_speed(results.download, args.units),
|
||||||
(results.download / 1000.0 / 1000.0) / args.units[1],
|
format_speed(results.upload, args.units)))
|
||||||
args.units[0],
|
|
||||||
(results.upload / 1000.0 / 1000.0) / args.units[1],
|
|
||||||
args.units[0]))
|
|
||||||
elif args.csv:
|
elif args.csv:
|
||||||
printer(results.csv(delimiter=args.csv_delimiter))
|
printer(results.csv(delimiter=args.csv_delimiter))
|
||||||
elif args.json:
|
elif args.json:
|
||||||
|
|
Loading…
Reference in New Issue