forked from LBRYCommunity/lbry-sdk
update daemon
-notify user when connected to lbrynet -check for updates from status bar app
This commit is contained in:
parent
2fc3ec7224
commit
02d8dc22e9
2 changed files with 128 additions and 49 deletions
|
@ -1,3 +1,4 @@
|
|||
import locale
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
|
@ -8,10 +9,10 @@ import subprocess
|
|||
import logging
|
||||
import argparse
|
||||
import pwd
|
||||
import requests
|
||||
|
||||
from twisted.web import xmlrpc, server
|
||||
from twisted.internet import defer, threads, reactor, error
|
||||
|
||||
from datetime import datetime
|
||||
from decimal import Decimal
|
||||
from StringIO import StringIO
|
||||
|
@ -39,8 +40,9 @@ from lbrynet.core.LBRYcrdWallet import LBRYcrdWallet, LBRYumWallet
|
|||
from lbrynet.lbryfilemanager.LBRYFileManager import LBRYFileManager
|
||||
from lbrynet.lbryfile.LBRYFileMetadataManager import DBLBRYFileMetadataManager, TempLBRYFileMetadataManager
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
# logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
|
||||
|
@ -118,6 +120,8 @@ class LBRYDaemon(xmlrpc.XMLRPC):
|
|||
self.max_key_fee = DEFAULT_MAX_KEY_FEE
|
||||
self.max_search_results = DEFAULT_MAX_SEARCH_RESULTS
|
||||
self.restart_message = ""
|
||||
self.startup_message = ""
|
||||
self.announced_startup = False
|
||||
self.search_timeout = 3.0
|
||||
self.query_handlers = {}
|
||||
|
||||
|
@ -323,8 +327,6 @@ class LBRYDaemon(xmlrpc.XMLRPC):
|
|||
d = self._stop_server()
|
||||
if self.session is not None:
|
||||
d.addCallback(lambda _: self.session.shut_down())
|
||||
# if self.status_app:
|
||||
# d.addCallback(lambda _: self.status_app.stop())
|
||||
return d
|
||||
|
||||
def _update_settings(self):
|
||||
|
@ -453,8 +455,45 @@ class LBRYDaemon(xmlrpc.XMLRPC):
|
|||
dl.addCallback(combine_results)
|
||||
dl.addCallback(create_session)
|
||||
dl.addCallback(lambda _: self.session.setup())
|
||||
dl.addCallback(lambda _: self._check_first_run())
|
||||
dl.addCallback(self._show_first_run_result)
|
||||
return dl
|
||||
|
||||
def _check_first_run(self):
|
||||
d = self.session.wallet.check_first_run()
|
||||
d.addCallback(lambda is_first_run: self._do_first_run() if is_first_run else 0.0)
|
||||
return d
|
||||
|
||||
def _do_first_run(self):
|
||||
d = self.session.wallet.get_new_address()
|
||||
|
||||
def send_request(url, data):
|
||||
r = requests.post(url, json=data)
|
||||
if r.status_code == 200:
|
||||
return r.json()['credits_sent']
|
||||
return 0.0
|
||||
|
||||
def log_error(err):
|
||||
log.warning("unable to request free credits. %s", err.getErrorMessage())
|
||||
return 0.0
|
||||
|
||||
def request_credits(address):
|
||||
url = "http://credreq.lbry.io/requestcredits"
|
||||
data = {"address": address}
|
||||
d = threads.deferToThread(send_request, url, data)
|
||||
d.addErrback(log_error)
|
||||
return d
|
||||
|
||||
d.addCallback(request_credits)
|
||||
return d
|
||||
|
||||
def _show_first_run_result(self, credits_received):
|
||||
if credits_received != 0.0:
|
||||
points_string = locale.format_string("%.2f LBC", (round(credits_received, 2),), grouping=True)
|
||||
self.startup_message = "Thank you for testing the alpha version of LBRY! You have been given %s for free because we love you. Please give them a few minutes to show up while you catch up with our blockchain." % points_string
|
||||
else:
|
||||
self.startup_message = "Connected to LBRYnet"
|
||||
|
||||
def _get_lbrycrdd_path(self):
|
||||
def get_lbrycrdd_path_conf_file():
|
||||
lbrycrdd_path_conf_path = os.path.join(os.path.expanduser("~"), ".lbrycrddpath.conf")
|
||||
|
@ -629,7 +668,14 @@ class LBRYDaemon(xmlrpc.XMLRPC):
|
|||
return d
|
||||
|
||||
def xmlrpc_is_running(self):
|
||||
if self.startup_message != "" and self.announced_startup == False:
|
||||
print "Startup message:", self.startup_message
|
||||
self.announced_startup = True
|
||||
return self.startup_message
|
||||
elif self.announced_startup:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def xmlrpc_get_settings(self):
|
||||
"""
|
||||
|
@ -1050,40 +1096,52 @@ class LBRYDaemon(xmlrpc.XMLRPC):
|
|||
return self.fetcher.verbose
|
||||
|
||||
def xmlrpc_check_for_new_version(self):
|
||||
message = ""
|
||||
|
||||
git_version = subprocess.check_output("git ls-remote https://github.com/lbryio/lbry.git | grep HEAD | cut -f 1", shell=True)
|
||||
if os.path.isfile(os.path.join(self.db_dir, "lbrynet_version.txt")):
|
||||
f = open(os.path.join(self.db_dir, "lbrynet_version.txt"), 'r')
|
||||
def _check_for_updates(package):
|
||||
git_version = subprocess.check_output("git ls-remote " + package['git'] + " | grep HEAD | cut -f 1", shell=True)
|
||||
up_to_date = False
|
||||
if os.path.isfile(package['version_file']):
|
||||
f = open(package['version_file'], 'r')
|
||||
current_version = f.read()
|
||||
f.close()
|
||||
|
||||
if git_version == current_version:
|
||||
message += "LBRYnet is up to date\n"
|
||||
r = package['name'] + " is up to date"
|
||||
up_to_date = True
|
||||
else:
|
||||
message += "LBRYnet version is out of date, restart the daemon to update\n"
|
||||
r = package['name'] + " version is out of date"
|
||||
else:
|
||||
message += "Unknown version of LBRYnet, try running installer again\n"
|
||||
r = "Unknown version of " + package['name']
|
||||
|
||||
git_version = subprocess.check_output("git ls-remote https://github.com/jackrobison/lbrynet-app.git | grep HEAD | cut -f 1", shell=True)
|
||||
if os.path.isfile(os.path.join(self.wallet_dir, "lbry_app_version.txt")):
|
||||
f = open(os.path.join(self.wallet_dir, "lbry_app_version.txt"), 'r')
|
||||
current_version = f.read()
|
||||
f.close()
|
||||
return (up_to_date, r)
|
||||
|
||||
if git_version == current_version:
|
||||
message += "LBRY is up to date"
|
||||
else:
|
||||
message += "LBRY version is out of date, restart the daemon to update"
|
||||
else:
|
||||
message += "Unknown version of LBRYnet, try running installer again\n"
|
||||
package_infos = {
|
||||
"lbrynet": {"name": "LBRYnet",
|
||||
"git": "https://github.com/lbryio/lbry.git",
|
||||
"version_file": os.path.join(self.db_dir, ".lbrynet_version"),
|
||||
"clone": ".lbrygit",
|
||||
},
|
||||
"lbryum": {"name": "lbryum",
|
||||
"git": "https://github.com/lbryio/lbryum.git",
|
||||
"version_file": os.path.join(self.db_dir, ".lbryum_version"),
|
||||
"clone": ".lbryumgit",
|
||||
},
|
||||
"lbry": {"name": "LBRY",
|
||||
"git": "https://github.com/jackrobison/lbrynet-app.git",
|
||||
"version_file": os.path.join(self.db_dir, ".lbry_app_version"),
|
||||
"clone": None,
|
||||
},
|
||||
}
|
||||
|
||||
return message
|
||||
return [_check_for_updates(package_infos[p]) for p in package_infos.keys()]
|
||||
|
||||
def xmlrpc_start_status_bar_app(self):
|
||||
if sys.platform == 'darwin':
|
||||
subprocess.Popen("screen -dmS lbry-status bash -c 'lbrynet-daemon-status --startdaemon=False'", shell=True)
|
||||
if os.path.isdir("/Applications/LBRY.app"):
|
||||
# subprocess.Popen("screen -dmS lbry-status bash -c 'lbrynet-daemon-status --startdaemon=False'", shell=True)
|
||||
subprocess.Popen("screen -dmS lbry-status bash -c 'open /Applications/LBRY.app'")
|
||||
return "Started"
|
||||
else:
|
||||
return "Couldn't find LBRY.app, try running the installer"
|
||||
else:
|
||||
return "Status bar not implemented on non OS X"
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@ import argparse
|
|||
class DaemonStatusBarApp(rumps.App):
|
||||
def __init__(self):
|
||||
icon_path = 'app.icns'
|
||||
|
||||
if os.path.isfile(icon_path):
|
||||
rumps.App.__init__(self, name="LBRY", icon=icon_path, quit_button=None,
|
||||
menu=["Open", "Preferences", "View balance", "Quit"])
|
||||
|
@ -17,51 +16,69 @@ class DaemonStatusBarApp(rumps.App):
|
|||
rumps.App.__init__(self, name="LBRY", title="LBRY", quit_button=None,
|
||||
menu=["Open", "Preferences", "View balance", "Quit"])
|
||||
|
||||
@rumps.timer(1)
|
||||
def alert_daemon_start(self):
|
||||
daemon = xmlrpclib.ServerProxy("http://localhost:7080/")
|
||||
try:
|
||||
start_msg = daemon.is_running()
|
||||
if isinstance(start_msg, str):
|
||||
rumps.notification(title='LBRY', subtitle='', message=str(start_msg), sound=True)
|
||||
update_info = daemon.check_for_new_version()
|
||||
update_msg = ""
|
||||
for p in update_info:
|
||||
if not p[0]:
|
||||
update_msg += p[1] + "\n"
|
||||
if update_msg:
|
||||
update_msg += "\n Try running the installer again to fix this"
|
||||
rumps.notification(title='LBRY', subtitle='', message=update_msg, sound=True)
|
||||
except:
|
||||
pass
|
||||
|
||||
@rumps.clicked('Open')
|
||||
def get_ui(self):
|
||||
daemon = xmlrpclib.ServerProxy("http://localhost:7080/")
|
||||
try:
|
||||
daemon = xmlrpclib.ServerProxy('http://localhost:7080')
|
||||
daemon.is_running()
|
||||
webbrowser.open("lbry://lbry")
|
||||
except:
|
||||
try:
|
||||
rumps.notification(title='LBRY', subtitle='status', message="Couldn't connect to lbrynet daemon", sound=True)
|
||||
rumps.notification(title='LBRY', subtitle='', message="Couldn't connect to lbrynet daemon", sound=True)
|
||||
except:
|
||||
rumps.alert(title='LBRY', message="Couldn't connect to lbrynet daemon")
|
||||
|
||||
@rumps.clicked("Preferences")
|
||||
def prefs(self, _):
|
||||
def prefs(self):
|
||||
daemon = xmlrpclib.ServerProxy("http://localhost:7080/")
|
||||
try:
|
||||
daemon = xmlrpclib.ServerProxy('http://localhost:7080')
|
||||
daemon.is_running()
|
||||
webbrowser.open("lbry://settings")
|
||||
except:
|
||||
rumps.notification(title='LBRY', subtitle='status', message="Couldn't connect to lbrynet daemon", sound=True)
|
||||
rumps.notification(title='LBRY', subtitle='', message="Couldn't connect to lbrynet daemon", sound=True)
|
||||
|
||||
@rumps.clicked("View balance")
|
||||
def disp_balance(self):
|
||||
daemon = xmlrpclib.ServerProxy('http://localhost:7080')
|
||||
daemon = xmlrpclib.ServerProxy("http://localhost:7080/")
|
||||
try:
|
||||
balance = daemon.get_balance()
|
||||
r = round(float(balance), 2)
|
||||
try:
|
||||
rumps.notification(title='LBRY', subtitle='status', message="Your balance is " + str(balance), sound=False)
|
||||
rumps.notification(title='LBRY', subtitle='', message=str("Your balance is %.2f LBC" % r), sound=False)
|
||||
except:
|
||||
rumps.alert(title='LBRY', message="Your balance is " + str(balance))
|
||||
rumps.alert(title='LBRY', message=str("Your balance is %.2f LBC" % r))
|
||||
|
||||
except:
|
||||
try:
|
||||
rumps.notification(title='LBRY', subtitle='status', message="Couldn't connect to lbrynet daemon", sound=True)
|
||||
rumps.notification(title='LBRY', subtitle='', message="Couldn't connect to lbrynet daemon", sound=True)
|
||||
except:
|
||||
rumps.alert(title='LBRY', message="Couldn't connect to lbrynet daemon")
|
||||
|
||||
@rumps.clicked('Quit')
|
||||
def clean_quit(self):
|
||||
daemon = xmlrpclib.ServerProxy('http://localhost:7080')
|
||||
daemon = xmlrpclib.ServerProxy("http://localhost:7080/")
|
||||
try:
|
||||
daemon.stop()
|
||||
except:
|
||||
pass
|
||||
|
||||
rumps.quit_application()
|
||||
|
||||
|
||||
|
@ -74,6 +91,10 @@ def main():
|
|||
args = parser.parse_args()
|
||||
|
||||
if str(args.startdaemon).lower() == "true":
|
||||
daemon = xmlrpclib.ServerProxy('http://localhost:7080')
|
||||
try:
|
||||
daemon.is_running()
|
||||
except:
|
||||
subprocess.Popen("screen -dmS lbrynet bash -c "
|
||||
"'PYTHONPATH=$PYTHONPATH:`cat /Users/${USER}/Library/Application\ Support/lbrynet/.python_path`; "
|
||||
"PATH=$PATH:`cat /Users/${USER}/Library/Application\ Support/lbrynet/.lbry_bin_path`; "
|
||||
|
|
Loading…
Reference in a new issue