commit
41a0a0c64c
5 changed files with 137 additions and 87 deletions
|
@ -1006,7 +1006,7 @@ class LBRYumWallet(LBRYWallet):
|
|||
return defer.succeed(Decimal(self.wallet.get_addr_received(address))/COIN)
|
||||
|
||||
def get_nametrie(self):
|
||||
cmd = known_commands['getnametrie']
|
||||
cmd = known_commands['getclaimtrie']
|
||||
func = getattr(self.cmd_runner, cmd.name)
|
||||
return threads.deferToThread(func)
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ from lbrynet.lbryfile.StreamDescriptor import LBRYFileStreamType
|
|||
from lbrynet.lbryfile.client.LBRYFileDownloader import LBRYFileSaverFactory, LBRYFileOpenerFactory
|
||||
from lbrynet.lbryfile.client.LBRYFileOptions import add_lbry_file_to_sd_identifier
|
||||
from lbrynet.lbrynet_daemon.LBRYDownloader import GetStream, FetcherDaemon
|
||||
# from lbrynet.lbrynet_daemon.LBRYOSXStatusBar import DaemonStatusBarApp
|
||||
from lbrynet.lbrynet_daemon.LBRYPublisher import Publisher
|
||||
from lbrynet.core.utils import generate_id
|
||||
from lbrynet.lbrynet_console.LBRYSettings import LBRYSettings
|
||||
|
@ -16,7 +15,7 @@ from lbrynet.conf import MIN_BLOB_DATA_PAYMENT_RATE, DEFAULT_MAX_SEARCH_RESULTS,
|
|||
from lbrynet.core.StreamDescriptor import StreamDescriptorIdentifier, download_sd_blob
|
||||
from lbrynet.core.Session import LBRYSession
|
||||
from lbrynet.core.PTCWallet import PTCWallet
|
||||
from lbrynet.core.LBRYcrdWallet import LBRYcrdWallet
|
||||
from lbrynet.core.LBRYcrdWallet import LBRYcrdWallet, LBRYumWallet
|
||||
from lbrynet.lbryfilemanager.LBRYFileManager import LBRYFileManager
|
||||
from lbrynet.lbryfile.LBRYFileMetadataManager import DBLBRYFileMetadataManager, TempLBRYFileMetadataManager
|
||||
from twisted.web import xmlrpc, server
|
||||
|
@ -26,9 +25,11 @@ from decimal import Decimal
|
|||
from StringIO import StringIO
|
||||
from zipfile import ZipFile
|
||||
from urllib import urlopen
|
||||
import os, sys, json, binascii, webbrowser, xmlrpclib, subprocess, logging
|
||||
|
||||
import os, sys, json, binascii, webbrowser, xmlrpclib, subprocess, logging, argparse
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
# logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
|
||||
# TODO add login credentials in a conf file
|
||||
|
@ -46,8 +47,8 @@ class LBRYDaemon(xmlrpc.XMLRPC):
|
|||
LBRYnet daemon
|
||||
"""
|
||||
|
||||
def setup(self):
|
||||
def _set_vars():
|
||||
def setup(self, wallet_type, check_for_updates):
|
||||
def _set_vars(wallet_type, check_for_updates):
|
||||
self.fetcher = None
|
||||
self.current_db_revision = 1
|
||||
self.run_server = True
|
||||
|
@ -57,7 +58,8 @@ class LBRYDaemon(xmlrpc.XMLRPC):
|
|||
self.db_dir = os.path.join(os.path.expanduser("~"), ".lbrynet")
|
||||
else:
|
||||
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.peer_port = 3333
|
||||
self.dht_node_port = 4444
|
||||
|
@ -93,10 +95,10 @@ class LBRYDaemon(xmlrpc.XMLRPC):
|
|||
self.lbry_file_metadata_manager = None
|
||||
self.lbry_file_manager = None
|
||||
self.settings = LBRYSettings(self.db_dir)
|
||||
self.wallet_type = "lbrycrd"
|
||||
self.wallet_type = wallet_type
|
||||
self.check_for_updates = check_for_updates
|
||||
self.lbrycrd_conf = os.path.join(self.wallet_dir, "lbrycrd.conf")
|
||||
self.autofetcher_conf = os.path.join(self.wallet_dir, "autofetcher.conf")
|
||||
self.files = []
|
||||
self.created_data_dir = False
|
||||
if not os.path.exists(self.db_dir):
|
||||
os.mkdir(self.db_dir)
|
||||
|
@ -117,11 +119,14 @@ class LBRYDaemon(xmlrpc.XMLRPC):
|
|||
else:
|
||||
print "Started LBRYnet daemon"
|
||||
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)
|
||||
|
||||
log.info('[' + str(datetime.now()) + '] Starting lbrynet-daemon')
|
||||
|
||||
d = defer.Deferred()
|
||||
d.addCallback(lambda _: _set_vars())
|
||||
d.addCallback(lambda _: _set_vars(wallet_type, check_for_updates))
|
||||
d.addCallback(lambda _: threads.deferToThread(self._setup_data_directory))
|
||||
d.addCallback(lambda _: self._check_db_migration())
|
||||
d.addCallback(lambda _: self._get_settings())
|
||||
|
@ -134,8 +139,8 @@ class LBRYDaemon(xmlrpc.XMLRPC):
|
|||
d.addCallback(lambda _: self._setup_query_handlers())
|
||||
d.addCallback(lambda _: self._setup_server())
|
||||
if sys.platform == "darwin":
|
||||
d.addCallback(lambda _: self._update())
|
||||
# d.addCallback(lambda _: self.status_app.run())
|
||||
d.addCallback(lambda _: self._update() if self.check_for_updates == "True" else defer.succeed(None))
|
||||
# d.addCallback(lambda _: defer.succeed(self.status_app.run()))
|
||||
d.addCallback(lambda _: self._setup_fetcher())
|
||||
d.addCallback(lambda _: _disp_startup())
|
||||
d.callback(None)
|
||||
|
@ -397,6 +402,8 @@ class LBRYDaemon(xmlrpc.XMLRPC):
|
|||
|
||||
def get_wallet():
|
||||
if self.wallet_type == "lbrycrd":
|
||||
print "Using lbrycrd wallet"
|
||||
log.info("Using lbrycrd wallet")
|
||||
lbrycrdd_path = None
|
||||
if self.start_lbrycrdd is True:
|
||||
lbrycrdd_path = self.lbrycrdd_path
|
||||
|
@ -404,8 +411,17 @@ class LBRYDaemon(xmlrpc.XMLRPC):
|
|||
lbrycrdd_path = self.default_lbrycrdd_path
|
||||
d = defer.succeed(LBRYcrdWallet(self.db_dir, wallet_dir=self.wallet_dir, wallet_conf=self.lbrycrd_conf,
|
||||
lbrycrdd_path=lbrycrdd_path))
|
||||
else:
|
||||
elif self.wallet_type == "lbryum":
|
||||
print "Using lbryum wallet"
|
||||
log.info("Using lbryum wallet")
|
||||
d = defer.succeed(LBRYumWallet(self.db_dir))
|
||||
elif self.wallet_type == "ptc":
|
||||
print "Using PTC wallet"
|
||||
log.info("Using PTC wallet")
|
||||
d = defer.succeed(PTCWallet(self.db_dir))
|
||||
else:
|
||||
d = defer.fail()
|
||||
|
||||
d.addCallback(lambda wallet: {"wallet": wallet})
|
||||
return d
|
||||
|
||||
|
@ -530,9 +546,11 @@ class LBRYDaemon(xmlrpc.XMLRPC):
|
|||
path = os.path.join(self.blobfile_dir, stream_hash)
|
||||
if os.path.isfile(path):
|
||||
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))
|
||||
else:
|
||||
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)
|
||||
|
||||
d = self._resolve_name(name)
|
||||
|
@ -578,8 +596,10 @@ class LBRYDaemon(xmlrpc.XMLRPC):
|
|||
def _check_est(d, name):
|
||||
if type(d.result) is float:
|
||||
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:
|
||||
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()
|
||||
return defer.succeed(None)
|
||||
|
||||
|
@ -636,6 +656,7 @@ class LBRYDaemon(xmlrpc.XMLRPC):
|
|||
|
||||
self.fetcher.start()
|
||||
print '[' + str(datetime.now()) + '] Start autofetcher'
|
||||
log.info('[' + str(datetime.now()) + '] Start autofetcher')
|
||||
return 'Started autofetching'
|
||||
|
||||
def xmlrpc_stop_fetcher(self):
|
||||
|
@ -645,6 +666,7 @@ class LBRYDaemon(xmlrpc.XMLRPC):
|
|||
|
||||
self.fetcher.stop()
|
||||
print '[' + str(datetime.now()) + '] Stop autofetcher'
|
||||
log.info('[' + str(datetime.now()) + '] Stop autofetcher')
|
||||
return 'Stopped autofetching'
|
||||
|
||||
def xmlrpc_fetcher_status(self):
|
||||
|
@ -669,6 +691,7 @@ class LBRYDaemon(xmlrpc.XMLRPC):
|
|||
"""
|
||||
|
||||
def _disp_shutdown():
|
||||
log.info('Shutting down lbrynet daemon')
|
||||
print 'Shutting down lbrynet daemon'
|
||||
|
||||
d = self._shutdown()
|
||||
|
@ -711,7 +734,6 @@ class LBRYDaemon(xmlrpc.XMLRPC):
|
|||
"""
|
||||
|
||||
def _disp(info):
|
||||
log.debug('[' + str(datetime.now()) + ']' + ' Resolved info: ' + str(info['stream_hash']))
|
||||
print '[' + str(datetime.now()) + ']' + ' Resolved info: ' + str(info['stream_hash'])
|
||||
return info
|
||||
|
||||
|
@ -813,13 +835,6 @@ class LBRYDaemon(xmlrpc.XMLRPC):
|
|||
@return:
|
||||
"""
|
||||
|
||||
#def _return_d(x):
|
||||
# d = defer.Deferred()
|
||||
# d.addCallback(lambda _: x)
|
||||
# d.callback(None)
|
||||
|
||||
# return d
|
||||
|
||||
def _clean(n):
|
||||
t = []
|
||||
for i in n:
|
||||
|
@ -861,9 +876,13 @@ class LBRYDaemon(xmlrpc.XMLRPC):
|
|||
|
||||
def _disp(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
|
||||
|
||||
print '[' + str(datetime.now()) + '] Search nametrie: ' + search
|
||||
log.info('[' + str(datetime.now()) + '] Search nametrie: ' + search)
|
||||
|
||||
d = self.session.wallet.get_nametrie()
|
||||
d.addCallback(lambda trie: [claim for claim in trie if claim['name'].startswith(search) and 'txid' in claim])
|
||||
|
@ -944,6 +963,9 @@ class LBRYDaemon(xmlrpc.XMLRPC):
|
|||
else:
|
||||
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)
|
||||
d = p.start(name, file_path, bid, title, description, thumbnail, key_fee, key_fee_address, content_license)
|
||||
|
||||
|
@ -981,6 +1003,15 @@ class LBRYDaemon(xmlrpc.XMLRPC):
|
|||
|
||||
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 _disp(x):
|
||||
# print x
|
||||
|
@ -1042,17 +1073,28 @@ class LBRYDaemon(xmlrpc.XMLRPC):
|
|||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Launch lbrynet-daemon")
|
||||
parser.add_argument("--wallet",
|
||||
help="lbrycrd or lbryum, default lbryum",
|
||||
type=str,
|
||||
default="lbryum")
|
||||
parser.add_argument("--update",
|
||||
help="True or false, default true",
|
||||
type=str,
|
||||
default="True")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
try:
|
||||
d = xmlrpclib.ServerProxy('http://localhost:7080')
|
||||
d.stop()
|
||||
daemon = xmlrpclib.ServerProxy("http://localhost:7080")
|
||||
daemon.stop()
|
||||
except:
|
||||
pass
|
||||
|
||||
daemon = LBRYDaemon()
|
||||
daemon.setup()
|
||||
daemon.setup(args.wallet, args.update)
|
||||
reactor.listenTCP(7080, server.Site(daemon))
|
||||
reactor.run()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
main()
|
|
@ -4,12 +4,11 @@ import xmlrpclib
|
|||
def main():
|
||||
daemon = xmlrpclib.ServerProxy("http://localhost:7080/")
|
||||
try:
|
||||
b = daemon.get_balance()
|
||||
is_running = True
|
||||
status = daemon.is_running()
|
||||
except:
|
||||
is_running = False
|
||||
status = False
|
||||
|
||||
if is_running:
|
||||
if status:
|
||||
daemon.stop()
|
||||
print "LBRYnet daemon stopped"
|
||||
else:
|
||||
|
|
|
@ -1,15 +1,25 @@
|
|||
import rumps
|
||||
import xmlrpclib
|
||||
import os
|
||||
import webbrowser
|
||||
|
||||
class DaemonStatusBarApp(rumps.App):
|
||||
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)
|
||||
self.menu = ["Quit"]
|
||||
self.menu = ["Open UI", "Quit"]
|
||||
|
||||
@rumps.clicked('Open UI')
|
||||
def get_ui(self):
|
||||
webbrowser.open("lbry://lbry")
|
||||
|
||||
@rumps.clicked('Quit')
|
||||
def clean_quit(self):
|
||||
d = xmlrpclib.ServerProxy('http://localhost:7080')
|
||||
d.stop()
|
||||
daemon = xmlrpclib.ServerProxy('http://localhost:7080')
|
||||
daemon.stop()
|
||||
rumps.quit_application()
|
||||
|
||||
def main():
|
||||
DaemonStatusBarApp().run()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -59,7 +59,7 @@ else
|
|||
fi
|
||||
|
||||
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
|
||||
tar xf six-1.9.0.tar.gz &>/dev/null
|
||||
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
|
||||
|
||||
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 development --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 development --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)
|
||||
|
||||
|
@ -83,15 +128,15 @@ if [ -d "$lbrynet_directory" ]; then
|
|||
|
||||
echo "Downloading LBRYnet update"
|
||||
|
||||
git clone --depth 1 https://github.com/lbryio/lbry.git &>/dev/null
|
||||
git clone -b development --depth 1 https://github.com/lbryio/lbry.git &>/dev/null
|
||||
cd lbry
|
||||
|
||||
echo "Installing update"
|
||||
echo "Installing update..."
|
||||
sudo python setup.py install &>/dev/null
|
||||
mkdir -p "$lbrynet_directory"
|
||||
echo $lbrynet_current_version > "${lbrynet_directory}/lbrynet_version.txt"
|
||||
|
||||
echo "Cleaning up"
|
||||
echo "Cleaning up..."
|
||||
|
||||
cd ../../
|
||||
rm -rf $tmp
|
||||
|
@ -100,63 +145,17 @@ if [ -d "$lbrynet_directory" ]; then
|
|||
tmp=$(mktemp -d)
|
||||
cd $tmp
|
||||
|
||||
echo "Downloading LBRYnet update"
|
||||
echo "Downloading LBRYnet..."
|
||||
|
||||
git clone --depth 1 https://github.com/lbryio/lbry.git &>/dev/null
|
||||
git clone -b development --depth 1 https://github.com/lbryio/lbry.git &>/dev/null
|
||||
cd lbry
|
||||
|
||||
echo "Installing update"
|
||||
echo "Installing..."
|
||||
sudo python setup.py install &>/dev/null
|
||||
mkdir -p "$lbrynet_directory"
|
||||
echo $lbrynet_current_version > "${lbrynet_directory}/lbrynet_version.txt"
|
||||
|
||||
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"
|
||||
echo "Cleaning up..."
|
||||
|
||||
cd ../../
|
||||
rm -rf $tmp
|
||||
|
|
Loading…
Reference in a new issue