def main(): api = LBRYAPIClient.config() try: status = api.daemon_status() assert status.get('code', False) == "started" except Exception: try: settings.update({'use_auth_http': not settings.use_auth_http}) api = LBRYAPIClient.config() status = api.daemon_status() assert status.get('code', False) == "started" except Exception: print "lbrynet-daemon isn't running" sys.exit(1) parser = argparse.ArgumentParser() parser.add_argument('method', nargs=1) parser.add_argument('params', nargs=argparse.REMAINDER, default=None) args = parser.parse_args() meth = args.method[0] params = {} if len(args.params) > 1: params = get_params_from_kwargs(args.params) elif len(args.params) == 1: try: params = json.loads(args.params[0]) except ValueError: params = get_params_from_kwargs(args.params) msg = help_msg for f in api.help(): msg += f + "\n" if meth in ['--help', '-h', 'help']: print msg sys.exit(1) if meth in api.help(): try: if params: result = LBRYAPIClient.config(service=meth, params=params) else: result = LBRYAPIClient.config(service=meth, params=params) print json.dumps(result, sort_keys=True) except RPCError 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:" % meth print api.help({'function': meth}) print "Here's the traceback for the error you encountered:" print err.msg else: print "Unknown function" print msg
def update_settings_from_args(args): to_pass = {} if args.ui: to_pass['local_ui_path'] = args.ui if args.branch: to_pass['ui_branch'] = args.branch to_pass['use_auth_http'] = args.useauth to_pass['wallet'] = args.wallet settings.update(to_pass)