Merge pull request #8 from jackrobison/master
Fix daemon paths and add settings
This commit is contained in:
commit
e906564f70
2 changed files with 39 additions and 9 deletions
|
@ -16,6 +16,7 @@ from twisted.internet import defer, threads, reactor
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -42,9 +43,13 @@ class LBRYDaemon(xmlrpc.XMLRPC):
|
||||||
from lbrynet.winhelpers.knownpaths import get_path, FOLDERID, UserHandle
|
from lbrynet.winhelpers.knownpaths import get_path, FOLDERID, UserHandle
|
||||||
self.download_directory = get_path(FOLDERID.Downloads, UserHandle.current)
|
self.download_directory = get_path(FOLDERID.Downloads, UserHandle.current)
|
||||||
self.wallet_dir = os.path.join(get_path(FOLDERID.RoamingAppData, UserHandle.current), "lbrycrd")
|
self.wallet_dir = os.path.join(get_path(FOLDERID.RoamingAppData, UserHandle.current), "lbrycrd")
|
||||||
else:
|
elif sys.platform == "darwin":
|
||||||
self.download_directory = os.path.join(os.path.expanduser("~"), 'Downloads')
|
self.download_directory = os.path.join(os.path.expanduser("~"), 'Downloads')
|
||||||
|
self.wallet_dir = os.path.join(os.path.expanduser("~"), "Library/Application Support/lbrycrd")
|
||||||
|
else:
|
||||||
self.wallet_dir = os.path.join(os.path.expanduser("~"), ".lbrycrd")
|
self.wallet_dir = os.path.join(os.path.expanduser("~"), ".lbrycrd")
|
||||||
|
self.download_directory = os.path.join(os.path.expanduser("~"), 'Downloads')
|
||||||
|
|
||||||
self.wallet_conf = os.path.join(self.wallet_dir, "lbrycrd.conf")
|
self.wallet_conf = os.path.join(self.wallet_dir, "lbrycrd.conf")
|
||||||
self.wallet_user = None
|
self.wallet_user = None
|
||||||
self.wallet_password = None
|
self.wallet_password = None
|
||||||
|
@ -66,15 +71,17 @@ 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 = "lbrycrd"
|
self.wallet_type = "lbrycrd"
|
||||||
self.lbrycrd_dir = os.path.join(os.path.expanduser("~"), ".lbrycrd")
|
self.lbrycrd_conf = os.path.join(self.wallet_dir, "lbrycrd.conf")
|
||||||
self.lbrycrd_conf = os.path.join(self.lbrycrd_dir, "lbrycrd.conf")
|
self.autofetcher_conf = os.path.join(self.wallet_dir, "autofetcher.conf")
|
||||||
self.autofetcher_conf = os.path.join(self.lbrycrd_dir, "autofetcher.conf")
|
|
||||||
self.rpc_conn = None
|
self.rpc_conn = None
|
||||||
self.files = []
|
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)
|
||||||
self.created_data_dir = True
|
self.created_data_dir = True
|
||||||
|
self.session_settings = None
|
||||||
|
self.data_rate = 0.5
|
||||||
|
self.max_key_fee = 100.0
|
||||||
return defer.succeed(None)
|
return defer.succeed(None)
|
||||||
|
|
||||||
d = defer.Deferred()
|
d = defer.Deferred()
|
||||||
|
@ -93,6 +100,10 @@ class LBRYDaemon(xmlrpc.XMLRPC):
|
||||||
|
|
||||||
return defer.succeed(None)
|
return defer.succeed(None)
|
||||||
|
|
||||||
|
def _update_settings(self):
|
||||||
|
self.data_rate = self.session_settings['data_rate']
|
||||||
|
self.max_key_fee = self.session_settings['max_key_fee']
|
||||||
|
|
||||||
def _setup_fetcher(self):
|
def _setup_fetcher(self):
|
||||||
self.fetcher = FetcherDaemon(self.session, self.lbry_file_manager, self.lbry_file_metadata_manager,
|
self.fetcher = FetcherDaemon(self.session, self.lbry_file_manager, self.lbry_file_metadata_manager,
|
||||||
self.session.wallet, self.sd_identifier, self.autofetcher_conf)
|
self.session.wallet, self.sd_identifier, self.autofetcher_conf)
|
||||||
|
@ -177,7 +188,7 @@ class LBRYDaemon(xmlrpc.XMLRPC):
|
||||||
lbrycrdd_path = self.lbrycrdd_path
|
lbrycrdd_path = self.lbrycrdd_path
|
||||||
if not lbrycrdd_path:
|
if not lbrycrdd_path:
|
||||||
lbrycrdd_path = self.default_lbrycrdd_path
|
lbrycrdd_path = self.default_lbrycrdd_path
|
||||||
d = defer.succeed(LBRYcrdWallet(self.db_dir, wallet_dir=self.lbrycrd_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=lbrycrdd_path))
|
||||||
else:
|
else:
|
||||||
d = defer.succeed(PTCWallet(self.db_dir))
|
d = defer.succeed(PTCWallet(self.db_dir))
|
||||||
|
@ -264,7 +275,8 @@ class LBRYDaemon(xmlrpc.XMLRPC):
|
||||||
log.debug('[' + str(datetime.now()) + ']' + ' Downloading: ' + str(stream.stream_hash))
|
log.debug('[' + str(datetime.now()) + ']' + ' Downloading: ' + str(stream.stream_hash))
|
||||||
return defer.succeed(None)
|
return defer.succeed(None)
|
||||||
|
|
||||||
stream = GetStream(self.sd_identifier, self.session, self.session.wallet, self.lbry_file_manager, 25.0)
|
stream = GetStream(self.sd_identifier, self.session, self.session.wallet, self.lbry_file_manager,
|
||||||
|
max_key_fee=self.max_key_fee, data_rate=self.data_rate)
|
||||||
self.downloads.append(stream)
|
self.downloads.append(stream)
|
||||||
|
|
||||||
d = self.session.wallet.get_stream_info_for_name(name)
|
d = self.session.wallet.get_stream_info_for_name(name)
|
||||||
|
@ -302,6 +314,21 @@ class LBRYDaemon(xmlrpc.XMLRPC):
|
||||||
d.callback(None)
|
d.callback(None)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
def xmlrpc_get_settings(self):
|
||||||
|
"""
|
||||||
|
Get LBRY payment settings
|
||||||
|
"""
|
||||||
|
if not self.session_settings:
|
||||||
|
self.session_settings = {'data_rate': self.data_rate, 'max_key_fee': self.max_key_fee}
|
||||||
|
|
||||||
|
return self.session_settings
|
||||||
|
|
||||||
|
def xmlrpc_set_settings(self, settings):
|
||||||
|
self.session_settings = settings
|
||||||
|
self._update_settings()
|
||||||
|
|
||||||
|
return 'Set'
|
||||||
|
|
||||||
def xmlrpc_start_fetcher(self):
|
def xmlrpc_start_fetcher(self):
|
||||||
"""
|
"""
|
||||||
Start autofetcher
|
Start autofetcher
|
||||||
|
@ -400,7 +427,9 @@ class LBRYDaemon(xmlrpc.XMLRPC):
|
||||||
log.debug('[' + str(datetime.now()) + ']' + ' Downloading: ' + str(stream.stream_hash))
|
log.debug('[' + str(datetime.now()) + ']' + ' Downloading: ' + str(stream.stream_hash))
|
||||||
return defer.succeed(None)
|
return defer.succeed(None)
|
||||||
|
|
||||||
stream = GetStream(self.sd_identifier, self.session, self.session.wallet, self.lbry_file_manager, 25.0)
|
stream = GetStream(self.sd_identifier, self.session, self.session.wallet, self.lbry_file_manager,
|
||||||
|
max_key_fee=self.max_key_fee, data_rate=self.data_rate)
|
||||||
|
|
||||||
self.downloads.append(stream)
|
self.downloads.append(stream)
|
||||||
|
|
||||||
d = self.session.wallet.get_stream_info_for_name(name)
|
d = self.session.wallet.get_stream_info_for_name(name)
|
||||||
|
|
|
@ -12,7 +12,7 @@ log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class GetStream(object):
|
class GetStream(object):
|
||||||
def __init__(self, sd_identifier, session, wallet, lbry_file_manager, max_key_fee, pay_key=True):
|
def __init__(self, sd_identifier, session, wallet, lbry_file_manager, max_key_fee, pay_key=True, data_rate=0.5):
|
||||||
self.finished_deferred = defer.Deferred(None)
|
self.finished_deferred = defer.Deferred(None)
|
||||||
self.wallet = wallet
|
self.wallet = wallet
|
||||||
self.resolved_name = None
|
self.resolved_name = None
|
||||||
|
@ -36,6 +36,7 @@ class GetStream(object):
|
||||||
self.stream_info = None
|
self.stream_info = None
|
||||||
self.stream_info_manager = None
|
self.stream_info_manager = None
|
||||||
self.downloader = None
|
self.downloader = None
|
||||||
|
self.data_rate = data_rate
|
||||||
self.pay_key = pay_key
|
self.pay_key = pay_key
|
||||||
|
|
||||||
def start(self, stream_info):
|
def start(self, stream_info):
|
||||||
|
@ -133,7 +134,7 @@ class GetStream(object):
|
||||||
self.downloader.file_name)
|
self.downloader.file_name)
|
||||||
return self.downloader
|
return self.downloader
|
||||||
|
|
||||||
self.downloader = self.factory.make_downloader(self.metadata, [0.5, True], self.payment_rate_manager)
|
self.downloader = self.factory.make_downloader(self.metadata, [self.data_rate, True], self.payment_rate_manager)
|
||||||
self.downloader.addCallback(_set_downloader)
|
self.downloader.addCallback(_set_downloader)
|
||||||
return defer.succeed(self.downloader)
|
return defer.succeed(self.downloader)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue