update lbrynet-daemon

This commit is contained in:
Jack 2016-02-25 17:17:07 -05:00
parent 96bc02c8cb
commit eeef183cc6
4 changed files with 113 additions and 78 deletions

View file

@ -8,7 +8,6 @@ from lbrynet.lbryfile.StreamDescriptor import LBRYFileStreamType
from lbrynet.lbryfile.client.LBRYFileDownloader import LBRYFileSaverFactory, LBRYFileOpenerFactory from lbrynet.lbryfile.client.LBRYFileDownloader import LBRYFileSaverFactory, LBRYFileOpenerFactory
from lbrynet.lbryfile.client.LBRYFileOptions import add_lbry_file_to_sd_identifier from lbrynet.lbryfile.client.LBRYFileOptions import add_lbry_file_to_sd_identifier
from lbrynet.lbrynet_daemon.LBRYDownloader import GetStream, FetcherDaemon from lbrynet.lbrynet_daemon.LBRYDownloader import GetStream, FetcherDaemon
# from lbrynet.lbrynet_daemon.LBRYOSXStatusBar import DaemonStatusBarApp
from lbrynet.lbrynet_daemon.LBRYPublisher import Publisher from lbrynet.lbrynet_daemon.LBRYPublisher import Publisher
from lbrynet.core.utils import generate_id from lbrynet.core.utils import generate_id
from lbrynet.lbrynet_console.LBRYSettings import LBRYSettings from lbrynet.lbrynet_console.LBRYSettings import LBRYSettings
@ -27,9 +26,10 @@ 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, argparse, getopt import os, sys, json, binascii, webbrowser, xmlrpclib, subprocess, logging, argparse
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
# logging.basicConfig(level=logging.DEBUG)
# TODO add login credentials in a conf file # TODO add login credentials in a conf file
@ -47,8 +47,8 @@ class LBRYDaemon(xmlrpc.XMLRPC):
LBRYnet daemon LBRYnet daemon
""" """
def setup(self, wallet_type): def setup(self, wallet_type, check_for_updates):
def _set_vars(wallet_type): def _set_vars(wallet_type, check_for_updates):
self.fetcher = None self.fetcher = None
self.current_db_revision = 1 self.current_db_revision = 1
self.run_server = True self.run_server = True
@ -58,7 +58,8 @@ class LBRYDaemon(xmlrpc.XMLRPC):
self.db_dir = os.path.join(os.path.expanduser("~"), ".lbrynet") self.db_dir = os.path.join(os.path.expanduser("~"), ".lbrynet")
else: else:
self.db_dir = os.path.join(os.path.expanduser("~"), "Library/Application Support/lbrynet") self.db_dir = os.path.join(os.path.expanduser("~"), "Library/Application Support/lbrynet")
# self.status_app = DaemonStatusBarApp() from lbrynet.lbrynet_daemon.LBRYOSXStatusBar import DaemonStatusBarApp
self.status_app = DaemonStatusBarApp()
self.blobfile_dir = os.path.join(self.db_dir, "blobfiles") self.blobfile_dir = os.path.join(self.db_dir, "blobfiles")
self.peer_port = 3333 self.peer_port = 3333
self.dht_node_port = 4444 self.dht_node_port = 4444
@ -95,9 +96,9 @@ class LBRYDaemon(xmlrpc.XMLRPC):
self.lbry_file_manager = None self.lbry_file_manager = None
self.settings = LBRYSettings(self.db_dir) self.settings = LBRYSettings(self.db_dir)
self.wallet_type = wallet_type self.wallet_type = wallet_type
self.check_for_updates = check_for_updates
self.lbrycrd_conf = os.path.join(self.wallet_dir, "lbrycrd.conf") self.lbrycrd_conf = os.path.join(self.wallet_dir, "lbrycrd.conf")
self.autofetcher_conf = os.path.join(self.wallet_dir, "autofetcher.conf") self.autofetcher_conf = os.path.join(self.wallet_dir, "autofetcher.conf")
self.files = []
self.created_data_dir = False self.created_data_dir = False
if not os.path.exists(self.db_dir): if not os.path.exists(self.db_dir):
os.mkdir(self.db_dir) os.mkdir(self.db_dir)
@ -118,11 +119,14 @@ class LBRYDaemon(xmlrpc.XMLRPC):
else: else:
print "Started LBRYnet daemon" print "Started LBRYnet daemon"
print "The daemon can be shut down by running 'stop-lbrynet-daemon' in a terminal" print "The daemon can be shut down by running 'stop-lbrynet-daemon' in a terminal"
log.info('[' + str(datetime.now()) + '] Started lbrynet-daemon')
return defer.succeed(None) return defer.succeed(None)
log.info('[' + str(datetime.now()) + '] Starting lbrynet-daemon')
d = defer.Deferred() d = defer.Deferred()
d.addCallback(lambda _: _set_vars(wallet_type)) d.addCallback(lambda _: _set_vars(wallet_type, check_for_updates))
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())
@ -135,8 +139,8 @@ class LBRYDaemon(xmlrpc.XMLRPC):
d.addCallback(lambda _: self._setup_query_handlers()) d.addCallback(lambda _: self._setup_query_handlers())
d.addCallback(lambda _: self._setup_server()) d.addCallback(lambda _: self._setup_server())
if sys.platform == "darwin": if sys.platform == "darwin":
d.addCallback(lambda _: self._update()) d.addCallback(lambda _: self._update() if self.check_for_updates == "True" else defer.succeed(None))
# d.addCallback(lambda _: self.status_app.run()) # d.addCallback(lambda _: defer.succeed(self.status_app.run()))
d.addCallback(lambda _: self._setup_fetcher()) d.addCallback(lambda _: self._setup_fetcher())
d.addCallback(lambda _: _disp_startup()) d.addCallback(lambda _: _disp_startup())
d.callback(None) d.callback(None)
@ -399,6 +403,7 @@ class LBRYDaemon(xmlrpc.XMLRPC):
def get_wallet(): def get_wallet():
if self.wallet_type == "lbrycrd": if self.wallet_type == "lbrycrd":
print "Using lbrycrd wallet" print "Using lbrycrd wallet"
log.info("Using lbrycrd wallet")
lbrycrdd_path = None lbrycrdd_path = None
if self.start_lbrycrdd is True: if self.start_lbrycrdd is True:
lbrycrdd_path = self.lbrycrdd_path lbrycrdd_path = self.lbrycrdd_path
@ -408,9 +413,11 @@ class LBRYDaemon(xmlrpc.XMLRPC):
lbrycrdd_path=lbrycrdd_path)) lbrycrdd_path=lbrycrdd_path))
elif self.wallet_type == "lbryum": elif self.wallet_type == "lbryum":
print "Using lbryum wallet" print "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":
print "Using PTC wallet" print "Using PTC wallet"
log.info("Using PTC wallet")
d = defer.succeed(PTCWallet(self.db_dir)) d = defer.succeed(PTCWallet(self.db_dir))
else: else:
d = defer.fail() d = defer.fail()
@ -539,9 +546,11 @@ class LBRYDaemon(xmlrpc.XMLRPC):
path = os.path.join(self.blobfile_dir, stream_hash) path = os.path.join(self.blobfile_dir, stream_hash)
if os.path.isfile(path): if os.path.isfile(path):
print "[" + str(datetime.now()) + "] Search for lbry_file, returning: " + stream_hash print "[" + str(datetime.now()) + "] Search for lbry_file, returning: " + stream_hash
log.info("[" + str(datetime.now()) + "] Search for lbry_file, returning: " + stream_hash)
return defer.succeed(_get_lbry_file(path)) return defer.succeed(_get_lbry_file(path))
else: else:
print "[" + str(datetime.now()) + "] Search for lbry_file didn't return anything" print "[" + str(datetime.now()) + "] Search for lbry_file didn't return anything"
log.info("[" + str(datetime.now()) + "] Search for lbry_file didn't return anything")
return defer.succeed(False) return defer.succeed(False)
d = self._resolve_name(name) d = self._resolve_name(name)
@ -587,8 +596,10 @@ class LBRYDaemon(xmlrpc.XMLRPC):
def _check_est(d, name): def _check_est(d, name):
if type(d.result) is float: if type(d.result) is float:
print '[' + str(datetime.now()) + '] Cost est for lbry://' + name + ': ' + str(d.result) + 'LBC' print '[' + str(datetime.now()) + '] Cost est for lbry://' + name + ': ' + str(d.result) + 'LBC'
log.info('[' + str(datetime.now()) + '] Cost est for lbry://' + name + ': ' + str(d.result) + 'LBC')
else: else:
print '[' + str(datetime.now()) + '] Timeout estimating cost for lbry://' + name + ', using key fee' print '[' + str(datetime.now()) + '] Timeout estimating cost for lbry://' + name + ', using key fee'
log.info('[' + str(datetime.now()) + '] Timeout estimating cost for lbry://' + name + ', using key fee')
d.cancel() d.cancel()
return defer.succeed(None) return defer.succeed(None)
@ -645,6 +656,7 @@ class LBRYDaemon(xmlrpc.XMLRPC):
self.fetcher.start() self.fetcher.start()
print '[' + str(datetime.now()) + '] Start autofetcher' print '[' + str(datetime.now()) + '] Start autofetcher'
log.info('[' + str(datetime.now()) + '] Start autofetcher')
return 'Started autofetching' return 'Started autofetching'
def xmlrpc_stop_fetcher(self): def xmlrpc_stop_fetcher(self):
@ -654,6 +666,7 @@ class LBRYDaemon(xmlrpc.XMLRPC):
self.fetcher.stop() self.fetcher.stop()
print '[' + str(datetime.now()) + '] Stop autofetcher' print '[' + str(datetime.now()) + '] Stop autofetcher'
log.info('[' + str(datetime.now()) + '] Stop autofetcher')
return 'Stopped autofetching' return 'Stopped autofetching'
def xmlrpc_fetcher_status(self): def xmlrpc_fetcher_status(self):
@ -678,6 +691,7 @@ class LBRYDaemon(xmlrpc.XMLRPC):
""" """
def _disp_shutdown(): def _disp_shutdown():
log.info('Shutting down lbrynet daemon')
print 'Shutting down lbrynet daemon' print 'Shutting down lbrynet daemon'
d = self._shutdown() d = self._shutdown()
@ -720,7 +734,6 @@ class LBRYDaemon(xmlrpc.XMLRPC):
""" """
def _disp(info): def _disp(info):
log.debug('[' + str(datetime.now()) + ']' + ' Resolved info: ' + str(info['stream_hash']))
print '[' + str(datetime.now()) + ']' + ' Resolved info: ' + str(info['stream_hash']) print '[' + str(datetime.now()) + ']' + ' Resolved info: ' + str(info['stream_hash'])
return info return info
@ -822,13 +835,6 @@ class LBRYDaemon(xmlrpc.XMLRPC):
@return: @return:
""" """
#def _return_d(x):
# d = defer.Deferred()
# d.addCallback(lambda _: x)
# d.callback(None)
# return d
def _clean(n): def _clean(n):
t = [] t = []
for i in n: for i in n:
@ -870,9 +876,13 @@ class LBRYDaemon(xmlrpc.XMLRPC):
def _disp(results): def _disp(results):
print '[' + str(datetime.now()) + '] Found ' + str(len(results)) + ' results' print '[' + str(datetime.now()) + '] Found ' + str(len(results)) + ' results'
log.info('[' + str(datetime.now()) + '] Search results: ')
for r in results:
log.info(str(r))
return results return results
print '[' + str(datetime.now()) + '] Search nametrie: ' + search print '[' + str(datetime.now()) + '] Search nametrie: ' + search
log.info('[' + str(datetime.now()) + '] Search nametrie: ' + search)
d = self.session.wallet.get_nametrie() d = self.session.wallet.get_nametrie()
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])
@ -953,6 +963,9 @@ class LBRYDaemon(xmlrpc.XMLRPC):
else: else:
content_license = None content_license = None
log.info('[' + str(datetime.now()) + '] Publish: ', name, file_path, bid, title, description, thumbnail,
key_fee, key_fee_address, content_license)
p = Publisher(self.session, self.lbry_file_manager, self.session.wallet) p = Publisher(self.session, self.lbry_file_manager, self.session.wallet)
d = p.start(name, file_path, bid, title, description, thumbnail, key_fee, key_fee_address, content_license) d = p.start(name, file_path, bid, title, description, thumbnail, key_fee, key_fee_address, content_license)
@ -990,6 +1003,15 @@ class LBRYDaemon(xmlrpc.XMLRPC):
return d return d
def xmlrpc_get_new_address(self):
def _disp(address):
print "[" + str(datetime.now()) + "] Got new wallet address: " + address
return address
d = self.session.wallet.get_new_address()
d.addCallback(_disp)
return d
# def xmlrpc_update_name(self, metadata): # def xmlrpc_update_name(self, metadata):
# def _disp(x): # def _disp(x):
# print x # print x
@ -1053,9 +1075,14 @@ class LBRYDaemon(xmlrpc.XMLRPC):
def main(): def main():
parser = argparse.ArgumentParser(description="Launch lbrynet-daemon") parser = argparse.ArgumentParser(description="Launch lbrynet-daemon")
parser.add_argument("--wallet", parser.add_argument("--wallet",
help="Either lbrycrd or lbryum", help="lbrycrd or lbryum, default lbryum",
type=str, type=str,
default="lbryum") default="lbryum")
parser.add_argument("--update",
help="True or false, default true",
type=str,
default="True")
args = parser.parse_args() args = parser.parse_args()
try: try:
@ -1065,7 +1092,7 @@ def main():
pass pass
daemon = LBRYDaemon() daemon = LBRYDaemon()
daemon.setup(args.wallet) daemon.setup(args.wallet, args.update)
reactor.listenTCP(7080, server.Site(daemon)) reactor.listenTCP(7080, server.Site(daemon))
reactor.run() reactor.run()

View file

@ -4,12 +4,11 @@ import xmlrpclib
def main(): def main():
daemon = xmlrpclib.ServerProxy("http://localhost:7080/") daemon = xmlrpclib.ServerProxy("http://localhost:7080/")
try: try:
b = daemon.get_balance() status = daemon.is_running()
is_running = True
except: except:
is_running = False status = False
if is_running: if status:
daemon.stop() daemon.stop()
print "LBRYnet daemon stopped" print "LBRYnet daemon stopped"
else: else:

View file

@ -1,15 +1,25 @@
import rumps import rumps
import xmlrpclib import xmlrpclib
import os import os
import webbrowser
class DaemonStatusBarApp(rumps.App): class DaemonStatusBarApp(rumps.App):
def __init__(self): def __init__(self):
super(DaemonStatusBarApp, self).__init__("LBRYnet", icon=os.path.join(os.path.expanduser("~"), "Downloads/lbryio//web/img/fav/apple-touch-icon.png"), quit_button=None) super(DaemonStatusBarApp, self).__init__("LBRYnet", icon=os.path.join(os.path.expanduser("~"), "Downloads/lbryio//web/img/fav/apple-touch-icon.png"), quit_button=None)
self.menu = ["Quit"] self.menu = ["Open UI", "Quit"]
@rumps.clicked('Open UI')
def get_ui(self):
webbrowser.open("lbry://lbry")
@rumps.clicked('Quit') @rumps.clicked('Quit')
def clean_quit(self): def clean_quit(self):
d = xmlrpclib.ServerProxy('http://localhost:7080') daemon = xmlrpclib.ServerProxy('http://localhost:7080')
d.stop() daemon.stop()
rumps.quit_application() rumps.quit_application()
def main():
DaemonStatusBarApp().run()
if __name__ == '__main__':
main()

View file

@ -59,7 +59,7 @@ else
fi fi
if ! python -c "import six; exit(0) if six.__version__ == '1.9.0' else exit(1)" &>/dev/null; then if ! python -c "import six; exit(0) if six.__version__ == '1.9.0' else exit(1)" &>/dev/null; then
echo "Installing six 1.9.0 for python" echo "Installing six 1.9.0 for python..."
curl -O https://pypi.python.org/packages/source/s/six/six-1.9.0.tar.gz &>/dev/null curl -O https://pypi.python.org/packages/source/s/six/six-1.9.0.tar.gz &>/dev/null
tar xf six-1.9.0.tar.gz &>/dev/null tar xf six-1.9.0.tar.gz &>/dev/null
cd six-1.9.0 cd six-1.9.0
@ -70,6 +70,51 @@ if ! python -c "import six; exit(0) if six.__version__ == '1.9.0' else exit(1)"
fi fi
lbrynet_directory="/Users/${SUDO_USER}/Library/Application Support/lbrynet" lbrynet_directory="/Users/${SUDO_USER}/Library/Application Support/lbrynet"
lbryum_current_version=$(git ls-remote https://github.com/lbryio/lbryum.git | grep HEAD | cut -f 1)
if [ -d "$lbrynet_directory" ]; then
if [ -f "${lbrynet_directory}/lbryum_version.txt" ]; then
if grep -Fxq "$lbryum_current_version" "${lbrynet_directory}/lbryum_version.txt"; then
echo "LBRYum version $lbryum_current_version is up to date"
else
tmp=$(mktemp -d)
cd $tmp
echo "Downloading LBRYum update..."
git clone -b search --depth 1 https://github.com/lbryio/lbryum.git &>/dev/null
cd lbryum
echo "Installing update..."
sudo python setup.py install &>/dev/null
mkdir -p "$lbrynet_directory"
echo $lbryum_current_version > "${lbrynet_directory}/lbryum_version.txt"
echo "Cleaning up..."
cd ../../
rm -rf $tmp
fi
else
tmp=$(mktemp -d)
cd $tmp
echo "Downloading LBRYum..."
git clone -b search--depth 1 https://github.com/lbryio/lbryum.git &>/dev/null
cd lbryum
echo "Installing..."
sudo python setup.py install &>/dev/null
mkdir -p "$lbrynet_directory"
echo $lbryum_current_version > "${lbrynet_directory}/lbryum_version.txt"
echo "Cleaning up..."
cd ../../
rm -rf $tmp
fi
fi
lbrynet_current_version=$(git ls-remote https://github.com/lbryio/lbry.git | grep HEAD | cut -f 1) lbrynet_current_version=$(git ls-remote https://github.com/lbryio/lbry.git | grep HEAD | cut -f 1)
@ -86,12 +131,12 @@ if [ -d "$lbrynet_directory" ]; then
git clone --depth 1 https://github.com/lbryio/lbry.git &>/dev/null git clone --depth 1 https://github.com/lbryio/lbry.git &>/dev/null
cd lbry cd lbry
echo "Installing update" echo "Installing update..."
sudo python setup.py install &>/dev/null sudo python setup.py install &>/dev/null
mkdir -p "$lbrynet_directory" mkdir -p "$lbrynet_directory"
echo $lbrynet_current_version > "${lbrynet_directory}/lbrynet_version.txt" echo $lbrynet_current_version > "${lbrynet_directory}/lbrynet_version.txt"
echo "Cleaning up" echo "Cleaning up..."
cd ../../ cd ../../
rm -rf $tmp rm -rf $tmp
@ -100,63 +145,17 @@ if [ -d "$lbrynet_directory" ]; then
tmp=$(mktemp -d) tmp=$(mktemp -d)
cd $tmp cd $tmp
echo "Downloading LBRYnet update" echo "Downloading LBRYnet..."
git clone --depth 1 https://github.com/lbryio/lbry.git &>/dev/null git clone --depth 1 https://github.com/lbryio/lbry.git &>/dev/null
cd lbry cd lbry
echo "Installing update" echo "Installing..."
sudo python setup.py install &>/dev/null sudo python setup.py install &>/dev/null
mkdir -p "$lbrynet_directory" mkdir -p "$lbrynet_directory"
echo $lbrynet_current_version > "${lbrynet_directory}/lbrynet_version.txt" echo $lbrynet_current_version > "${lbrynet_directory}/lbrynet_version.txt"
echo "Cleaning up" echo "Cleaning up..."
cd ../../
rm -rf $tmp
fi
fi
lbryum_current_version=$(git ls-remote https://github.com/lbryio/lbryum.git | grep HEAD | cut -f 1)
if [ -d "$lbrynet_directory" ]; then
if [ -f "${lbrynet_directory}/lbryum_version.txt" ]; then
if grep -Fxq "$lbryum_current_version" "${lbrynet_directory}/lbryum_version.txt"; then
echo "LBRYum version $lbryum_current_version is up to date"
else
tmp=$(mktemp -d)
cd $tmp
echo "Downloading LBRYum update"
git clone --depth 1 https://github.com/lbryio/lbryum.git &>/dev/null
cd lbryum
echo "Installing update"
sudo python setup.py install &>/dev/null
mkdir -p "$lbrynet_directory"
echo $lbryum_current_version > "${lbrynet_directory}/lbryum_version.txt"
echo "Cleaning up"
cd ../../
rm -rf $tmp
fi
else
tmp=$(mktemp -d)
cd $tmp
echo "Downloading LBRYum update"
git clone --depth 1 https://github.com/lbryio/lbryum.git &>/dev/null
cd lbryum
echo "Installing update"
sudo python setup.py install &>/dev/null
mkdir -p "$lbrynet_directory"
echo $lbryum_current_version > "${lbrynet_directory}/lbryum_version.txt"
echo "Cleaning up"
cd ../../ cd ../../
rm -rf $tmp rm -rf $tmp