forked from LBRYCommunity/lbry-sdk
check UI version from command line
-check UI version, if out of date get a fresh copy. overridden by —ui flag, which is used to specify a ui directory
This commit is contained in:
parent
4355b799cb
commit
2540b9969f
1 changed files with 72 additions and 29 deletions
|
@ -1,19 +1,22 @@
|
||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
import tempfile
|
import subprocess
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
|
import webbrowser
|
||||||
|
import sys
|
||||||
|
|
||||||
from StringIO import StringIO
|
from StringIO import StringIO
|
||||||
from zipfile import ZipFile
|
from zipfile import ZipFile
|
||||||
from urllib import urlopen
|
from urllib import urlopen
|
||||||
|
from datetime import datetime
|
||||||
|
from appdirs import user_data_dir
|
||||||
from twisted.web import server, static
|
from twisted.web import server, static
|
||||||
from twisted.internet import reactor, defer
|
from twisted.internet import reactor, defer
|
||||||
from jsonrpc.proxy import JSONRPCProxy
|
from jsonrpc.proxy import JSONRPCProxy
|
||||||
|
|
||||||
from lbrynet.lbrynet_daemon.LBRYDaemon import LBRYDaemon, LBRYindex, LBRYFileRender
|
from lbrynet.lbrynet_daemon.LBRYDaemon import LBRYDaemon, LBRYindex, LBRYFileRender
|
||||||
from lbrynet.conf import API_CONNECTION_STRING, API_INTERFACE, API_ADDRESS, API_PORT, DEFAULT_WALLET
|
from lbrynet.conf import API_CONNECTION_STRING, API_INTERFACE, API_ADDRESS, API_PORT, DEFAULT_WALLET, UI_ADDRESS
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
@ -43,8 +46,8 @@ def start():
|
||||||
type=str,
|
type=str,
|
||||||
default="True")
|
default="True")
|
||||||
parser.add_argument("--ui",
|
parser.add_argument("--ui",
|
||||||
help="temp or path, default temp, path is the path of the dist folder",
|
help="path to custom UI folder",
|
||||||
default="temp")
|
default="")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
JSONRPCProxy.from_url(API_CONNECTION_STRING).is_running()
|
JSONRPCProxy.from_url(API_CONNECTION_STRING).is_running()
|
||||||
|
@ -56,33 +59,73 @@ def start():
|
||||||
log.info("Starting lbrynet-daemon from command line")
|
log.info("Starting lbrynet-daemon from command line")
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
download_ui = True
|
|
||||||
|
|
||||||
if args.ui != "temp" and os.path.isdir(args.ui):
|
def getui(ui_dir=None):
|
||||||
download_ui = False
|
if ui_dir:
|
||||||
ui_dir = args.ui
|
if os.path.isdir(ui_dir):
|
||||||
log.info("Using user specified UI directory: " + str(ui_dir))
|
log.info("Using user specified UI directory: " + str(ui_dir))
|
||||||
|
return defer.succeed(ui_dir)
|
||||||
|
else:
|
||||||
|
log.info("User specified UI directory doesn't exist: " + str(ui_dir))
|
||||||
|
|
||||||
if args.ui == "temp" or download_ui:
|
def download_ui(dest_dir):
|
||||||
log.info("Downloading current web ui to temp directory")
|
|
||||||
ui_dir = tempfile.mkdtemp()
|
|
||||||
url = urlopen("https://rawgit.com/lbryio/lbry-web-ui/master/dist.zip")
|
url = urlopen("https://rawgit.com/lbryio/lbry-web-ui/master/dist.zip")
|
||||||
z = ZipFile(StringIO(url.read()))
|
z = ZipFile(StringIO(url.read()))
|
||||||
z.extractall(ui_dir)
|
z.extractall(dest_dir)
|
||||||
|
return defer.succeed(dest_dir)
|
||||||
|
|
||||||
daemon = LBRYDaemon()
|
data_dir = user_data_dir("LBRY")
|
||||||
daemon.setup(args.wallet, args.update)
|
version_dir = os.path.join(data_dir, "ui_version_history")
|
||||||
|
|
||||||
|
git_version = subprocess.check_output(
|
||||||
|
"git ls-remote https://github.com/lbryio/lbry-web-ui.git | grep HEAD | cut -f 1", shell=True)
|
||||||
|
|
||||||
|
if not os.path.isdir(data_dir):
|
||||||
|
os.mkdir(data_dir)
|
||||||
|
|
||||||
|
if not os.path.isdir(os.path.join(data_dir, "ui_version_history")):
|
||||||
|
os.mkdir(version_dir)
|
||||||
|
|
||||||
|
if not os.path.isfile(os.path.join(version_dir, git_version)):
|
||||||
|
try:
|
||||||
|
f = open(os.path.join(version_dir, git_version), "w")
|
||||||
|
version_message = "[" + str(datetime.now()) + "] Updating UI --> " + git_version
|
||||||
|
f.write(version_message)
|
||||||
|
f.close()
|
||||||
|
log.info(version_message)
|
||||||
|
except:
|
||||||
|
log.info("You should have been notified to install xcode command line tools, once it's installed you can start LBRY")
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
if os.path.isdir(os.path.join(data_dir, "lbry-web-ui")):
|
||||||
|
shutil.rmtree(os.path.join(data_dir, "lbry-web-ui"))
|
||||||
|
else:
|
||||||
|
version_message = "[" + str(datetime.now()) + "] UI version " + git_version + " up to date"
|
||||||
|
log.info(version_message)
|
||||||
|
|
||||||
|
if os.path.isdir(os.path.join(data_dir, "lbry-web-ui")):
|
||||||
|
return defer.succeed(os.path.join(data_dir, "lbry-web-ui"))
|
||||||
|
else:
|
||||||
|
return download_ui((os.path.join(data_dir, "lbry-web-ui")))
|
||||||
|
|
||||||
|
def setupserver(ui_dir):
|
||||||
root = LBRYindex(ui_dir)
|
root = LBRYindex(ui_dir)
|
||||||
root.putChild("css", static.File(os.path.join(ui_dir, "css")))
|
root.putChild("css", static.File(os.path.join(ui_dir, "css")))
|
||||||
root.putChild("font", static.File(os.path.join(ui_dir, "font")))
|
root.putChild("font", static.File(os.path.join(ui_dir, "font")))
|
||||||
root.putChild("img", static.File(os.path.join(ui_dir, "img")))
|
root.putChild("img", static.File(os.path.join(ui_dir, "img")))
|
||||||
root.putChild("js", static.File(os.path.join(ui_dir, "js")))
|
root.putChild("js", static.File(os.path.join(ui_dir, "js")))
|
||||||
root.putChild(API_ADDRESS, daemon)
|
|
||||||
root.putChild("view", LBRYFileRender())
|
root.putChild("view", LBRYFileRender())
|
||||||
|
return defer.succeed(root)
|
||||||
|
|
||||||
|
def setupapi(root, wallet):
|
||||||
|
daemon = LBRYDaemon()
|
||||||
|
root.putChild(API_ADDRESS, daemon)
|
||||||
reactor.listenTCP(API_PORT, server.Site(root), interface=API_INTERFACE)
|
reactor.listenTCP(API_PORT, server.Site(root), interface=API_INTERFACE)
|
||||||
reactor.run()
|
return daemon.setup(wallet, "False")
|
||||||
|
|
||||||
if download_ui:
|
d = getui(args.ui)
|
||||||
shutil.rmtree(ui_dir)
|
d.addCallback(setupserver)
|
||||||
|
d.addCallback(lambda r: setupapi(r, args.wallet))
|
||||||
|
d.addCallback(lambda _: webbrowser.open(UI_ADDRESS))
|
||||||
|
|
||||||
|
reactor.run()
|
Loading…
Reference in a new issue