Merge d5f36a7679
into 72ed585c6f
This commit is contained in:
commit
d74d29da3d
|
@ -95,6 +95,7 @@ Usage
|
||||||
--share Generate and provide a URL to the speedtest.net share
|
--share Generate and provide a URL to the speedtest.net share
|
||||||
results image, not displayed with --csv
|
results image, not displayed with --csv
|
||||||
--simple Suppress verbose output, only show basic information
|
--simple Suppress verbose output, only show basic information
|
||||||
|
--no-human Do not print (values) as human readable
|
||||||
--csv Suppress verbose output, only show basic information
|
--csv Suppress verbose output, only show basic information
|
||||||
in CSV format. Speeds listed in bit/s and not affected
|
in CSV format. Speeds listed in bit/s and not affected
|
||||||
by --bytes
|
by --bytes
|
||||||
|
|
43
speedtest.py
43
speedtest.py
|
@ -1636,6 +1636,9 @@ def parse_args():
|
||||||
parser.add_argument('--simple', action='store_true', default=False,
|
parser.add_argument('--simple', action='store_true', default=False,
|
||||||
help='Suppress verbose output, only show basic '
|
help='Suppress verbose output, only show basic '
|
||||||
'information')
|
'information')
|
||||||
|
parser.add_argument('--no-human', dest='human', default=True,
|
||||||
|
action='store_const', const=False,
|
||||||
|
help='Do not print (values) as human readable')
|
||||||
parser.add_argument('--csv', action='store_true', default=False,
|
parser.add_argument('--csv', action='store_true', default=False,
|
||||||
help='Suppress verbose output, only show basic '
|
help='Suppress verbose output, only show basic '
|
||||||
'information in CSV format. Speeds listed in '
|
'information in CSV format. Speeds listed in '
|
||||||
|
@ -1724,6 +1727,18 @@ def printer(string, quiet=False, debug=False, error=False, **kwargs):
|
||||||
print_(out, **kwargs)
|
print_(out, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
def humanized(big_number):
|
||||||
|
# Thanks to "T" on page http://code.activestate.com/recipes/577081-humanized-representation-of-a-number-of-bytes/
|
||||||
|
# Convert big numbers to human readble shorter ones using Kilo, Mega, Giga etc.
|
||||||
|
# prefix_list=['','Kilo','Mega','Giga','Tera', 'Peta', 'Exa', 'Zeta', 'Yotta'] # Long versions
|
||||||
|
prefix_list=['','K','M','G','T', 'P', 'E', 'Z', 'Y'] # Short versions
|
||||||
|
prefix_index = 0
|
||||||
|
while (big_number >= 1000) and (prefix_index <= len(prefix_list)): # we are trying get below 1000
|
||||||
|
prefix_index += 1
|
||||||
|
big_number = big_number / 1024.0
|
||||||
|
return "%.2f %s"%(big_number, prefix_list[prefix_index])
|
||||||
|
|
||||||
|
|
||||||
def shell():
|
def shell():
|
||||||
"""Run the full speedtest.net test"""
|
"""Run the full speedtest.net test"""
|
||||||
|
|
||||||
|
@ -1836,14 +1851,18 @@ def shell():
|
||||||
printer('Hosted by %(sponsor)s (%(name)s) [%(d)0.2f km]: '
|
printer('Hosted by %(sponsor)s (%(name)s) [%(d)0.2f km]: '
|
||||||
'%(latency)s ms' % results.server, quiet)
|
'%(latency)s ms' % results.server, quiet)
|
||||||
|
|
||||||
|
if args.simple:
|
||||||
|
printer('Ping: %s ms' % results.ping)
|
||||||
|
|
||||||
if args.download:
|
if args.download:
|
||||||
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' %
|
if args.human:
|
||||||
((results.download / 1000.0 / 1000.0) / args.units[1],
|
resultstr_down = humanized(results.download / args.units[1])
|
||||||
args.units[0]),
|
else:
|
||||||
quiet)
|
resultstr_down = '%0.2f ' % (results.download / args.units[1])
|
||||||
|
printer('Download: %s%s/s' % (resultstr_down, args.units[0]))
|
||||||
else:
|
else:
|
||||||
printer('Skipping download test', quiet)
|
printer('Skipping download test', quiet)
|
||||||
|
|
||||||
|
@ -1851,10 +1870,11 @@ 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' %
|
if args.human:
|
||||||
((results.upload / 1000.0 / 1000.0) / args.units[1],
|
resultstr_up = humanized(results.upload / args.units[1])
|
||||||
args.units[0]),
|
else:
|
||||||
quiet)
|
resultstr_up = '%0.2f ' % (results.upload / args.units[1])
|
||||||
|
printer('Upload: %s%s/s' % (resultstr_up, args.units[0]))
|
||||||
else:
|
else:
|
||||||
printer('Skipping upload test', quiet)
|
printer('Skipping upload test', quiet)
|
||||||
|
|
||||||
|
@ -1863,13 +1883,6 @@ def shell():
|
||||||
if not args.simple and args.share:
|
if not args.simple and args.share:
|
||||||
results.share()
|
results.share()
|
||||||
|
|
||||||
if args.simple:
|
|
||||||
printer('Ping: %s ms\nDownload: %0.2f M%s/s\nUpload: %0.2f M%s/s' %
|
|
||||||
(results.ping,
|
|
||||||
(results.download / 1000.0 / 1000.0) / args.units[1],
|
|
||||||
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