def stop(): conf.initialize_settings() log_support.configure_console() try: LBRYAPIClient.get_client().call('stop') except Exception: log.exception('Failed to stop deamon') else: log.info("Shutting down lbrynet-daemon from command line")
def main(): if len(sys.argv[1:]): method, args = sys.argv[1], sys.argv[2:] else: print_help() return if method in ['help', '--help', '-h']: if len(args) == 1: print_help_for_command(args[0]) else: print_help() return if method not in Daemon.callable_methods: print_error("\"%s\" is not a valid command." % method) return fn = Daemon.callable_methods[method] if hasattr(fn, "_flags"): flag_names = fn._flags else: flag_names = {} parsed = docopt(fn.__doc__, args) kwargs = set_flag_vals(flag_names, parsed) colorama.init() conf.initialize_settings() api = LBRYAPIClient.get_client() try: status = api.status() except URLError as err: if isinstance(err, HTTPError) and err.code == UNAUTHORIZED: print_error( "Daemon requires authentication, but none was provided.", suggest_help=False) else: print_error( "Could not connect to daemon. Are you sure it's running?", suggest_help=False) return 1 if status['startup_status']['code'] != "started": 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 try: result = api.call(method, **kwargs) if isinstance(result, basestring): # printing the undumped string is prettier print result else: print utils.json_dumps_pretty(result) except (RPCError, KeyError, JSONRPCException, HTTPError) as err: error_data = None if isinstance(err, HTTPError): error_body = err.read() try: error_data = json.loads(error_body) except ValueError: print( "There was an error, and the response was not valid JSON.\n" + "Raw JSONRPC response:\n" + error_body) return 1 print_error(error_data['error']['message'] + "\n", suggest_help=False) else: print_error("Something went wrong\n", suggest_help=False) print_help_for_command(method) if 'data' in error_data['error'] and 'traceback' in error_data[ 'error']['data']: print "Here's the traceback for the error you encountered:" print "\n".join(error_data['error']['data']['traceback']) return 1
def main(): parser = argparse.ArgumentParser(add_help=False) _, arguments = parser.parse_known_args() conf.initialize_settings() api = LBRYAPIClient.get_client() try: status = api.status() except URLError as err: if isinstance(err, HTTPError) and err.code == UNAUTHORIZED: print_error("Daemon requires authentication, but none was provided.", suggest_help=False) else: print_error("Could not connect to daemon. Are you sure it's running?", suggest_help=False) return 1 if status['startup_status']['code'] != "started": 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['blocks_behind'] > 0 ): message += '. Blocks left: ' + str(status['blocks_behind']) print " Status: " + message return 1 if len(arguments) < 1: print_help(api) return 1 method = arguments[0] try: params = parse_params(arguments[1:]) except InvalidParameters as e: print_error(e.message) return 1 # TODO: check if port is bound. Error if its not if method in ['--help', '-h', 'help']: if len(params) == 0: print_help(api) elif 'command' not in params: print_error( 'To get help on a specific command, use `{} help command=COMMAND_NAME`'.format( os.path.basename(sys.argv[0])) ) else: print api.call('help', params).strip() elif method not in api.commands(): print_error("'" + method + "' is not a valid command.") else: try: result = api.call(method, params) if isinstance(result, basestring): # printing the undumped string is prettier print result else: print json.dumps(result, sort_keys=True, indent=2, separators=(',', ': ')) except (RPCError, KeyError, JSONRPCException) as err: # TODO: The api should return proper error codes # and messages so that they can be passed along to the user # instead of this generic message. # https://app.asana.com/0/158602294500137/200173944358192 print "Something went wrong, here's the usage for %s:" % method print api.call('help', {'command': method}) if hasattr(err, 'msg'): print "Here's the traceback for the error you encountered:" print err.msg return 1
def main(): colorama.init() parser = argparse.ArgumentParser(add_help=False) _, arguments = parser.parse_known_args() conf.initialize_settings() api = LBRYAPIClient.get_client() try: status = api.status() except URLError as err: if isinstance(err, HTTPError) and err.code == UNAUTHORIZED: print_error("Daemon requires authentication, but none was provided.", suggest_help=False) else: print_error("Could not connect to daemon. Are you sure it's running?", suggest_help=False) return 1 if status['startup_status']['code'] != "started": 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 if len(arguments) < 1: print_help(api) return 1 method = arguments[0] try: params = parse_params(arguments[1:]) except InvalidParameters as e: print_error(e.message) return 1 # TODO: check if port is bound. Error if its not if method in ['--help', '-h', 'help']: if len(params) == 0: print_help(api) elif 'command' not in params: print_error( 'To get help on a specific command, use `{} help command=COMMAND_NAME`'.format( os.path.basename(sys.argv[0])) ) else: print_help_for_command(api, params['command']) elif method not in api.commands(): print_error("'" + method + "' is not a valid command.") else: try: result = api.call(method, params) if isinstance(result, basestring): # printing the undumped string is prettier print result else: print utils.json_dumps_pretty(result) except (RPCError, KeyError, JSONRPCException, HTTPError) as err: error_data = None if isinstance(err, HTTPError): error_body = err.read() try: error_data = json.loads(error_body) except ValueError: print ( "There was an error, and the response was not valid JSON.\n" + "Raw JSONRPC response:\n" + error_body ) return 1 print_error(error_data['error']['message'] + "\n", suggest_help=False) else: print_error("Something went wrong\n", suggest_help=False) print_help_for_command(api, method) if 'data' in error_data['error'] and 'traceback' in error_data['error']['data']: print "Here's the traceback for the error you encountered:" print "\n".join(error_data['error']['data']['traceback']) return 1
def __init__(self): self.started_daemon = False self.daemon = LBRYAPIClient.get_client()