lbry-sdk/lbry/wallet/server/cli.py

44 lines
1.3 KiB
Python
Raw Normal View History

2018-12-12 18:54:38 +01:00
import logging
import traceback
import argparse
import importlib
from lbry.wallet.server.env import Env
from lbry.wallet.server.server import Server
2018-12-12 18:54:38 +01:00
def get_argument_parser():
parser = argparse.ArgumentParser(
2021-03-24 21:07:17 +01:00
prog="lbry-hub"
2018-12-12 18:54:38 +01:00
)
2019-09-13 16:39:05 +02:00
parser.add_argument("spvserver", type=str, help="Python class path to SPV server implementation.",
nargs="?", default="lbry.wallet.server.coin.LBC")
2018-12-12 18:54:38 +01:00
return parser
def get_coin_class(spvserver):
spvserver_path, coin_class_name = spvserver.rsplit('.', 1)
spvserver_module = importlib.import_module(spvserver_path)
return getattr(spvserver_module, coin_class_name)
def main():
parser = get_argument_parser()
args = parser.parse_args()
coin_class = get_coin_class(args.spvserver)
2021-04-28 22:46:24 +02:00
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)-4s %(name)s:%(lineno)d: %(message)s")
logging.info('lbry.server starting')
logging.getLogger('aiohttp').setLevel(logging.WARNING)
logging.getLogger('elasticsearch').setLevel(logging.WARNING)
2018-12-12 18:54:38 +01:00
try:
server = Server(Env(coin_class))
server.run()
except Exception:
traceback.print_exc()
logging.critical('lbry.server terminated abnormally')
2018-12-12 18:54:38 +01:00
else:
logging.info('lbry.server terminated normally')
2018-12-12 18:54:38 +01:00
if __name__ == "__main__":
main()