コード例 #1
0
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
コード例 #2
0
ファイル: DaemonCLI.py プロジェクト: lbryio/lbry
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
コード例 #3
0
ファイル: LBRYURIHandler.py プロジェクト: lbryio/lbry
 def __init__(self):
     self.started_daemon = False
     self.daemon = LBRYAPIClient.config()
コード例 #4
0
def launch_lbry_console():
    from twisted.internet import reactor

    parser = argparse.ArgumentParser(description="Launch a lbrynet console")
    parser.add_argument("--no_listen_peer",
                        help="Don't listen for incoming data connections.",
                        action="store_true")
    parser.add_argument("--peer_port",
                        help="The port on which the console will listen for incoming data connections.",
                        type=int, default=3333)
    parser.add_argument("--no_listen_dht",
                        help="Don't listen for incoming DHT connections.",
                        action="store_true")
    parser.add_argument("--dht_node_port",
                        help="The port on which the console will listen for DHT connections.",
                        type=int, default=4444)
    parser.add_argument("--fake_wallet",
                        help="Testing purposes only. Use a non-blockchain wallet.",
                        action="store_true")
    parser.add_argument("--no_dht_bootstrap",
                        help="Don't try to connect to the DHT",
                        action="store_true")
    parser.add_argument("--dht_bootstrap_host",
                        help="The hostname of a known DHT node, to be used to bootstrap into the DHT. "
                             "Must be used with --dht_bootstrap_port",
                        type=str, default='104.236.42.182')
    parser.add_argument("--dht_bootstrap_port",
                        help="The port of a known DHT node, to be used to bootstrap into the DHT. Must "
                             "be used with --dht_bootstrap_host",
                        type=int, default=4000)
    parser.add_argument("--disable_upnp",
                        help="Don't try to use UPnP to enable incoming connections through the firewall",
                        action="store_true")
    parser.add_argument("--data_dir",
                        help=("The full path to the directory in which lbrynet data and metadata will be stored. "
                              "Default: ~/.lbrynet on linux, ~/Library/Application Support/lbrynet on OS X"),
                        type=str)
    parser.add_argument("--lbrycrdd_path",
                        help="The path to lbrycrdd, which will be launched if it isn't running. If"
                             "this option is chosen, lbrycrdd will be used as the interface to the"
                             "blockchain. By default, a lightweight interface is used.")
    parser.add_argument("--lbrycrd_wallet_dir",
                        help="The directory in which lbrycrd data will stored. Used if lbrycrdd is "
                             "launched by this application.")
    parser.add_argument("--lbrycrd_wallet_conf",
                        help="The configuration file for the LBRYcrd wallet. Default: ~/.lbrycrd/lbrycrd.conf",
                        type=str)

    args = parser.parse_args()

    if args.no_dht_bootstrap:
        bootstrap_nodes = []
    else:
        bootstrap_nodes = [(args.dht_bootstrap_host, args.dht_bootstrap_port)]

    if args.no_listen_peer:
        peer_port = None
    else:
        peer_port = args.peer_port

    if args.no_listen_dht:
        dht_node_port = None
    else:
        dht_node_port = args.dht_node_port

    created_data_dir = False
    if not args.data_dir:
        if sys.platform == "darwin":
            data_dir = user_data_dir("LBRY")
        else:
            data_dir = os.path.join(os.path.expanduser("~"), ".lbrynet")
    else:
        data_dir = args.data_dir
    if not os.path.exists(data_dir):
        os.mkdir(data_dir)
        created_data_dir = True

    daemon = LBRYAPIClient.config()
    try:
        daemon.is_running()
        log.info("Attempt to start lbrynet-console while lbrynet-daemon is running")
        print "lbrynet-daemon is running, you must turn it off before using lbrynet-console"
        print "If you're running the app, quit before starting lbrynet-console"
        print "If you're running lbrynet-daemon in a terminal, run 'stop-lbrynet-daemon' to turn it off"

        webbrowser.open("http://localhost:5279")

    except:
        log_format = "(%(asctime)s)[%(filename)s:%(lineno)s] %(funcName)s(): %(message)s"
        formatter = logging.Formatter(log_format)

        logger = logging.getLogger()
        logger.setLevel(logging.DEBUG)
        file_handler = logging.FileHandler(os.path.join(data_dir, "console.log"))
        file_handler.setFormatter(formatter)
        file_handler.addFilter(logging.Filter("lbrynet"))
        logger.addHandler(file_handler)


        console = Console(peer_port, dht_node_port, bootstrap_nodes, fake_wallet=args.fake_wallet,
                                lbrycrd_conf=args.lbrycrd_wallet_conf, lbrycrd_dir=args.lbrycrd_wallet_dir,
                                use_upnp=not args.disable_upnp, data_dir=data_dir,
                                created_data_dir=created_data_dir, lbrycrdd_path=args.lbrycrdd_path)

        d = task.deferLater(reactor, 0, console.start)
        d.addErrback(lambda _: reactor.stop())
        reactor.addSystemEventTrigger('before', 'shutdown', console.shut_down)
        reactor.run()
コード例 #5
0
 def __init__(self):
     self.started_daemon = False
     self.daemon = LBRYAPIClient.config()