Load, Save and Show Speedtest.net configuration
This commit is contained in:
parent
b0e1e58a0b
commit
8962060b4d
@ -30,6 +30,7 @@ import signal
|
|||||||
import socket
|
import socket
|
||||||
import timeit
|
import timeit
|
||||||
import threading
|
import threading
|
||||||
|
from json import dump as jsonDump, load as jsonLoad
|
||||||
|
|
||||||
# Used for bound_interface
|
# Used for bound_interface
|
||||||
socket_socket = socket.socket
|
socket_socket = socket.socket
|
||||||
@ -496,6 +497,12 @@ def speedtest():
|
|||||||
parser.add_argument('--simple', action='store_true',
|
parser.add_argument('--simple', action='store_true',
|
||||||
help='Suppress verbose output, only show basic '
|
help='Suppress verbose output, only show basic '
|
||||||
'information')
|
'information')
|
||||||
|
parser.add_argument('--showconfig', action='store_true',
|
||||||
|
help='Display the client configuration')
|
||||||
|
parser.add_argument('--saveconfig', help='Specify a file to save the speedtest.net '
|
||||||
|
'configuration')
|
||||||
|
parser.add_argument('--loadconfig', help='Specify a file to load the speedtest.net '
|
||||||
|
'configuration')
|
||||||
parser.add_argument('--list', action='store_true',
|
parser.add_argument('--list', action='store_true',
|
||||||
help='Display a list of speedtest.net servers '
|
help='Display a list of speedtest.net servers '
|
||||||
'sorted by distance')
|
'sorted by distance')
|
||||||
@ -525,13 +532,42 @@ def speedtest():
|
|||||||
source = args.source
|
source = args.source
|
||||||
socket.socket = bound_socket
|
socket.socket = bound_socket
|
||||||
|
|
||||||
if not args.simple:
|
# Retrieve speedtest configuration
|
||||||
print_('Retrieving speedtest.net configuration...')
|
if args.loadconfig == None:
|
||||||
try:
|
if not args.simple:
|
||||||
config = getConfig()
|
print_('Retrieving speedtest.net configuration...')
|
||||||
except URLError:
|
try:
|
||||||
print_('Cannot retrieve speedtest configuration')
|
config = getConfig()
|
||||||
sys.exit(1)
|
except URLError:
|
||||||
|
print_('Cannot retrieve speedtest configuration')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
if args.saveconfig != None:
|
||||||
|
if not args.simple:
|
||||||
|
print_('Saving speedtest.net configuration to %s' % args.saveconfig)
|
||||||
|
try:
|
||||||
|
configfile = open(args.saveconfig, 'w')
|
||||||
|
except:
|
||||||
|
print_('Unable to open configuration file %s' % args.saveconfig)
|
||||||
|
sys.exit(1)
|
||||||
|
jsonDump(config, configfile)
|
||||||
|
configfile.close()
|
||||||
|
else:
|
||||||
|
if not args.simple:
|
||||||
|
print_('Loading speedtest.net configuration from %s' % args.loadconfig)
|
||||||
|
try:
|
||||||
|
confFile = open(args.loadconfig, 'r')
|
||||||
|
except:
|
||||||
|
print_('Unable to open configuration file %s' % args.loadconfig)
|
||||||
|
sys.exit(1)
|
||||||
|
config = jsonLoad(confFile)
|
||||||
|
confFile.close()
|
||||||
|
|
||||||
|
if args.showconfig:
|
||||||
|
print_('Speedtest.net configuration:')
|
||||||
|
for configitem in config:
|
||||||
|
print_(' %s: %s' % (configitem, config[configitem]))
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
if not args.simple:
|
if not args.simple:
|
||||||
print_('Retrieving speedtest.net server list...')
|
print_('Retrieving speedtest.net server list...')
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user