forked from LBRYCommunity/lbry-sdk
clean up daemon imports and settings var name
This commit is contained in:
parent
f9fef3d586
commit
7f96e35b0e
1 changed files with 67 additions and 90 deletions
|
@ -10,7 +10,6 @@ import sys
|
|||
import base58
|
||||
import requests
|
||||
import simplejson as json
|
||||
|
||||
from urllib2 import urlopen
|
||||
from appdirs import user_data_dir
|
||||
from datetime import datetime
|
||||
|
@ -21,55 +20,34 @@ from twisted.internet.task import LoopingCall
|
|||
from txjsonrpc import jsonrpclib
|
||||
from jsonschema import ValidationError
|
||||
|
||||
from lbrynet import __version__ as lbrynet_version
|
||||
# TODO: importing this when internet is disabled raises a socket.gaierror
|
||||
from lbryum.version import LBRYUM_VERSION as lbryum_version
|
||||
|
||||
from lbrynet import __version__ as lbrynet_version
|
||||
from lbrynet import conf
|
||||
from lbrynet.conf import settings as lbrynet_settings
|
||||
from lbrynet import analytics
|
||||
from lbrynet import reflector
|
||||
from lbrynet.metadata.Metadata import Metadata, verify_name_characters
|
||||
from lbrynet import conf, reflector, analytics
|
||||
from lbrynet.metadata.Fee import FeeValidator
|
||||
from lbrynet.core import log_support
|
||||
from lbrynet.core import utils
|
||||
from lbrynet.core.utils import generate_id
|
||||
from lbrynet.core.StreamDescriptor import StreamDescriptorIdentifier, download_sd_blob, BlobStreamDescriptorReader
|
||||
from lbrynet.core.Session import Session
|
||||
from lbrynet.core.looping_call_manager import LoopingCallManager
|
||||
from lbrynet.core.server.BlobRequestHandler import BlobRequestHandlerFactory
|
||||
from lbrynet.core.server.ServerProtocol import ServerProtocolFactory
|
||||
from lbrynet.core.Error import InsufficientFundsError, InvalidNameError
|
||||
from lbrynet.core.PTCWallet import PTCWallet
|
||||
from lbrynet.core.Wallet import LBRYcrdWallet, LBRYumWallet
|
||||
from lbrynet.lbrynet_console.Settings import Settings
|
||||
from lbrynet.lbryfilemanager.EncryptedFileManager import EncryptedFileManager
|
||||
from lbrynet.lbryfile.StreamDescriptor import EncryptedFileStreamType
|
||||
from lbrynet.metadata.Metadata import Metadata, verify_name_characters
|
||||
from lbrynet.lbryfile.client.EncryptedFileDownloader import EncryptedFileSaverFactory, EncryptedFileOpenerFactory
|
||||
from lbrynet.lbryfile.client.EncryptedFileOptions import add_lbry_file_to_sd_identifier
|
||||
from lbrynet.lbryfile.EncryptedFileMetadataManager import DBEncryptedFileMetadataManager
|
||||
from lbrynet.lbryfile.EncryptedFileMetadataManager import TempEncryptedFileMetadataManager
|
||||
from lbrynet.lbryfile.StreamDescriptor import EncryptedFileStreamType
|
||||
from lbrynet.lbryfilemanager.EncryptedFileManager import EncryptedFileManager
|
||||
from lbrynet.lbrynet_console.Settings import Settings
|
||||
from lbrynet.lbrynet_daemon.UIManager import UIManager
|
||||
from lbrynet.lbrynet_daemon.Downloader import GetStream
|
||||
from lbrynet.lbrynet_daemon.Publisher import Publisher
|
||||
from lbrynet.lbrynet_daemon.ExchangeRateManager import ExchangeRateManager
|
||||
from lbrynet.lbrynet_daemon.Lighthouse import LighthouseClient
|
||||
from lbrynet.lbrynet_daemon.auth.server import AuthJSONRPCServer
|
||||
|
||||
from lbrynet.metadata.Metadata import Metadata, verify_name_characters
|
||||
from lbrynet.core import log_support
|
||||
from lbrynet.core import utils
|
||||
from lbrynet.core.utils import generate_id
|
||||
from lbrynet.lbrynet_console.Settings import Settings
|
||||
|
||||
from lbrynet.core.StreamDescriptor import StreamDescriptorIdentifier, download_sd_blob, BlobStreamDescriptorReader
|
||||
from lbrynet.core.Session import Session
|
||||
from lbrynet.core.PTCWallet import PTCWallet
|
||||
from lbrynet.core.Wallet import LBRYcrdWallet, LBRYumWallet
|
||||
from lbrynet.lbryfilemanager.EncryptedFileManager import EncryptedFileManager
|
||||
from lbrynet.lbryfile.EncryptedFileMetadataManager import DBEncryptedFileMetadataManager, TempEncryptedFileMetadataManager
|
||||
from lbrynet import reflector
|
||||
from lbrynet.core.looping_call_manager import LoopingCallManager
|
||||
from lbrynet.core.server.BlobRequestHandler import BlobRequestHandlerFactory
|
||||
from lbrynet.core.server.ServerProtocol import ServerProtocolFactory
|
||||
from lbrynet.core.Error import InsufficientFundsError, InvalidNameError
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
@ -222,7 +200,7 @@ class Daemon(AuthJSONRPCServer):
|
|||
"""
|
||||
|
||||
def __init__(self, root):
|
||||
AuthJSONRPCServer.__init__(self, lbrynet_settings.use_auth_http)
|
||||
AuthJSONRPCServer.__init__(self, conf.settings.use_auth_http)
|
||||
reactor.addSystemEventTrigger('before', 'shutdown', self._shutdown)
|
||||
|
||||
self.allowed_during_startup = [
|
||||
|
@ -232,38 +210,38 @@ class Daemon(AuthJSONRPCServer):
|
|||
'version', 'get_search_servers'
|
||||
]
|
||||
last_version = {'last_version': {'lbrynet': lbrynet_version, 'lbryum': lbryum_version}}
|
||||
lbrynet_settings.update(last_version)
|
||||
self.db_dir = lbrynet_settings.data_dir
|
||||
self.download_directory = lbrynet_settings.download_directory
|
||||
conf.settings.update(last_version)
|
||||
self.db_dir = conf.settings.data_dir
|
||||
self.download_directory = conf.settings.download_directory
|
||||
self.created_data_dir = False
|
||||
if not os.path.exists(self.db_dir):
|
||||
os.mkdir(self.db_dir)
|
||||
self.created_data_dir = True
|
||||
if lbrynet_settings.BLOBFILES_DIR == "blobfiles":
|
||||
if conf.settings.BLOBFILES_DIR == "blobfiles":
|
||||
self.blobfile_dir = os.path.join(self.db_dir, "blobfiles")
|
||||
else:
|
||||
log.info("Using non-default blobfiles directory: %s", lbrynet_settings.BLOBFILES_DIR)
|
||||
self.blobfile_dir = lbrynet_settings.BLOBFILES_DIR
|
||||
log.info("Using non-default blobfiles directory: %s", conf.settings.BLOBFILES_DIR)
|
||||
self.blobfile_dir = conf.settings.BLOBFILES_DIR
|
||||
|
||||
self.run_on_startup = lbrynet_settings.run_on_startup
|
||||
self.data_rate = lbrynet_settings.data_rate
|
||||
self.max_key_fee = lbrynet_settings.max_key_fee
|
||||
self.max_upload = lbrynet_settings.max_upload
|
||||
self.max_download = lbrynet_settings.max_download
|
||||
self.upload_log = lbrynet_settings.upload_log
|
||||
self.search_timeout = lbrynet_settings.search_timeout
|
||||
self.download_timeout = lbrynet_settings.download_timeout
|
||||
self.max_search_results = lbrynet_settings.max_search_results
|
||||
self.run_reflector_server = lbrynet_settings.run_reflector_server
|
||||
self.wallet_type = lbrynet_settings.wallet
|
||||
self.delete_blobs_on_remove = lbrynet_settings.delete_blobs_on_remove
|
||||
self.peer_port = lbrynet_settings.peer_port
|
||||
self.reflector_port = lbrynet_settings.reflector_port
|
||||
self.dht_node_port = lbrynet_settings.dht_node_port
|
||||
self.use_upnp = lbrynet_settings.use_upnp
|
||||
self.start_lbrycrdd = lbrynet_settings.start_lbrycrdd
|
||||
self.cache_time = lbrynet_settings.cache_time
|
||||
self.startup_scripts = lbrynet_settings.startup_scripts
|
||||
self.run_on_startup = conf.settings.run_on_startup
|
||||
self.data_rate = conf.settings.data_rate
|
||||
self.max_key_fee = conf.settings.max_key_fee
|
||||
self.max_upload = conf.settings.max_upload
|
||||
self.max_download = conf.settings.max_download
|
||||
self.upload_log = conf.settings.upload_log
|
||||
self.search_timeout = conf.settings.search_timeout
|
||||
self.download_timeout = conf.settings.download_timeout
|
||||
self.max_search_results = conf.settings.max_search_results
|
||||
self.run_reflector_server = conf.settings.run_reflector_server
|
||||
self.wallet_type = conf.settings.wallet
|
||||
self.delete_blobs_on_remove = conf.settings.delete_blobs_on_remove
|
||||
self.peer_port = conf.settings.peer_port
|
||||
self.reflector_port = conf.settings.reflector_port
|
||||
self.dht_node_port = conf.settings.dht_node_port
|
||||
self.use_upnp = conf.settings.use_upnp
|
||||
self.start_lbrycrdd = conf.settings.start_lbrycrdd
|
||||
self.cache_time = conf.settings.cache_time
|
||||
self.startup_scripts = conf.settings.startup_scripts
|
||||
|
||||
self.startup_status = STARTUP_STAGES[0]
|
||||
self.startup_message = None
|
||||
|
@ -275,11 +253,11 @@ class Daemon(AuthJSONRPCServer):
|
|||
self.ui_version = None
|
||||
self.ip = None
|
||||
self.first_run = None
|
||||
self.log_file = lbrynet_settings.get_log_filename()
|
||||
self.log_file = conf.settings.get_log_filename()
|
||||
self.current_db_revision = 1
|
||||
self.session = None
|
||||
self.uploaded_temp_files = []
|
||||
self._session_id = base58.b58encode(generate_id())
|
||||
self._session_id = base58.b58encode(utils.generate_id())
|
||||
# TODO: this should probably be passed into the daemon, or
|
||||
# possibly have the entire log upload functionality taken out
|
||||
# of the daemon, but I don't want to deal with that now
|
||||
|
@ -287,7 +265,7 @@ class Daemon(AuthJSONRPCServer):
|
|||
|
||||
self.analytics_manager = None
|
||||
self.lbryid = PENDING_LBRY_ID
|
||||
self.daemon_conf = lbrynet_settings.get_conf_filename()
|
||||
self.daemon_conf = conf.settings.get_conf_filename()
|
||||
|
||||
self.wallet_user = None
|
||||
self.wallet_password = None
|
||||
|
@ -321,7 +299,6 @@ class Daemon(AuthJSONRPCServer):
|
|||
parsed = jsonrpclib.loads(content)
|
||||
function_path = parsed.get("method")
|
||||
if self.wallet_type == "lbryum" and function_path in ['set_miner', 'get_miner_status']:
|
||||
log.warning("Mining commands are not available in lbryum")
|
||||
raise Exception("Command not available in lbryum")
|
||||
return True
|
||||
|
||||
|
@ -389,7 +366,7 @@ class Daemon(AuthJSONRPCServer):
|
|||
self.exchange_rate_manager.start()
|
||||
|
||||
d = defer.Deferred()
|
||||
if lbrynet_settings.host_ui:
|
||||
if conf.settings.host_ui:
|
||||
self.lbry_ui_manager.update_checker.start(1800, now=False)
|
||||
d.addCallback(lambda _: self.lbry_ui_manager.setup())
|
||||
d.addCallback(lambda _: self._initial_setup())
|
||||
|
@ -678,27 +655,27 @@ class Daemon(AuthJSONRPCServer):
|
|||
for key, setting_type in setting_types.iteritems():
|
||||
if key in settings:
|
||||
if isinstance(settings[key], setting_type):
|
||||
lbrynet_settings.update({key: settings[key]})
|
||||
conf.settings.update({key: settings[key]})
|
||||
elif key == "max_key_fee" and isinstance(FeeValidator(settings[key]).amount, setting_type):
|
||||
lbrynet_settings.update({key: settings[key]})
|
||||
conf.settings.update({key: settings[key]})
|
||||
else:
|
||||
try:
|
||||
converted = setting_type(settings[key])
|
||||
lbrynet_settings.update({key: converted})
|
||||
conf.settings.update({key: converted})
|
||||
except Exception as err:
|
||||
log.warning(err.message)
|
||||
log.warning("error converting setting '%s' to type %s", key, setting_type)
|
||||
|
||||
self.run_on_startup = lbrynet_settings.run_on_startup
|
||||
self.data_rate = lbrynet_settings.data_rate
|
||||
self.max_key_fee = lbrynet_settings.max_key_fee
|
||||
self.download_directory = lbrynet_settings.download_directory
|
||||
self.max_upload = lbrynet_settings.max_upload
|
||||
self.max_download = lbrynet_settings.max_download
|
||||
self.upload_log = lbrynet_settings.upload_log
|
||||
self.download_timeout = lbrynet_settings.download_timeout
|
||||
self.search_timeout = lbrynet_settings.search_timeout
|
||||
self.cache_time = lbrynet_settings.cache_time
|
||||
self.run_on_startup = conf.settings.run_on_startup
|
||||
self.data_rate = conf.settings.data_rate
|
||||
self.max_key_fee = conf.settings.max_key_fee
|
||||
self.download_directory = conf.settings.download_directory
|
||||
self.max_upload = conf.settings.max_upload
|
||||
self.max_download = conf.settings.max_download
|
||||
self.upload_log = conf.settings.upload_log
|
||||
self.download_timeout = conf.settings.download_timeout
|
||||
self.search_timeout = conf.settings.search_timeout
|
||||
self.cache_time = conf.settings.cache_time
|
||||
|
||||
return defer.succeed(True)
|
||||
|
||||
|
@ -755,7 +732,7 @@ class Daemon(AuthJSONRPCServer):
|
|||
self.lbryid = lbryid
|
||||
|
||||
def _make_set_and_save_lbryid(self):
|
||||
self.lbryid = generate_id()
|
||||
self.lbryid = utils.generate_id()
|
||||
log.info("Generated new LBRY ID: " + base58.b58encode(self.lbryid))
|
||||
d = self.settings.save_lbryid(self.lbryid)
|
||||
return d
|
||||
|
@ -797,7 +774,7 @@ class Daemon(AuthJSONRPCServer):
|
|||
def get_default_data_rate():
|
||||
d = self.settings.get_default_data_payment_rate()
|
||||
d.addCallback(lambda rate: {"default_data_payment_rate": rate if rate is not None else
|
||||
lbrynet_settings.data_rate})
|
||||
conf.settings.data_rate})
|
||||
return d
|
||||
|
||||
def get_wallet():
|
||||
|
@ -811,8 +788,8 @@ class Daemon(AuthJSONRPCServer):
|
|||
elif self.wallet_type == "lbryum":
|
||||
log.info("Using lbryum wallet")
|
||||
config = {'auto-connect': True}
|
||||
if lbrynet_settings.lbryum_wallet_dir:
|
||||
config['lbryum_path'] = lbrynet_settings.lbryum_wallet_dir
|
||||
if conf.settings.lbryum_wallet_dir:
|
||||
config['lbryum_path'] = conf.settings.lbryum_wallet_dir
|
||||
d = defer.succeed(LBRYumWallet(self.db_dir, config))
|
||||
elif self.wallet_type == "ptc":
|
||||
log.info("Using PTC wallet")
|
||||
|
@ -835,7 +812,7 @@ class Daemon(AuthJSONRPCServer):
|
|||
def create_session(results):
|
||||
self.session = Session(results['default_data_payment_rate'], db_dir=self.db_dir, lbryid=self.lbryid,
|
||||
blob_dir=self.blobfile_dir, dht_node_port=self.dht_node_port,
|
||||
known_dht_nodes=lbrynet_settings.known_dht_nodes, peer_port=self.peer_port,
|
||||
known_dht_nodes=conf.settings.known_dht_nodes, peer_port=self.peer_port,
|
||||
use_upnp=self.use_upnp, wallet=results['wallet'])
|
||||
self.startup_status = STARTUP_STAGES[2]
|
||||
|
||||
|
@ -857,7 +834,7 @@ class Daemon(AuthJSONRPCServer):
|
|||
self.sd_identifier.add_stream_downloader_factory(EncryptedFileStreamType, file_opener_factory)
|
||||
return defer.succeed(None)
|
||||
|
||||
def _download_sd_blob(self, sd_hash, timeout=lbrynet_settings.sd_download_timeout):
|
||||
def _download_sd_blob(self, sd_hash, timeout=conf.settings.sd_download_timeout):
|
||||
def cb(result):
|
||||
if not r.called:
|
||||
r.callback(result)
|
||||
|
@ -875,7 +852,7 @@ class Daemon(AuthJSONRPCServer):
|
|||
|
||||
return r
|
||||
|
||||
def _download_name(self, name, timeout=lbrynet_settings.download_timeout, download_directory=None,
|
||||
def _download_name(self, name, timeout=conf.settings.download_timeout, download_directory=None,
|
||||
file_name=None, stream_info=None, wait_for_write=True):
|
||||
"""
|
||||
Add a lbry file to the file manager, start the download, and return the new lbry file.
|
||||
|
@ -1030,7 +1007,7 @@ class Daemon(AuthJSONRPCServer):
|
|||
|
||||
log.info("Reflecting stream: %s" % stream_hash)
|
||||
|
||||
reflector_server = random.choice(lbrynet_settings.reflector_servers)
|
||||
reflector_server = random.choice(conf.settings.reflector_servers)
|
||||
reflector_address, reflector_port = reflector_server[0], reflector_server[1]
|
||||
log.info("Start reflector client")
|
||||
factory = reflector.ClientFactory(
|
||||
|
@ -1049,7 +1026,7 @@ class Daemon(AuthJSONRPCServer):
|
|||
|
||||
log.info("Reflecting %i blobs" % len(blob_hashes))
|
||||
|
||||
reflector_server = random.choice(lbrynet_settings.reflector_servers)
|
||||
reflector_server = random.choice(conf.settings.reflector_servers)
|
||||
reflector_address, reflector_port = reflector_server[0], reflector_server[1]
|
||||
log.info("Start reflector client")
|
||||
factory = reflector.BlobClientFactory(
|
||||
|
@ -1072,7 +1049,7 @@ class Daemon(AuthJSONRPCServer):
|
|||
log.info("Removing one time startup scripts")
|
||||
remaining_scripts = [s for s in self.startup_scripts if 'run_once' not in s.keys()]
|
||||
startup_scripts = self.startup_scripts
|
||||
self.startup_scripts = lbrynet_settings.startup_scripts = remaining_scripts
|
||||
self.startup_scripts = conf.settings.startup_scripts = remaining_scripts
|
||||
conf.save_settings()
|
||||
|
||||
for script in startup_scripts:
|
||||
|
@ -1251,7 +1228,7 @@ class Daemon(AuthJSONRPCServer):
|
|||
"""
|
||||
|
||||
log.info("Get daemon settings")
|
||||
return self._render_response(lbrynet_settings.__dict__, OK_CODE)
|
||||
return self._render_response(conf.settings.__dict__, OK_CODE)
|
||||
|
||||
@AuthJSONRPCServer.auth_required
|
||||
def jsonrpc_set_settings(self, p):
|
||||
|
@ -1272,12 +1249,12 @@ class Daemon(AuthJSONRPCServer):
|
|||
"""
|
||||
|
||||
def _log_settings_change():
|
||||
log.info("Set daemon settings to " + json.dumps(lbrynet_settings.configurable_settings))
|
||||
log.info("Set daemon settings to " + json.dumps(conf.settings.configurable_settings))
|
||||
|
||||
d = self._update_settings(p)
|
||||
d.addErrback(lambda err: log.info(err.getTraceback()))
|
||||
d.addCallback(lambda _: _log_settings_change())
|
||||
d.addCallback(lambda _: self._render_response(lbrynet_settings.configurable_settings, OK_CODE))
|
||||
d.addCallback(lambda _: self._render_response(conf.settings.configurable_settings, OK_CODE))
|
||||
|
||||
return d
|
||||
|
||||
|
@ -2036,7 +2013,7 @@ class Daemon(AuthJSONRPCServer):
|
|||
sd blob, dict
|
||||
"""
|
||||
sd_hash = p[FileID.SD_HASH]
|
||||
timeout = p.get('timeout', lbrynet_settings.sd_download_timeout)
|
||||
timeout = p.get('timeout', conf.settings.sd_download_timeout)
|
||||
d = self._download_sd_blob(sd_hash, timeout)
|
||||
d.addCallbacks(
|
||||
lambda r: self._render_response(r, OK_CODE),
|
||||
|
@ -2401,7 +2378,7 @@ def get_darwin_lbrycrdd_path():
|
|||
|
||||
|
||||
class _DownloadNameHelper(object):
|
||||
def __init__(self, daemon, name, timeout=lbrynet_settings.download_timeout, download_directory=None,
|
||||
def __init__(self, daemon, name, timeout=conf.settings.download_timeout, download_directory=None,
|
||||
file_name=None, wait_for_write=True):
|
||||
self.daemon = daemon
|
||||
self.name = name
|
||||
|
|
Loading…
Reference in a new issue