Merge pull request #64 from lbryio/check-for-new-ui
Check for new ui periodically
This commit is contained in:
commit
0254df63f9
5 changed files with 112 additions and 54 deletions
|
@ -4,5 +4,5 @@ log = logging.getLogger(__name__)
|
||||||
logging.getLogger(__name__).addHandler(logging.NullHandler())
|
logging.getLogger(__name__).addHandler(logging.NullHandler())
|
||||||
log.setLevel(logging.ERROR)
|
log.setLevel(logging.ERROR)
|
||||||
|
|
||||||
__version__ = "0.3.3"
|
__version__ = "0.3.4"
|
||||||
version = tuple(__version__.split('.'))
|
version = tuple(__version__.split('.'))
|
|
@ -247,11 +247,8 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
||||||
|
|
||||||
if self.session_settings['last_version'] != self.default_settings['last_version']:
|
if self.session_settings['last_version'] != self.default_settings['last_version']:
|
||||||
self.session_settings['last_version'] = self.default_settings['last_version']
|
self.session_settings['last_version'] = self.default_settings['last_version']
|
||||||
|
|
||||||
self.first_run_after_update = True
|
self.first_run_after_update = True
|
||||||
log.info("First run after update")
|
log.info("First run after update")
|
||||||
if lbrynet_version == '0.2.5':
|
|
||||||
self.session_settings['startup_scripts'].append({'script_name': 'migrateto025', 'run_once': True})
|
|
||||||
|
|
||||||
f = open(self.daemon_conf, "w")
|
f = open(self.daemon_conf, "w")
|
||||||
f.write(json.dumps(self.session_settings))
|
f.write(json.dumps(self.session_settings))
|
||||||
|
@ -430,7 +427,7 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
||||||
log.error(failure)
|
log.error(failure)
|
||||||
return jsonrpclib.Fault(self.FAILURE, "error")
|
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():
|
def _log_starting_vals():
|
||||||
log.info("Starting balance: " + str(self.session.wallet.wallet_balance))
|
log.info("Starting balance: " + str(self.session.wallet.wallet_balance))
|
||||||
return defer.succeed(None)
|
return defer.succeed(None)
|
||||||
|
@ -473,8 +470,11 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
||||||
self.internet_connection_checker.start(3600)
|
self.internet_connection_checker.start(3600)
|
||||||
self.version_checker.start(3600 * 12)
|
self.version_checker.start(3600 * 12)
|
||||||
self.connection_problem_checker.start(1)
|
self.connection_problem_checker.start(1)
|
||||||
|
if host_ui:
|
||||||
|
self.lbry_ui_manager.update_checker.start(1800, now=False)
|
||||||
|
|
||||||
d = defer.Deferred()
|
d = defer.Deferred()
|
||||||
|
if host_ui:
|
||||||
d.addCallback(lambda _: self.lbry_ui_manager.setup(branch=branch,
|
d.addCallback(lambda _: self.lbry_ui_manager.setup(branch=branch,
|
||||||
user_specified=user_specified,
|
user_specified=user_specified,
|
||||||
branch_specified=branch_specified))
|
branch_specified=branch_specified))
|
||||||
|
@ -482,7 +482,6 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
||||||
d.addCallback(lambda _: threads.deferToThread(self._setup_data_directory))
|
d.addCallback(lambda _: threads.deferToThread(self._setup_data_directory))
|
||||||
d.addCallback(lambda _: self._check_db_migration())
|
d.addCallback(lambda _: self._check_db_migration())
|
||||||
d.addCallback(lambda _: self._get_settings())
|
d.addCallback(lambda _: self._get_settings())
|
||||||
d.addCallback(lambda _: self._get_lbrycrdd_path())
|
|
||||||
d.addCallback(lambda _: self._get_session())
|
d.addCallback(lambda _: self._get_session())
|
||||||
d.addCallback(lambda _: add_lbry_file_to_sd_identifier(self.sd_identifier))
|
d.addCallback(lambda _: add_lbry_file_to_sd_identifier(self.sd_identifier))
|
||||||
d.addCallback(lambda _: self._setup_stream_identifier())
|
d.addCallback(lambda _: self._setup_stream_identifier())
|
||||||
|
@ -563,8 +562,8 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
||||||
def _get_lbrynet_version():
|
def _get_lbrynet_version():
|
||||||
try:
|
try:
|
||||||
r = urlopen("https://raw.githubusercontent.com/lbryio/lbry/master/lbrynet/__init__.py").read().split('\n')
|
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(" ", "")
|
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(','))
|
vt = tuple(int(x) for x in vs[1:-1].split('.'))
|
||||||
vr = ".".join([str(x) for x in vt])
|
vr = ".".join([str(x) for x in vt])
|
||||||
log.info("remote lbrynet " + str(vr) + " > local lbrynet " + str(lbrynet_version) + " = " + str(
|
log.info("remote lbrynet " + str(vr) + " > local lbrynet " + str(lbrynet_version) + " = " + str(
|
||||||
vr > lbrynet_version))
|
vr > lbrynet_version))
|
||||||
|
@ -700,6 +699,8 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
||||||
self.version_checker.stop()
|
self.version_checker.stop()
|
||||||
if self.connection_problem_checker.running:
|
if self.connection_problem_checker.running:
|
||||||
self.connection_problem_checker.stop()
|
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 = self._upload_log(log_type="close", exclude_previous=False if self.first_run else True)
|
||||||
d.addCallback(lambda _: self._stop_server())
|
d.addCallback(lambda _: self._stop_server())
|
||||||
|
@ -837,7 +838,6 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
||||||
d = self.settings.start()
|
d = self.settings.start()
|
||||||
d.addCallback(lambda _: self.settings.get_lbryid())
|
d.addCallback(lambda _: self.settings.get_lbryid())
|
||||||
d.addCallback(self._set_lbryid)
|
d.addCallback(self._set_lbryid)
|
||||||
d.addCallback(lambda _: self._get_lbrycrdd_path())
|
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def _set_lbryid(self, lbryid):
|
def _set_lbryid(self, lbryid):
|
||||||
|
@ -877,18 +877,13 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def get_wallet():
|
def get_wallet():
|
||||||
if self.wallet_type == "lbrycrd":
|
if self.wallet_type in ["lbrycrd", "lbryum"]: #force lbrycrd wallet no matter what while lbryum is down
|
||||||
log.info("Using lbrycrd wallet")
|
log.info("Using lbrycrd wallet")
|
||||||
lbrycrdd_path = None
|
|
||||||
if self.start_lbrycrdd is True:
|
|
||||||
lbrycrdd_path = self.lbrycrdd_path
|
|
||||||
if not lbrycrdd_path:
|
|
||||||
lbrycrdd_path = self.default_lbrycrdd_path
|
|
||||||
d = defer.succeed(LBRYcrdWallet(self.db_dir, wallet_dir=self.wallet_dir, wallet_conf=self.lbrycrd_conf,
|
d = defer.succeed(LBRYcrdWallet(self.db_dir, wallet_dir=self.wallet_dir, wallet_conf=self.lbrycrd_conf,
|
||||||
lbrycrdd_path=lbrycrdd_path))
|
lbrycrdd_path=self.lbrycrdd_path))
|
||||||
elif self.wallet_type == "lbryum":
|
# elif self.wallet_type == "lbryum":
|
||||||
log.info("Using lbryum wallet")
|
# log.info("Using lbryum wallet")
|
||||||
d = defer.succeed(LBRYumWallet(self.db_dir))
|
# d = defer.succeed(LBRYumWallet(self.db_dir))
|
||||||
elif self.wallet_type == "ptc":
|
elif self.wallet_type == "ptc":
|
||||||
log.info("Using PTC wallet")
|
log.info("Using PTC wallet")
|
||||||
d = defer.succeed(PTCWallet(self.db_dir))
|
d = defer.succeed(PTCWallet(self.db_dir))
|
||||||
|
@ -979,25 +974,6 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
||||||
else:
|
else:
|
||||||
self.startup_message = None
|
self.startup_message = None
|
||||||
|
|
||||||
def _get_lbrycrdd_path(self):
|
|
||||||
def get_lbrycrdd_path_conf_file():
|
|
||||||
lbrycrdd_path_conf_path = os.path.join(os.path.expanduser("~"), ".lbrycrddpath.conf")
|
|
||||||
if not os.path.exists(lbrycrdd_path_conf_path):
|
|
||||||
return ""
|
|
||||||
lbrycrdd_path_conf = open(lbrycrdd_path_conf_path)
|
|
||||||
lines = lbrycrdd_path_conf.readlines()
|
|
||||||
return lines
|
|
||||||
|
|
||||||
d = threads.deferToThread(get_lbrycrdd_path_conf_file)
|
|
||||||
|
|
||||||
def load_lbrycrdd_path(conf):
|
|
||||||
for line in conf:
|
|
||||||
if len(line.strip()) and line.strip()[0] != "#":
|
|
||||||
self.lbrycrdd_path = line.strip()
|
|
||||||
|
|
||||||
d.addCallback(load_lbrycrdd_path)
|
|
||||||
return d
|
|
||||||
|
|
||||||
def _setup_stream_identifier(self):
|
def _setup_stream_identifier(self):
|
||||||
file_saver_factory = LBRYFileSaverFactory(self.session.peer_finder, self.session.rate_limiter,
|
file_saver_factory = LBRYFileSaverFactory(self.session.peer_finder, self.session.rate_limiter,
|
||||||
self.session.blob_manager, self.stream_info_manager,
|
self.session.blob_manager, self.stream_info_manager,
|
||||||
|
@ -1482,7 +1458,9 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
||||||
'lbryum_version': lbryum_version,
|
'lbryum_version': lbryum_version,
|
||||||
'ui_version': self.ui_version,
|
'ui_version': self.ui_version,
|
||||||
'remote_lbrynet': self.git_lbrynet_version,
|
'remote_lbrynet': self.git_lbrynet_version,
|
||||||
'remote_lbryum': self.git_lbryum_version
|
'remote_lbryum': self.git_lbryum_version,
|
||||||
|
'lbrynet_update_available': lbrynet_version < self.git_lbrynet_version,
|
||||||
|
'lbryum_update_available': lbryum_version < self.git_lbryum_version
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("[" + str(datetime.now()) + "] Get version info: " + json.dumps(msg))
|
log.info("[" + str(datetime.now()) + "] Get version info: " + json.dumps(msg))
|
||||||
|
@ -2248,12 +2226,17 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
||||||
'path': path to a ui folder
|
'path': path to a ui folder
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if 'path' in p.keys():
|
if 'check_requirements' in p:
|
||||||
d = self.lbry_ui_manager.setup(user_specified=p['path'])
|
check_require = p['check_requirements']
|
||||||
elif 'branch' in p.keys():
|
|
||||||
d = self.lbry_ui_manager.setup(branch=p['branch'])
|
|
||||||
else:
|
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))
|
d.addCallback(lambda r: self._render_response(r, OK_CODE))
|
||||||
|
|
||||||
return d
|
return d
|
||||||
|
|
59
lbrynet/lbrynet_daemon/LBRYDaemonCLI.py
Normal file
59
lbrynet/lbrynet_daemon/LBRYDaemonCLI.py
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
import sys
|
||||||
|
import json
|
||||||
|
|
||||||
|
from lbrynet.conf import API_CONNECTION_STRING, LOG_FILE_NAME
|
||||||
|
from jsonrpc.proxy import JSONRPCProxy
|
||||||
|
|
||||||
|
help_msg = "Useage: lbrynet-cli method json-args\n" \
|
||||||
|
+ "Examples: " \
|
||||||
|
+ "lbrynet-cli resolve_name '{\"name\": \"what\"}'\n" \
|
||||||
|
+ "lbrynet-cli get_balance\n" \
|
||||||
|
+ "lbrynet-cli help '{\"function\": \"resolve_name\"}'\n" \
|
||||||
|
+ "\n******lbrynet-cli functions******\n"
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
api = JSONRPCProxy.from_url(API_CONNECTION_STRING)
|
||||||
|
|
||||||
|
try:
|
||||||
|
s = api.is_running()
|
||||||
|
except:
|
||||||
|
print "lbrynet-daemon isn't running"
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
args = sys.argv[1:]
|
||||||
|
meth = args[0]
|
||||||
|
|
||||||
|
msg = help_msg
|
||||||
|
for f in api.help():
|
||||||
|
msg += f + "\n"
|
||||||
|
|
||||||
|
if meth in ['--help', '-h', 'help']:
|
||||||
|
print msg
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
if len(args) > 1:
|
||||||
|
if isinstance(args[1], dict):
|
||||||
|
params = args[1]
|
||||||
|
elif isinstance(args[1], str) or isinstance(args[1], unicode):
|
||||||
|
params = json.loads(args[1])
|
||||||
|
else:
|
||||||
|
params = None
|
||||||
|
|
||||||
|
if meth in api.help():
|
||||||
|
try:
|
||||||
|
if params:
|
||||||
|
r = api.call(meth, params)
|
||||||
|
else:
|
||||||
|
r = api.call(meth)
|
||||||
|
print r
|
||||||
|
except:
|
||||||
|
print "Something went wrong, here's the usage for %s:" % meth
|
||||||
|
print api.help({'function': meth})
|
||||||
|
else:
|
||||||
|
print "Unknown function"
|
||||||
|
print msg
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
|
@ -8,6 +8,7 @@ from urllib2 import urlopen
|
||||||
from StringIO import StringIO
|
from StringIO import StringIO
|
||||||
from twisted.web import static
|
from twisted.web import static
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
|
from twisted.internet.task import LoopingCall
|
||||||
from lbrynet.conf import DEFAULT_UI_BRANCH, LOG_FILE_NAME
|
from lbrynet.conf import DEFAULT_UI_BRANCH, LOG_FILE_NAME
|
||||||
from lbrynet import __version__ as lbrynet_version
|
from lbrynet import __version__ as lbrynet_version
|
||||||
from lbryum.version import LBRYUM_VERSION as lbryum_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.config = os.path.join(self.ui_root, "active.json")
|
||||||
self.update_requires = os.path.join(self.update_dir, "requirements.txt")
|
self.update_requires = os.path.join(self.update_dir, "requirements.txt")
|
||||||
self.requirements = {}
|
self.requirements = {}
|
||||||
|
self.check_requirements = True
|
||||||
self.ui_dir = self.active_dir
|
self.ui_dir = self.active_dir
|
||||||
self.git_version = None
|
self.git_version = None
|
||||||
self.root = root
|
self.root = root
|
||||||
|
self.branch = None
|
||||||
|
self.update_checker = LoopingCall(self.setup)
|
||||||
|
|
||||||
if not os.path.isfile(os.path.join(self.config)):
|
if not os.path.isfile(os.path.join(self.config)):
|
||||||
self.loaded_git_version = None
|
self.loaded_git_version = None
|
||||||
|
@ -73,7 +77,10 @@ class LBRYUIManager(object):
|
||||||
self.loaded_branch = None
|
self.loaded_branch = None
|
||||||
self.loaded_requirements = 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
|
self.branch = branch
|
||||||
if user_specified:
|
if user_specified:
|
||||||
if os.path.isdir(user_specified):
|
if os.path.isdir(user_specified):
|
||||||
|
@ -84,7 +91,7 @@ class LBRYUIManager(object):
|
||||||
d.addCallback(lambda _: self._load_ui())
|
d.addCallback(lambda _: self._load_ui())
|
||||||
return d
|
return d
|
||||||
else:
|
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:
|
elif self.loaded_branch == "user-specified" and not branch_specified:
|
||||||
log.info("Loading user provided UI")
|
log.info("Loading user provided UI")
|
||||||
d = self._load_ui()
|
d = self._load_ui()
|
||||||
|
@ -113,8 +120,12 @@ class LBRYUIManager(object):
|
||||||
log.info("UI updates available, checking if installation meets requirements")
|
log.info("UI updates available, checking if installation meets requirements")
|
||||||
return defer.succeed(False)
|
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 = _get_git_info()
|
||||||
d.addCallback(_set_git)
|
d.addCallbacks(_set_git, lambda _: _use_existing)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def migrate_ui(self, source=None):
|
def migrate_ui(self, source=None):
|
||||||
|
@ -127,6 +138,10 @@ class LBRYUIManager(object):
|
||||||
source_dir = source
|
source_dir = source
|
||||||
delete_source = False
|
delete_source = False
|
||||||
|
|
||||||
|
def _skip_requirements():
|
||||||
|
log.info("Skipping ui requirement check")
|
||||||
|
return defer.succeed(True)
|
||||||
|
|
||||||
def _check_requirements():
|
def _check_requirements():
|
||||||
if not os.path.isfile(requires_file):
|
if not os.path.isfile(requires_file):
|
||||||
log.info("No requirements.txt file, rejecting request to migrate this UI")
|
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']
|
self.loaded_requirements = loaded_ui['requirements']
|
||||||
return defer.succeed(True)
|
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())
|
d.addCallback(lambda r: _do_migrate() if r else _disp_failure())
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
3
setup.py
3
setup.py
|
@ -21,7 +21,8 @@ console_scripts = ['lbrynet-console = lbrynet.lbrynet_console.LBRYConsole:launch
|
||||||
'lbrynet-lookup-hosts-for-hash = lbrynet.dht_scripts:get_hosts_for_hash_in_dht',
|
'lbrynet-lookup-hosts-for-hash = lbrynet.dht_scripts:get_hosts_for_hash_in_dht',
|
||||||
'lbrynet-announce_hash_to_dht = lbrynet.dht_scripts:announce_hash_to_dht',
|
'lbrynet-announce_hash_to_dht = lbrynet.dht_scripts:announce_hash_to_dht',
|
||||||
'lbrynet-daemon = lbrynet.lbrynet_daemon.LBRYDaemonControl:start',
|
'lbrynet-daemon = lbrynet.lbrynet_daemon.LBRYDaemonControl:start',
|
||||||
'stop-lbrynet-daemon = lbrynet.lbrynet_daemon.LBRYDaemonControl:stop']
|
'stop-lbrynet-daemon = lbrynet.lbrynet_daemon.LBRYDaemonControl:stop',
|
||||||
|
'lbrynet-cli = lbrynet.lbrynet_daemon.LBRYDaemonCLI:main']
|
||||||
|
|
||||||
requires = ['pycrypto', 'twisted', 'miniupnpc', 'yapsy', 'seccure',
|
requires = ['pycrypto', 'twisted', 'miniupnpc', 'yapsy', 'seccure',
|
||||||
'python-bitcoinrpc==0.1', 'txJSON-RPC', 'requests>=2.4.2', 'unqlite==0.2.0',
|
'python-bitcoinrpc==0.1', 'txJSON-RPC', 'requests>=2.4.2', 'unqlite==0.2.0',
|
||||||
|
|
Loading…
Reference in a new issue