check every 30 minutes for a new ui version

-previously the check for a new ui version was only at startup, which
resulted in bugs persisting after they’d been fixed

-add option to skip requirements check

-try to load an existing ui if it can’t be obtained from github
This commit is contained in:
Jack 2016-07-06 01:27:25 -04:00
parent a79af11371
commit 8b1d75ea98
3 changed files with 43 additions and 18 deletions

View file

@ -4,5 +4,5 @@ log = logging.getLogger(__name__)
logging.getLogger(__name__).addHandler(logging.NullHandler())
log.setLevel(logging.ERROR)
__version__ = "0.3.3"
__version__ = "0.3.4"
version = tuple(__version__.split('.'))

View file

@ -430,7 +430,7 @@ class LBRYDaemon(jsonrpc.JSONRPC):
log.error(failure)
return jsonrpclib.Fault(self.FAILURE, "error")
def setup(self, branch=DEFAULT_UI_BRANCH, user_specified=False, branch_specified=False):
def setup(self, branch=DEFAULT_UI_BRANCH, user_specified=False, branch_specified=False, host_ui=True):
def _log_starting_vals():
log.info("Starting balance: " + str(self.session.wallet.wallet_balance))
return defer.succeed(None)
@ -473,8 +473,11 @@ class LBRYDaemon(jsonrpc.JSONRPC):
self.internet_connection_checker.start(3600)
self.version_checker.start(3600 * 12)
self.connection_problem_checker.start(1)
if host_ui:
self.lbry_ui_manager.update_checker.start(1800, now=False)
d = defer.Deferred()
if host_ui:
d.addCallback(lambda _: self.lbry_ui_manager.setup(branch=branch,
user_specified=user_specified,
branch_specified=branch_specified))
@ -563,8 +566,8 @@ class LBRYDaemon(jsonrpc.JSONRPC):
def _get_lbrynet_version():
try:
r = urlopen("https://raw.githubusercontent.com/lbryio/lbry/master/lbrynet/__init__.py").read().split('\n')
vs = next(i for i in r if 'version =' in i).split("=")[1].replace(" ", "")
vt = tuple(int(x) for x in vs[1:-1].split(','))
vs = next(i for i in r if '__version__ =' in i).split("=")[1].replace(" ", "")
vt = tuple(int(x) for x in vs[1:-1].split('.'))
vr = ".".join([str(x) for x in vt])
log.info("remote lbrynet " + str(vr) + " > local lbrynet " + str(lbrynet_version) + " = " + str(
vr > lbrynet_version))
@ -700,6 +703,8 @@ class LBRYDaemon(jsonrpc.JSONRPC):
self.version_checker.stop()
if self.connection_problem_checker.running:
self.connection_problem_checker.stop()
if self.lbry_ui_manager.update_checker.running:
self.lbry_ui_manager.update_checker.stop()
d = self._upload_log(log_type="close", exclude_previous=False if self.first_run else True)
d.addCallback(lambda _: self._stop_server())
@ -2248,12 +2253,17 @@ class LBRYDaemon(jsonrpc.JSONRPC):
'path': path to a ui folder
"""
if 'path' in p.keys():
d = self.lbry_ui_manager.setup(user_specified=p['path'])
elif 'branch' in p.keys():
d = self.lbry_ui_manager.setup(branch=p['branch'])
if 'check_requirements' in p:
check_require = p['check_requirements']
else:
d = self.lbry_ui_manager.setup()
check_require = True
if 'path' in p:
d = self.lbry_ui_manager.setup(user_specified=p['path'], check_requirements=check_require)
elif 'branch' in p:
d = self.lbry_ui_manager.setup(branch=p['branch'], check_requirements=check_require)
else:
d = self.lbry_ui_manager.setup(check_requirements=check_require)
d.addCallback(lambda r: self._render_response(r, OK_CODE))
return d

View file

@ -8,6 +8,7 @@ from urllib2 import urlopen
from StringIO import StringIO
from twisted.web import static
from twisted.internet import defer
from twisted.internet.task import LoopingCall
from lbrynet.conf import DEFAULT_UI_BRANCH, LOG_FILE_NAME
from lbrynet import __version__ as lbrynet_version
from lbryum.version import LBRYUM_VERSION as lbryum_version
@ -52,9 +53,12 @@ class LBRYUIManager(object):
self.config = os.path.join(self.ui_root, "active.json")
self.update_requires = os.path.join(self.update_dir, "requirements.txt")
self.requirements = {}
self.check_requirements = True
self.ui_dir = self.active_dir
self.git_version = None
self.root = root
self.branch = None
self.update_checker = LoopingCall(self.setup)
if not os.path.isfile(os.path.join(self.config)):
self.loaded_git_version = None
@ -73,7 +77,10 @@ class LBRYUIManager(object):
self.loaded_branch = None
self.loaded_requirements = None
def setup(self, branch=DEFAULT_UI_BRANCH, user_specified=None, branch_specified=False):
def setup(self, branch=DEFAULT_UI_BRANCH, user_specified=None, branch_specified=False, check_requirements=None):
if check_requirements is not None:
self.check_requirements = check_requirements
if self.branch is not None:
self.branch = branch
if user_specified:
if os.path.isdir(user_specified):
@ -84,7 +91,7 @@ class LBRYUIManager(object):
d.addCallback(lambda _: self._load_ui())
return d
else:
log.info("User specified UI directory doesn't exist, using " + branch)
log.info("User specified UI directory doesn't exist, using " + self.branch)
elif self.loaded_branch == "user-specified" and not branch_specified:
log.info("Loading user provided UI")
d = self._load_ui()
@ -113,8 +120,12 @@ class LBRYUIManager(object):
log.info("UI updates available, checking if installation meets requirements")
return defer.succeed(False)
def _use_existing():
log.info("Failed to check for new ui version, trying to use cached ui")
return defer.succeed(True)
d = _get_git_info()
d.addCallback(_set_git)
d.addCallbacks(_set_git, lambda _: _use_existing)
return d
def migrate_ui(self, source=None):
@ -127,6 +138,10 @@ class LBRYUIManager(object):
source_dir = source
delete_source = False
def _skip_requirements():
log.info("Skipping ui requirement check")
return defer.succeed(True)
def _check_requirements():
if not os.path.isfile(requires_file):
log.info("No requirements.txt file, rejecting request to migrate this UI")
@ -197,7 +212,7 @@ class LBRYUIManager(object):
self.loaded_requirements = loaded_ui['requirements']
return defer.succeed(True)
d = _check_requirements()
d = _check_requirements() if self.check_requirements else _skip_requirements()
d.addCallback(lambda r: _do_migrate() if r else _disp_failure())
return d