Status bar for lbrynet daemon

This commit is contained in:
Jack 2016-02-18 20:41:23 -05:00
parent 4451978af6
commit 2c51928b9d
2 changed files with 108 additions and 35 deletions

View file

@ -1,3 +1,6 @@
from threading import Thread
from time import sleep
from lbrynet.core.PaymentRateManager import PaymentRateManager from lbrynet.core.PaymentRateManager import PaymentRateManager
from lbrynet.core.server.BlobAvailabilityHandler import BlobAvailabilityHandlerFactory from lbrynet.core.server.BlobAvailabilityHandler import BlobAvailabilityHandlerFactory
from lbrynet.core.server.BlobRequestHandler import BlobRequestHandlerFactory from lbrynet.core.server.BlobRequestHandler import BlobRequestHandlerFactory
@ -21,18 +24,11 @@ from lbrynet.lbryfile.LBRYFileMetadataManager import DBLBRYFileMetadataManager,
from twisted.web import xmlrpc, server from twisted.web import xmlrpc, server
from twisted.internet import defer, threads, reactor, error from twisted.internet import defer, threads, reactor, error
from datetime import datetime from datetime import datetime
import logging
import os
import sys
import json
import binascii
import webbrowser
import xmlrpclib
from decimal import Decimal from decimal import Decimal
import subprocess
from StringIO import StringIO from StringIO import StringIO
from zipfile import ZipFile from zipfile import ZipFile
from urllib import urlopen from urllib import urlopen
import os, sys, json, binascii, webbrowser, xmlrpclib, subprocess, logging, rumps
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -565,12 +561,6 @@ class LBRYDaemon(xmlrpc.XMLRPC):
d.cancel() d.cancel()
return defer.succeed(None) return defer.succeed(None)
def _to_dict(r):
t = {}
for i in r:
t[i[0]] = i[1]
return t
def _add_key_fee(data_cost): def _add_key_fee(data_cost):
d = self.session.wallet.get_stream_info_for_name(name) d = self.session.wallet.get_stream_info_for_name(name)
d.addCallback(lambda info: data_cost + info['key_fee'] if 'key_fee' in info.keys() else data_cost) d.addCallback(lambda info: data_cost + info['key_fee'] if 'key_fee' in info.keys() else data_cost)
@ -581,14 +571,16 @@ class LBRYDaemon(xmlrpc.XMLRPC):
self.blob_request_payment_rate_manager)) self.blob_request_payment_rate_manager))
d.addCallback(self.sd_identifier.get_metadata_for_sd_blob) d.addCallback(self.sd_identifier.get_metadata_for_sd_blob)
d.addCallback(lambda metadata: metadata.validator.info_to_show()) d.addCallback(lambda metadata: metadata.validator.info_to_show())
d.addCallback(_to_dict) d.addCallback(lambda info: int(dict(info)['stream_size']) / 1000000 * self.data_rate)
d.addCallback(lambda info: int(info['stream_size']) / 1000000 * self.data_rate)
d.addCallback(_add_key_fee) d.addCallback(_add_key_fee)
d.addErrback(lambda _: _add_key_fee(0.0)) d.addErrback(lambda _: _add_key_fee(0.0))
reactor.callLater(self.search_timeout, _check_est, d, name) reactor.callLater(self.search_timeout, _check_est, d, name)
return d return d
def xmlrpc_is_running(self):
return True
def xmlrpc_get_settings(self): def xmlrpc_get_settings(self):
""" """
Get LBRY payment settings Get LBRY payment settings
@ -855,16 +847,6 @@ class LBRYDaemon(xmlrpc.XMLRPC):
d.addCallback(lambda trie: [claim for claim in trie if claim['name'].startswith(search) and 'txid' in claim]) d.addCallback(lambda trie: [claim for claim in trie if claim['name'].startswith(search) and 'txid' in claim])
d.addCallback(lambda claims: claims[:self.max_search_results]) d.addCallback(lambda claims: claims[:self.max_search_results])
d.addCallback(resolve_claims) d.addCallback(resolve_claims)
#filtered_results = [n for n in self.session.wallet.get_nametrie() if n['name'].startswith(search)]
#if len(filtered_results) > self.max_search_results:
# filtered_results = filtered_results[:self.max_search_results]
#filtered_results = [n for n in filtered_results if 'txid' in n.keys()]
#resolved_results = [defer.DeferredList([_return_d(n), self._resolve_name_wc(n['name']),
# self._get_est_cost(n['name'])], consumeErrors=True)
# for n in filtered_results]
#d = defer.DeferredList(resolved_results)
d.addCallback(_clean) d.addCallback(_clean)
d.addCallback(_parse) d.addCallback(_parse)
d.addCallback(_disp) d.addCallback(_disp)
@ -1036,19 +1018,52 @@ class LBRYDaemon(xmlrpc.XMLRPC):
return message return message
def main():
# shut down existing instance of lbrynet-daemon if there is one class DaemonStatusBarApp(rumps.App):
try: def __init__(self):
super(DaemonStatusBarApp, self).__init__("LBRYnet", icon=os.path.join(os.path.expanduser("~"), "Downloads/lbryio/lbry.io/web/img/fav/apple-touch-icon.png"), quit_button=None)
self.menu = ["Quit"]
# shut down existing instance of lbrynet-daemon if there is one
try:
d = xmlrpclib.ServerProxy('http://localhost:7080')
d.stop()
except:
pass
daemon = LBRYDaemon()
daemon.setup()
reactor.listenTCP(7080, server.Site(daemon))
Thread(target=reactor.run, args=(False,)).start()
@rumps.clicked('Quit')
def clean_quit(self):
d = xmlrpclib.ServerProxy('http://localhost:7080') d = xmlrpclib.ServerProxy('http://localhost:7080')
d.stop() d.stop()
except: while True:
pass try:
d.is_running()
except:
break
daemon = LBRYDaemon() sleep(1)
daemon.setup()
reactor.listenTCP(7080, server.Site(daemon))
reactor.run()
rumps.quit_application()
def main():
if sys.platform == "darwin":
DaemonStatusBarApp().run()
else:
try:
d = xmlrpclib.ServerProxy('http://localhost:7080')
d.stop()
except:
pass
daemon = LBRYDaemon()
daemon.setup()
reactor.listenTCP(7080, server.Site(daemon))
reactor.run()
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -1,5 +1,63 @@
#!/bin/sh #!/bin/sh
if ! which brew &>/dev/null; then
echo "Installing brew..."
sudo -u ${SUDO_USER} ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null &>/dev/null
else
echo "Updating brew..."
sudo -u ${SUDO_USER} brew update &>/dev/null
fi
if ! brew list mpfr &>/dev/null; then
echo "Installing mpfr..."
sudo -u ${SUDO_USER} brew install mpfr &>/dev/null
else
echo "mpfr already installed..."
fi
if ! brew list libmpc &>/dev/null; then
echo "Installing libmpc..."
sudo -u ${SUDO_USER} brew install libmpc &>/dev/null
else
echo "libmpc already installed..."
fi
if ! brew list openssl &>/dev/null; then
echo "Installing openssl..."
sudo -u ${SUDO_USER} brew install openssl &>/dev/null
sudo -u ${SUDO_USER} brew link --force openssl &>/dev/null
else
echo "openssl already installed..."
fi
if ! which pip &>/dev/null; then
echo "Installing pip..."
sudo easy_install pip &>/dev/null
else
echo "pip already installed"
fi
if ! python -c 'import gmpy' &>/dev/null; then
echo "Installing gmpy..."
sudo pip install gmpy &>/dev/null
else
echo "gmpy already installed..."
fi
if ! python -c 'import service_identity' &>/dev/null; then
echo "Installing service_identity..."
sudo pip install service_identity &>/dev/null
else
echo "gmpy already installed..."
fi
if ! python -c 'import rumps' &>/dev/null; then
echo "Installing rumps..."
sudo pip install rumps &>/dev/null
else
echo "rumps already installed..."
fi
lbrycrd_directory="/Users/${SUDO_USER}/Library/Application Support/lbrycrd" lbrycrd_directory="/Users/${SUDO_USER}/Library/Application Support/lbrycrd"
current_version=$(git ls-remote https://github.com/jackrobison/lbrynet-app.git | grep HEAD | cut -f 1) current_version=$(git ls-remote https://github.com/jackrobison/lbrynet-app.git | grep HEAD | cut -f 1)