2016-03-14 17:30:22 +01:00
|
|
|
import argparse
|
|
|
|
import logging
|
2016-03-22 15:37:13 +01:00
|
|
|
import tempfile
|
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
|
|
|
|
from StringIO import StringIO
|
|
|
|
from zipfile import ZipFile
|
|
|
|
from urllib import urlopen
|
2016-03-14 17:30:22 +01:00
|
|
|
|
2016-03-22 05:03:17 +01:00
|
|
|
from twisted.web import server, static
|
2016-03-14 17:30:22 +01:00
|
|
|
from twisted.internet import reactor, defer
|
|
|
|
from jsonrpc.proxy import JSONRPCProxy
|
|
|
|
|
2016-03-22 05:03:17 +01:00
|
|
|
from lbrynet.lbrynet_daemon.LBRYDaemon import LBRYDaemon, LBRYindex, LBRYDaemonWeb, LBRYFileRender
|
2016-03-14 17:30:22 +01:00
|
|
|
from lbrynet.conf import API_CONNECTION_STRING, API_INTERFACE, API_ADDRESS, API_PORT, DEFAULT_WALLET
|
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
|
|
|
|
|
|
|
|
def stop():
|
|
|
|
def _disp_shutdown():
|
|
|
|
log.info("Shutting down lbrynet-daemon from command line")
|
|
|
|
|
|
|
|
def _disp_not_running():
|
|
|
|
log.info("Attempt to shut down lbrynet-daemon from command line when daemon isn't running")
|
|
|
|
|
|
|
|
d = defer.Deferred(None)
|
|
|
|
d.addCallback(lambda _: JSONRPCProxy.from_url(API_CONNECTION_STRING).stop())
|
|
|
|
d.addCallbacks(lambda _: _disp_shutdown(), lambda _: _disp_not_running())
|
|
|
|
d.callback(None)
|
|
|
|
|
|
|
|
|
|
|
|
def start():
|
|
|
|
parser = argparse.ArgumentParser(description="Launch lbrynet-daemon")
|
|
|
|
parser.add_argument("--wallet",
|
|
|
|
help="lbrycrd or lbryum, default lbryum",
|
|
|
|
type=str,
|
|
|
|
default=DEFAULT_WALLET)
|
|
|
|
parser.add_argument("--update",
|
|
|
|
help="True or false, default true",
|
|
|
|
type=str,
|
|
|
|
default="True")
|
2016-03-26 02:03:58 +01:00
|
|
|
parser.add_argument("--ui",
|
|
|
|
help="temp or path, default temp, path is the path of the dist folder",
|
|
|
|
default="temp")
|
2016-03-14 17:30:22 +01:00
|
|
|
|
|
|
|
log.info("Starting lbrynet-daemon from command line")
|
|
|
|
|
2016-03-26 02:03:58 +01:00
|
|
|
args = parser.parse_args()
|
|
|
|
download_ui = True
|
2016-03-22 15:37:13 +01:00
|
|
|
|
2016-03-26 02:03:58 +01:00
|
|
|
if args.ui != "temp" and os.path.isdir(args.ui):
|
|
|
|
download_ui = False
|
|
|
|
ui_dir = args.ui
|
2016-03-28 20:54:01 +02:00
|
|
|
log.info("Using user specified UI directory: " + str(ui_dir))
|
2016-03-26 02:03:58 +01:00
|
|
|
|
|
|
|
if args.ui == "temp" or download_ui:
|
2016-03-28 20:54:01 +02:00
|
|
|
log.info("Downloading current web ui to temp directory")
|
2016-03-26 02:03:58 +01:00
|
|
|
ui_dir = tempfile.mkdtemp()
|
|
|
|
url = urlopen("https://rawgit.com/lbryio/lbry-web-ui/master/dist.zip")
|
|
|
|
z = ZipFile(StringIO(url.read()))
|
|
|
|
z.extractall(ui_dir)
|
2016-03-22 15:37:13 +01:00
|
|
|
|
2016-03-14 17:30:22 +01:00
|
|
|
daemon = LBRYDaemon()
|
|
|
|
daemon.setup(args.wallet, args.update)
|
|
|
|
|
2016-03-26 02:03:58 +01:00
|
|
|
root = LBRYindex(ui_dir)
|
|
|
|
root.putChild("css", static.File(os.path.join(ui_dir, "css")))
|
|
|
|
root.putChild("font", static.File(os.path.join(ui_dir, "font")))
|
|
|
|
root.putChild("img", static.File(os.path.join(ui_dir, "img")))
|
|
|
|
root.putChild("js", static.File(os.path.join(ui_dir, "js")))
|
2016-03-14 17:30:22 +01:00
|
|
|
root.putChild(API_ADDRESS, daemon)
|
2016-03-22 05:03:17 +01:00
|
|
|
root.putChild("webapi", LBRYDaemonWeb())
|
|
|
|
root.putChild("view", LBRYFileRender())
|
|
|
|
|
2016-03-26 02:03:58 +01:00
|
|
|
reactor.listenTCP(API_PORT, server.Site(root), interface=API_INTERFACE)
|
2016-03-14 17:30:22 +01:00
|
|
|
reactor.run()
|
2016-03-26 02:03:58 +01:00
|
|
|
|
|
|
|
if download_ui:
|
|
|
|
shutil.rmtree(ui_dir)
|