Support output in bytes using the --bytes argument

This commit is contained in:
Matt Martz 2014-02-26 07:34:11 -06:00
parent f559d79ded
commit e6913368ef
1 changed files with 8 additions and 2 deletions

View File

@ -450,6 +450,10 @@ def speedtest():
parser.add_argument = parser.add_option parser.add_argument = parser.add_option
except AttributeError: except AttributeError:
pass pass
parser.add_argument('--bytes', dest='units', action='store_const',
const=('bytes', 1), default=('bits', 8),
help='Display values in bytes instead of bits. Does '
'not affect the image generated by --share')
parser.add_argument('--share', action='store_true', parser.add_argument('--share', action='store_true',
help='Generate and provide a URL to the speedtest.net ' help='Generate and provide a URL to the speedtest.net '
'share results image') 'share results image')
@ -584,7 +588,8 @@ def speedtest():
dlspeed = downloadSpeed(urls, args.simple) dlspeed = downloadSpeed(urls, args.simple)
if not args.simple: if not args.simple:
print_() print_()
print_('Download: %0.2f Mbit/s' % ((dlspeed / 1000 / 1000) * 8)) print_('Download: %0.2f M%s/s' %
((dlspeed / 1000 / 1000) * args.units[1], args.units[0]))
sizesizes = [int(.25 * 1000 * 1000), int(.5 * 1000 * 1000)] sizesizes = [int(.25 * 1000 * 1000), int(.5 * 1000 * 1000)]
sizes = [] sizes = []
@ -596,7 +601,8 @@ def speedtest():
ulspeed = uploadSpeed(best['url'], sizes, args.simple) ulspeed = uploadSpeed(best['url'], sizes, args.simple)
if not args.simple: if not args.simple:
print_() print_()
print_('Upload: %0.2f Mbit/s' % ((ulspeed / 1000 / 1000) * 8)) print_('Upload: %0.2f M%s/s' %
((ulspeed / 1000 / 1000) * args.units[1], args.units[0]))
if args.share and args.mini: if args.share and args.mini:
print_('Cannot generate a speedtest.net share results image while ' print_('Cannot generate a speedtest.net share results image while '