update lbrynet-cli

This commit is contained in:
hackrush 2018-07-24 12:36:42 -04:00 committed by Jack Robison
parent 3dc5a9de7b
commit 094d9c6497
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2

View file

@ -7,7 +7,7 @@ from collections import OrderedDict
from lbrynet import conf from lbrynet import conf
from lbrynet.core import utils from lbrynet.core import utils
from lbrynet.daemon.auth.client import JSONRPCException, LBRYAPIClient, AuthAPIClient from lbrynet.daemon.auth.client import JSONRPCException, LBRYAPIClient, AuthAPIClient
from lbrynet.daemon.Daemon import LOADING_WALLET_CODE, Daemon from lbrynet.daemon.Daemon import Daemon
from lbrynet.core.system_info import get_platform from lbrynet.core.system_info import get_platform
from jsonrpc.common import RPCError from jsonrpc.common import RPCError
from requests.exceptions import ConnectionError from requests.exceptions import ConnectionError
@ -21,17 +21,13 @@ def remove_brackets(key):
return key return key
def set_flag_vals(flag_names, parsed_args): def set_kwargs(parsed_args):
kwargs = OrderedDict() kwargs = OrderedDict()
for key, arg in parsed_args.iteritems(): for key, arg in parsed_args.iteritems():
if arg is None: if arg is None:
continue continue
elif key.startswith("--"): elif key.startswith("--") and remove_brackets(key[2:]) not in kwargs:
if remove_brackets(key[2:]) not in kwargs: k = remove_brackets(key[2:])
k = remove_brackets(key[2:])
elif key in flag_names:
if remove_brackets(flag_names[key]) not in kwargs:
k = remove_brackets(flag_names[key])
elif remove_brackets(key) not in kwargs: elif remove_brackets(key) not in kwargs:
k = remove_brackets(key) k = remove_brackets(key)
kwargs[k] = guess_type(arg, k) kwargs[k] = guess_type(arg, k)
@ -79,26 +75,22 @@ def main():
method = new_method method = new_method
fn = Daemon.callable_methods[method] fn = Daemon.callable_methods[method]
if hasattr(fn, "_flags"):
flag_names = fn._flags
else:
flag_names = {}
parsed = docopt(fn.__doc__, args) parsed = docopt(fn.__doc__, args)
kwargs = set_flag_vals(flag_names, parsed) kwargs = set_kwargs(parsed)
colorama.init() colorama.init()
conf.initialize_settings() conf.initialize_settings()
try: try:
api = LBRYAPIClient.get_client() api = LBRYAPIClient.get_client()
status = api.status() api.status()
except (URLError, ConnectionError) as err: except (URLError, ConnectionError) as err:
if isinstance(err, HTTPError) and err.code == UNAUTHORIZED: if isinstance(err, HTTPError) and err.code == UNAUTHORIZED:
api = AuthAPIClient.config() api = AuthAPIClient.config()
# this can happen if the daemon is using auth with the --http-auth flag # this can happen if the daemon is using auth with the --http-auth flag
# when the config setting is to not use it # when the config setting is to not use it
try: try:
status = api.status() api.status()
except: except:
print_error("Daemon requires authentication, but none was provided.", print_error("Daemon requires authentication, but none was provided.",
suggest_help=False) suggest_help=False)
@ -108,20 +100,6 @@ def main():
suggest_help=False) suggest_help=False)
return 1 return 1
status_code = status['startup_status']['code']
if status_code != "started" and method not in Daemon.allowed_during_startup:
print "Daemon is in the process of starting. Please try again in a bit."
message = status['startup_status']['message']
if message:
if (
status['startup_status']['code'] == LOADING_WALLET_CODE
and status['blockchain_status']['blocks_behind'] > 0
):
message += '. Blocks left: ' + str(status['blockchain_status']['blocks_behind'])
print " Status: " + message
return 1
# TODO: check if port is bound. Error if its not # TODO: check if port is bound. Error if its not
try: try: