Use the printer everywhere, leaving print_ to only be used within printer

This commit is contained in:
Matt Martz 2018-01-02 18:22:16 -06:00
parent 4737a69f10
commit 9848481d06
1 changed files with 14 additions and 14 deletions

View File

@ -1521,7 +1521,7 @@ def ctrl_c(shutdown_event):
""" """
def inner(signum, frame): def inner(signum, frame):
shutdown_event.set() shutdown_event.set()
print_('\nCancelling...') printer('\nCancelling...', error=True)
sys.exit(0) sys.exit(0)
return inner return inner
@ -1529,14 +1529,14 @@ def ctrl_c(shutdown_event):
def version(): def version():
"""Print the version""" """Print the version"""
print_(__version__) printer(__version__)
sys.exit(0) sys.exit(0)
def csv_header(delimiter=','): def csv_header(delimiter=','):
"""Print the CSV Headers""" """Print the CSV Headers"""
print_(SpeedtestResults.csv_header(delimiter=delimiter)) printer(SpeedtestResults.csv_header(delimiter=delimiter))
sys.exit(0) sys.exit(0)
@ -1641,7 +1641,7 @@ def validate_optional_args(args):
def printer(string, quiet=False, debug=False, error=False, **kwargs): def printer(string, quiet=False, debug=False, error=False, **kwargs):
"""Helper function to print a string only when not quiet""" """Helper function print a string with various features"""
if debug and not DEBUG: if debug and not DEBUG:
return return
@ -1729,7 +1729,7 @@ def shell():
line = ('%(id)5s) %(sponsor)s (%(name)s, %(country)s) ' line = ('%(id)5s) %(sponsor)s (%(name)s, %(country)s) '
'[%(d)0.2f km]' % server) '[%(d)0.2f km]' % server)
try: try:
print_(line) printer(line)
except IOError: except IOError:
e = get_exception() e = get_exception()
if e.errno != errno.EPIPE: if e.errno != errno.EPIPE:
@ -1795,18 +1795,18 @@ def shell():
printer('Results:\n%r' % results.dict(), debug=True) printer('Results:\n%r' % results.dict(), debug=True)
if args.simple: if args.simple:
print_('Ping: %s ms\nDownload: %0.2f M%s/s\nUpload: %0.2f M%s/s' % printer('Ping: %s ms\nDownload: %0.2f M%s/s\nUpload: %0.2f M%s/s' %
(results.ping, (results.ping,
(results.download / 1000.0 / 1000.0) / args.units[1], (results.download / 1000.0 / 1000.0) / args.units[1],
args.units[0], args.units[0],
(results.upload / 1000.0 / 1000.0) / args.units[1], (results.upload / 1000.0 / 1000.0) / args.units[1],
args.units[0])) args.units[0]))
elif args.csv: elif args.csv:
print_(results.csv(delimiter=args.csv_delimiter)) printer(results.csv(delimiter=args.csv_delimiter))
elif args.json: elif args.json:
if args.share: if args.share:
results.share() results.share()
print_(results.json()) printer(results.json())
if args.share and not machine_format: if args.share and not machine_format:
printer('Share results: %s' % results.share()) printer('Share results: %s' % results.share())
@ -1816,7 +1816,7 @@ def main():
try: try:
shell() shell()
except KeyboardInterrupt: except KeyboardInterrupt:
print_('\nCancelling...') printer('\nCancelling...', error=True)
except (SpeedtestException, SystemExit): except (SpeedtestException, SystemExit):
e = get_exception() e = get_exception()
# Ignore a successful exit, or argparse exit # Ignore a successful exit, or argparse exit