Replace settings with conf.settings

In the next commit I change conf.settings to be initialized
at runtime instead of load time and so any import of
`from lbrynet.conf import settings` will be and stay None if
it happens before the initialization.
This commit is contained in:
Job Evers-Meltzer 2016-12-21 11:55:43 -08:00
parent 26bc6d05a0
commit 39b2e44492
35 changed files with 149 additions and 134 deletions

View file

@ -5,7 +5,7 @@ import logging
from requests import auth
from requests_futures import sessions
from lbrynet.conf import settings
from lbrynet import conf
from lbrynet.analytics import utils
@ -83,6 +83,6 @@ class Api(object):
session = sessions.FuturesSession()
return cls(
session,
settings.ANALYTICS_ENDPOINT,
utils.deobfuscate(settings.ANALYTICS_TOKEN)
conf.settings.ANALYTICS_ENDPOINT,
utils.deobfuscate(conf.settings.ANALYTICS_TOKEN)
)

View file

@ -4,7 +4,7 @@ from twisted.internet import defer
from twisted.internet import task
from lbrynet.core.system_info import get_platform
from lbrynet.conf import settings
from lbrynet import conf
import constants
from api import Api

View file

@ -11,6 +11,9 @@ import envparse
LBRYCRD_WALLET = 'lbrycrd'
LBRYUM_WALLET = 'lbryum'
PTC_WALLET = 'ptc'
PROTOCOL_PREFIX = "lbry"
APP_NAME = "LBRY"
log = logging.getLogger(__name__)
@ -42,6 +45,9 @@ else:
default_lbryum_dir = os.path.join(os.path.expanduser("~"), ".lbryum")
ICON_PATH = "icons" if platform is WINDOWS else "app.icns"
class Settings(object):
"""A collection of configuration settings"""
__fixed = []
@ -218,9 +224,9 @@ class ApplicationSettings(Settings):
self.LOG_POST_URL = "https://lbry.io/log-upload"
self.CRYPTSD_FILE_EXTENSION = ".cryptsd"
self.API_ADDRESS = "lbryapi"
self.ICON_PATH = "icons" if platform is WINDOWS else "app.icns"
self.APP_NAME = "LBRY"
self.PROTOCOL_PREFIX = "lbry"
self.ICON_PATH = ICON_PATH
self.APP_NAME = APP_NAME
self.PROTOCOL_PREFIX = PROTOCOL_PREFIX
self.WALLET_TYPES = [LBRYUM_WALLET, LBRYCRD_WALLET]
self.SOURCE_TYPES = ['lbry_sd_hash', 'url', 'btih']
self.CURRENCIES = {

View file

@ -8,7 +8,7 @@ from twisted.internet import interfaces, defer, threads
from twisted.protocols.basic import FileSender
from twisted.python.failure import Failure
from zope.interface import implements
from lbrynet.conf import settings
from lbrynet import conf
from lbrynet.core.Error import DownloadCanceledError, InvalidDataError
from lbrynet.core.cryptoutils import get_lbry_hash_obj
@ -89,7 +89,7 @@ class HashBlob(object):
def set_length(self, length):
if self.length is not None and length == self.length:
return True
if self.length is None and 0 <= length <= settings.BLOB_SIZE:
if self.length is None and 0 <= length <= conf.settings.BLOB_SIZE:
self.length = length
return True
log.warning("Got an invalid length. Previous length: %s, Invalid length: %s",

View file

@ -1,12 +1,13 @@
from lbrynet.core.Strategy import get_default_strategy
from lbrynet.conf import settings
from lbrynet import conf
from decimal import Decimal
class BasePaymentRateManager(object):
def __init__(self, rate=settings.data_rate, info_rate=settings.min_info_rate):
self.min_blob_data_payment_rate = rate
self.min_blob_info_payment_rate = info_rate
def __init__(self, rate=None, info_rate=None):
self.min_blob_data_payment_rate = rate if rate is not None else conf.settings.data_rate
self.min_blob_info_payment_rate = (
info_rate if info_rate is not None else conf.settings.min_info_rate)
class PaymentRateManager(object):
@ -36,7 +37,7 @@ class PaymentRateManager(object):
class NegotiatedPaymentRateManager(object):
def __init__(self, base, availability_tracker, generous=settings.is_generous_host):
def __init__(self, base, availability_tracker, generous=None):
"""
@param base: a BasePaymentRateManager
@param availability_tracker: a BlobAvailabilityTracker
@ -46,7 +47,7 @@ class NegotiatedPaymentRateManager(object):
self.base = base
self.points_paid = 0.0
self.blob_tracker = availability_tracker
self.generous = generous
self.generous = generous if generous is not None else conf.settings.is_generous_host
self.strategy = get_default_strategy(self.blob_tracker,
base_price=self.base.min_blob_data_payment_rate,
is_generous=generous)

View file

@ -2,7 +2,7 @@ from zope.interface import implementer
from decimal import Decimal
from lbrynet.interfaces import IBlobPriceModel
from lbrynet.conf import settings
from lbrynet import conf
def get_default_price_model(blob_tracker, base_price, **kwargs):
@ -22,8 +22,9 @@ class MeanAvailabilityWeightedPrice(object):
"""
implementer(IBlobPriceModel)
def __init__(self, tracker, base_price=settings.data_rate, alpha=1.0):
def __init__(self, tracker, base_price=None, alpha=1.0):
self.blob_tracker = tracker
base_price = base_price if base_price is not None else conf.settings.data_rate
self.base_price = Decimal(base_price)
self.alpha = Decimal(alpha)

View file

@ -1,6 +1,6 @@
from zope.interface import implementer
from decimal import Decimal
from lbrynet.conf import settings
from lbrynet import conf
from lbrynet.interfaces import INegotiationStrategy
from lbrynet.core.Offer import Offer
from lbrynet.core.PriceModel import MeanAvailabilityWeightedPrice
@ -16,9 +16,10 @@ class Strategy(object):
"""
implementer(INegotiationStrategy)
def __init__(self, price_model, max_rate, min_rate, is_generous=settings.is_generous_host):
def __init__(self, price_model, max_rate, min_rate, is_generous=None):
self.price_model = price_model
self.is_generous = is_generous
self.is_generous = (
is_generous if is_generous is not None else conf.settings.is_generous_host)
self.accepted_offers = {}
self.pending_sent_offers = {}
self.offers_sent = {}
@ -104,7 +105,7 @@ class BasicAvailabilityWeightedStrategy(Strategy):
def __init__(self, blob_tracker, acceleration=1.25,
deceleration=0.9, max_rate=None,
min_rate=0.0,
is_generous=settings.is_generous_host,
is_generous=None,
base_price=0.0001, alpha=1.0):
price_model = MeanAvailabilityWeightedPrice(
blob_tracker, base_price=base_price, alpha=alpha)

View file

@ -4,7 +4,7 @@ from decimal import Decimal
from twisted.internet import error, defer
from twisted.internet.protocol import Protocol, ClientFactory
from twisted.python import failure
from lbrynet.conf import settings
from lbrynet import conf
from lbrynet.core.Error import ConnectionClosedBeforeResponseError, NoResponseError
from lbrynet.core.Error import DownloadCanceledError, MisbehavingPeerError
from lbrynet.core.Error import RequestCanceledError
@ -48,7 +48,7 @@ class ClientProtocol(Protocol):
self._blob_download_request.write(data)
else:
self._response_buff += data
if len(self._response_buff) > settings.MAX_RESPONSE_INFO_SIZE:
if len(self._response_buff) > conf.settings.MAX_RESPONSE_INFO_SIZE:
log.warning("Response is too large. Size %s", len(self._response_buff))
self.transport.loseConnection()
response, extra_data = self._get_valid_response(self._response_buff)

View file

@ -1,4 +1,4 @@
from lbrynet.conf import settings
from lbrynet import conf
class ClientRequest(object):
@ -17,7 +17,7 @@ class ClientBlobRequest(ClientPaidRequest):
def __init__(self, request_dict, response_identifier, write_func, finished_deferred,
cancel_func, blob):
if blob.length is None:
max_pay_units = settings.BLOB_SIZE
max_pay_units = conf.settings.BLOB_SIZE
else:
max_pay_units = blob.length
ClientPaidRequest.__init__(self, request_dict, response_identifier, max_pay_units)

View file

@ -2,7 +2,7 @@ import logging
from twisted.internet import defer
from zope.interface import implements
from lbrynet import interfaces
from lbrynet.conf import settings
from lbrynet import conf
from lbrynet.core.client.ClientProtocol import ClientProtocolFactory
from lbrynet.core.Error import InsufficientFundsError
@ -186,7 +186,7 @@ class ConnectionManager(object):
log.debug("Couldn't find a good peer to connect to")
return None
if len(self._peer_connections) < settings.max_connections_per_stream:
if len(self._peer_connections) < conf.settings.max_connections_per_stream:
ordered_request_creators = self._rank_request_creator_connections()
d = get_new_peers(ordered_request_creators)
d.addCallback(pick_best_peer)

View file

@ -12,7 +12,7 @@ import requests
from requests_futures.sessions import FuturesSession
import lbrynet
from lbrynet.conf import settings
from lbrynet import conf
from lbrynet.core import utils
####
@ -130,7 +130,7 @@ def configure_file_handler(file_name, **kwargs):
def get_loggly_url(token=None, version=None):
token = token or utils.deobfuscate(settings.LOGGLY_TOKEN)
token = token or utils.deobfuscate(conf.settings.LOGGLY_TOKEN)
version = version or lbrynet.__version__
return LOGGLY_URL.format(token=token, tag='lbrynet-' + version)
@ -304,7 +304,7 @@ class LogUploader(object):
'type': self.get_type(log_type),
'log': log_contents
}
requests.post(settings.LOG_POST_URL, params)
requests.post(conf.settings.LOG_POST_URL, params)
def log_contents(self, exclude_previous):
with open(self.log_file) as f:

View file

@ -1,7 +1,7 @@
import binascii
import logging
from Crypto.Cipher import AES
from lbrynet.conf import settings
from lbrynet import conf
from lbrynet.core.BlobInfo import BlobInfo
@ -66,7 +66,7 @@ class CryptStreamBlobMaker(object):
self.length = 0
def write(self, data):
max_bytes_to_write = settings.BLOB_SIZE - self.length - 1
max_bytes_to_write = conf.settings.BLOB_SIZE - self.length - 1
done = False
if max_bytes_to_write <= len(data):
num_bytes_to_write = max_bytes_to_write

View file

@ -7,7 +7,7 @@ import logging
import os
from lbrynet.core.StreamDescriptor import PlainStreamDescriptorWriter
from lbrynet.cryptstream.CryptStreamCreator import CryptStreamCreator
from lbrynet.conf import settings
from lbrynet import conf
from lbrynet.lbryfile.StreamDescriptor import get_sd_info
from lbrynet.core.cryptoutils import get_lbry_hash_obj
from twisted.protocols.basic import FileSender
@ -127,7 +127,7 @@ def create_lbry_file(session, lbry_file_manager, file_name, file_handle, key=Non
def make_stream_desc_file(stream_hash):
log.debug("creating the stream descriptor file")
descriptor_file_path = os.path.join(
session.db_dir, file_name + settings.CRYPTSD_FILE_EXTENSION)
session.db_dir, file_name + conf.settings.CRYPTSD_FILE_EXTENSION)
descriptor_writer = PlainStreamDescriptorWriter(descriptor_file_path)
d = get_sd_info(lbry_file_manager.stream_info_manager, stream_hash, True)

View file

@ -15,7 +15,7 @@ from lbrynet.lbryfilemanager.EncryptedFileStatusReport import EncryptedFileStatu
from lbrynet.interfaces import IStreamDownloaderFactory
from lbrynet.lbryfile.StreamDescriptor import save_sd_info
from lbrynet.reflector import reupload
from lbrynet.conf import settings
from lbrynet import conf
log = logging.getLogger(__name__)
@ -91,9 +91,9 @@ class ManagedEncryptedFileDownloader(EncryptedFileSaver):
return d
def _reupload(self):
if not settings.reflector_reupload:
if not conf.settings.reflector_reupload:
return
reflector_server = random.choice(settings.reflector_servers)
reflector_server = random.choice(conf.settings.reflector_servers)
return reupload.check_and_restore_availability(self, reflector_server)
def stop(self, err=None, change_status=True):

View file

@ -7,7 +7,7 @@ from lbrynet.core.cryptoutils import get_lbry_hash_obj, get_pub_key, sign_with_p
from Crypto import Random
import binascii
import logging
from lbrynet.conf import settings
from lbrynet import conf
from twisted.internet import interfaces, defer
from twisted.protocols.basic import FileSender
from zope.interface import implements
@ -24,7 +24,7 @@ class LiveStreamCreator(CryptStreamCreator):
self.stream_info_manager = stream_info_manager
self.delete_after_num = delete_after_num
self.secret_pass_phrase = secret_pass_phrase
self.file_extension = settings.CRYPTSD_FILE_EXTENSION
self.file_extension = conf.settings.CRYPTSD_FILE_EXTENSION
self.finished_blob_hashes = {}
def _save_stream(self):

View file

@ -4,7 +4,7 @@ import logging
from zope.interface import implements
from twisted.internet import defer
from twisted.python.failure import Failure
from lbrynet.conf import settings
from lbrynet import conf
from lbrynet.core.client.ClientRequest import ClientRequest, ClientPaidRequest
from lbrynet.lbrylive.LiveBlob import LiveBlobInfo
from lbrynet.core.cryptoutils import get_lbry_hash_obj, verify_signature
@ -137,7 +137,7 @@ class LiveStreamMetadataHandler(object):
if count is not None:
further_blobs_request['count'] = count
else:
further_blobs_request['count'] = settings.MAX_BLOB_INFOS_TO_REQUEST
further_blobs_request['count'] = conf.settings.MAX_BLOB_INFOS_TO_REQUEST
log.debug("Requesting %s blob infos from %s", str(further_blobs_request['count']), str(peer))
r_dict = {'further_blobs': further_blobs_request}
response_identifier = 'further_blobs'

View file

@ -774,7 +774,8 @@ class Daemon(AuthJSONRPCServer):
EncryptedFileStreamType, file_opener_factory)
return defer.succeed(None)
def _download_sd_blob(self, sd_hash, timeout=conf.settings.sd_download_timeout):
def _download_sd_blob(self, sd_hash, timeout=None):
timeout = timeout if timeout is not None else conf.settings.sd_download_timeout
def cb(result):
if not r.called:
r.callback(result)
@ -795,12 +796,13 @@ class Daemon(AuthJSONRPCServer):
return r
def _download_name(self, name, timeout=conf.settings.download_timeout, download_directory=None,
def _download_name(self, name, timeout=None, 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.
If it already exists in the file manager, return the existing lbry file
"""
timeout = timeout if timeout is not None else conf.settings.download_timeout
self.analytics_manager.send_download_started(name, stream_info)
helper = _DownloadNameHelper(
self, name, timeout, download_directory, file_name, wait_for_write)
@ -2341,12 +2343,12 @@ def get_output_callback(params):
class _DownloadNameHelper(object):
def __init__(self, daemon, name,
timeout=conf.settings.download_timeout,
timeout=None,
download_directory=None, file_name=None,
wait_for_write=True):
self.daemon = daemon
self.name = name
self.timeout = timeout
self.timeout = timeout if timeout is not None else conf.settings.download_timeout
if not download_directory or not os.path.isdir(download_directory):
self.download_directory = daemon.download_directory
else:

View file

@ -1,7 +1,7 @@
import sys
import argparse
import json
from lbrynet.conf import settings
from lbrynet import conf
from lbrynet.lbrynet_daemon.auth.client import LBRYAPIClient
from jsonrpc.common import RPCError
@ -45,7 +45,7 @@ def main():
assert status.get('code', False) == "started"
except Exception:
try:
settings.update({'use_auth_http': not settings.use_auth_http})
conf.settings.update({'use_auth_http': not conf.settings.use_auth_http})
api = LBRYAPIClient.config()
status = api.daemon_status()
assert status.get('code', False) == "started"

View file

@ -10,7 +10,7 @@ from lbrynet import conf
from lbrynet.core import log_support
from lbrynet.core import utils
from lbrynet.lbrynet_daemon.DaemonServer import DaemonServer
from lbrynet.conf import settings
from lbrynet import conf
log = logging.getLogger(__name__)
@ -30,12 +30,13 @@ def stop():
log.info("Attempt to shut down lbrynet-daemon from command line when daemon isn't running")
d = defer.Deferred(None)
d.addCallback(lambda _: JSONRPCProxy.from_url(settings.API_CONNECTION_STRING).stop())
d.addCallback(lambda _: JSONRPCProxy.from_url(conf.settings.API_CONNECTION_STRING).stop())
d.addCallbacks(lambda _: _disp_shutdown(), lambda _: _disp_not_running())
d.callback(None)
def start():
conf.initialize_settings()
parser = argparse.ArgumentParser(description="Launch lbrynet-daemon")
parser.add_argument("--wallet",
help="lbryum or ptc for testing, default lbryum",
@ -44,8 +45,8 @@ def start():
parser.add_argument("--ui", help="path to custom UI folder", default=None)
parser.add_argument(
"--branch",
help='Branch of lbry-web-ui repo to use, defaults to {}'.format(settings.ui_branch),
default=settings.ui_branch)
help='Branch of lbry-web-ui repo to use, defaults to {}'.format(conf.settings.ui_branch),
default=conf.settings.ui_branch)
parser.add_argument('--no-launch', dest='launchui', action="store_false")
parser.add_argument("--http-auth", dest="useauth", action="store_true")
parser.add_argument(
@ -67,13 +68,13 @@ def start():
conf.update_settings_from_file()
update_settings_from_args(args)
lbrynet_log = settings.get_log_filename()
lbrynet_log = conf.settings.get_log_filename()
log_support.configure_logging(lbrynet_log, args.logtoconsole, args.verbose)
log.debug('Final Settings: %s', settings.get_dict())
log.debug('Final Settings: %s', conf.settings.get_dict())
try:
log.debug('Checking for an existing lbrynet daemon instance')
JSONRPCProxy.from_url(settings.API_CONNECTION_STRING).is_running()
JSONRPCProxy.from_url(conf.settings.API_CONNECTION_STRING).is_running()
log.info("lbrynet-daemon is already running")
if not args.logtoconsole:
print "lbrynet-daemon is already running"
@ -87,8 +88,9 @@ def start():
if not args.logtoconsole and not args.quiet:
print "Starting lbrynet-daemon from command line"
print "To view activity, view the log file here: " + lbrynet_log
print "Web UI is available at http://%s:%i" % (settings.API_INTERFACE, settings.api_port)
print "JSONRPC API is available at " + settings.API_CONNECTION_STRING
print "Web UI is available at http://%s:%i" % (
conf.settings.API_INTERFACE, conf.settings.api_port)
print "JSONRPC API is available at " + conf.settings.API_CONNECTION_STRING
print "To quit press ctrl-c or call 'stop' via the API"
if test_internet_connection():
@ -114,7 +116,7 @@ def update_settings_from_args(args):
to_pass['ui_branch'] = args.branch
to_pass['use_auth_http'] = args.useauth
to_pass['wallet'] = args.wallet
settings.update(to_pass)
conf.settings.update(to_pass)
@defer.inlineCallbacks
@ -130,8 +132,8 @@ def start_server_and_listen(launchui, use_auth, analytics_manager):
daemon_server = DaemonServer(analytics_manager)
yield daemon_server.start(use_auth)
if launchui:
yield webbrowser.open(settings.UI_ADDRESS)
yield analytics_manager.send_server_startup_success()
yield webbrowser.open(conf.settings.UI_ADDRESS)
analytics_manager.send_server_startup_success()
except Exception as e:
log.exception('Failed to startup')
analytics_manager.send_server_startup_error(str(e))

View file

@ -6,7 +6,7 @@ from twisted.web import server, guard
from twisted.internet import defer, reactor, error
from twisted.cred import portal
from lbrynet.conf import settings
from lbrynet import conf
from lbrynet.lbrynet_daemon.Daemon import Daemon
from lbrynet.lbrynet_daemon.Resources import LBRYindex, HostedEncryptedFile, EncryptedFileUpload
from lbrynet.lbrynet_daemon.auth.auth import PasswordChecker, HttpPasswordRealm
@ -23,18 +23,19 @@ class DaemonServer(object):
self.analytics_manager = analytics_manager
def _setup_server(self, use_auth):
ui_path = os.path.join(settings.ensure_data_dir(), "lbry-ui", "active")
ui_path = os.path.join(conf.settings.ensure_data_dir(), "lbry-ui", "active")
self.root = LBRYindex(ui_path)
self._api = Daemon(self.root, self.analytics_manager)
self.root.putChild("view", HostedEncryptedFile(self._api))
self.root.putChild("upload", EncryptedFileUpload(self._api))
self.root.putChild(settings.API_ADDRESS, self._api)
self.root.putChild(conf.settings.API_ADDRESS, self._api)
lbrynet_server = server.Site(get_site_base(use_auth, self.root))
lbrynet_server.requestFactory = DaemonRequest
try:
reactor.listenTCP(settings.api_port, lbrynet_server, interface=settings.API_INTERFACE)
reactor.listenTCP(
conf.settings.api_port, lbrynet_server, interface=conf.settings.API_INTERFACE)
except error.CannotListenError:
log.info('Daemon already running, exiting app')
sys.exit(1)
@ -57,7 +58,7 @@ def get_site_base(use_auth, root):
def create_auth_session(root):
pw_path = os.path.join(settings.data_dir, ".api_keys")
pw_path = os.path.join(conf.settings.data_dir, ".api_keys")
initialize_api_key_file(pw_path)
checker = PasswordChecker.load_file(pw_path)
realm = HttpPasswordRealm(root)

View file

@ -9,7 +9,7 @@ from lbrynet.core.Error import InsufficientFundsError, KeyFeeAboveMaxAllowed
from lbrynet.core.StreamDescriptor import download_sd_blob
from lbrynet.metadata.Fee import FeeValidator
from lbrynet.lbryfilemanager.EncryptedFileDownloader import ManagedEncryptedFileDownloaderFactory
from lbrynet.conf import settings
from lbrynet import conf
INITIALIZING_CODE = 'initializing'
DOWNLOAD_METADATA_CODE = 'downloading_metadata'
@ -34,7 +34,7 @@ class GetStream(object):
max_key_fee, data_rate=0.5, timeout=None,
download_directory=None, file_name=None):
if timeout is None:
timeout = settings.download_timeout
timeout = conf.settings.download_timeout
self.wallet = wallet
self.resolved_name = None
self.description = None

View file

@ -10,7 +10,7 @@ from lbrynet.lbryfile.StreamDescriptor import publish_sd_blob
from lbrynet.metadata.Metadata import Metadata
from lbrynet.lbryfilemanager.EncryptedFileDownloader import ManagedEncryptedFileDownloader
from lbrynet import reflector
from lbrynet.conf import settings
from lbrynet import conf
log = logging.getLogger(__name__)
@ -32,7 +32,7 @@ class Publisher(object):
self.nout = None
self.stream_hash = None
# TODO: this needs to be passed into the constructor
reflector_server = random.choice(settings.reflector_servers)
reflector_server = random.choice(conf.settings.reflector_servers)
self.reflector_server, self.reflector_port = reflector_server[0], reflector_server[1]
self.metadata = {}
@ -77,7 +77,7 @@ class Publisher(object):
def start_reflector(self):
# TODO: is self.reflector_server unused?
reflector_server = random.choice(settings.reflector_servers)
reflector_server = random.choice(conf.settings.reflector_servers)
reflector_address, reflector_port = reflector_server[0], reflector_server[1]
log.info("Reflecting new publication")
factory = reflector.ClientFactory(

View file

@ -10,7 +10,7 @@ from appdirs import user_data_dir
from twisted.web import server, static, resource
from twisted.internet import defer, error
from lbrynet.conf import settings
from lbrynet import conf
from lbrynet.lbrynet_daemon.FileStreamer import EncryptedFileStreamer
# TODO: omg, this code is essentially duplicated in Daemon
@ -85,10 +85,10 @@ class HostedEncryptedFile(resource.Resource):
d = self._api._download_name(request.args['name'][0])
d.addCallback(lambda stream: self._make_stream_producer(request, stream))
elif request.args['name'][0] in self._api.waiting_on.keys():
request.redirect(settings.UI_ADDRESS + "/?watch=" + request.args['name'][0])
request.redirect(conf.settings.UI_ADDRESS + "/?watch=" + request.args['name'][0])
request.finish()
else:
request.redirect(settings.UI_ADDRESS)
request.redirect(conf.settings.UI_ADDRESS)
request.finish()
return server.NOT_DONE_YET

View file

@ -10,7 +10,7 @@ import pkg_resources
from twisted.internet import defer
from twisted.internet.task import LoopingCall
from lbrynet.conf import settings
from lbrynet import conf
from lbrynet.lbrynet_daemon.Resources import NoCacheStaticFile
from lbrynet import __version__ as lbrynet_version
from lbryum.version import LBRYUM_VERSION as lbryum_version
@ -22,7 +22,7 @@ log = logging.getLogger(__name__)
class UIManager(object):
def __init__(self, root):
self.ui_root = os.path.join(settings.data_dir, "lbry-ui")
self.ui_root = os.path.join(conf.settings.data_dir, "lbry-ui")
self.active_dir = os.path.join(self.ui_root, "active")
self.update_dir = os.path.join(self.ui_root, "update")
@ -61,11 +61,11 @@ class UIManager(object):
self.loaded_requirements = None
def setup(self, branch=None, check_requirements=None, user_specified=None):
local_ui_path = user_specified or settings.local_ui_path
local_ui_path = user_specified or conf.settings.local_ui_path
self.branch = branch or settings.ui_branch
self.branch = branch or conf.settings.ui_branch
self.check_requirements = (check_requirements if check_requirements is not None
else settings.check_ui_requirements)
else conf.settings.check_ui_requirements)
if self._check_for_bundled_ui():
return defer.succeed(True)

View file

@ -6,7 +6,7 @@ import base64
import json
from lbrynet.lbrynet_daemon.auth.util import load_api_keys, APIKey, API_KEY_NAME, get_auth_message
from lbrynet.conf import settings
from lbrynet import conf
from jsonrpc.proxy import JSONRPCProxy
log = logging.getLogger(__name__)
@ -106,7 +106,7 @@ class AuthAPIClient(object):
url=None, login_url=None):
api_key_name = API_KEY_NAME if not key_name else key_name
pw_path = os.path.join(settings.data_dir, ".api_keys") if not pw_path else pw_path
pw_path = os.path.join(conf.settings.data_dir, ".api_keys") if not pw_path else pw_path
if not key:
keys = load_api_keys(pw_path)
api_key = keys.get(api_key_name, False)
@ -115,9 +115,9 @@ class AuthAPIClient(object):
if login_url is None:
service_url = "http://%s:%s@%s:%i/%s" % (api_key_name,
api_key.secret,
settings.API_INTERFACE,
settings.api_port,
settings.API_ADDRESS)
conf.settings.API_INTERFACE,
conf.settings.api_port,
conf.settings.API_ADDRESS)
else:
service_url = login_url
id_count = count
@ -164,14 +164,14 @@ class AuthAPIClient(object):
class LBRYAPIClient(object):
@staticmethod
def config(service=None, params=None):
if settings.use_auth_http:
if conf.settings.use_auth_http:
if service is None:
return AuthAPIClient.config()
log.error("Try auth")
if params is not None:
return AuthAPIClient.config(service=service)(params)
return AuthAPIClient.config(service=service)()
url = settings.API_CONNECTION_STRING
url = conf.settings.API_CONNECTION_STRING
if service is None:
return JSONRPCProxy.from_url(url)
return JSONRPCProxy.from_url(url).call(service, params)

View file

@ -9,7 +9,7 @@ from twisted.python.failure import Failure
from txjsonrpc import jsonrpclib
from lbrynet.core.Error import InvalidAuthenticationToken, InvalidHeaderError, SubhandlerError
from lbrynet.conf import settings
from lbrynet import conf
from lbrynet.lbrynet_daemon.auth.util import APIKey, get_auth_message
from lbrynet.lbrynet_daemon.auth.client import LBRY_SECRET
@ -97,9 +97,10 @@ class AuthJSONRPCServer(AuthorizedBase):
NOT_FOUND = 8001
FAILURE = 8002
def __init__(self, use_authentication=settings.use_auth_http):
def __init__(self, use_authentication=None):
AuthorizedBase.__init__(self)
self._use_authentication = use_authentication
self._use_authentication = (
use_authentication if use_authentication is not None else conf.settings.use_auth_http)
self.announced_startup = False
self.allowed_during_startup = []
self.sessions = {}
@ -211,8 +212,8 @@ class AuthJSONRPCServer(AuthorizedBase):
log.debug(err.getTraceback())
def _set_headers(self, request, data, update_secret=False):
if settings.allowed_origin:
request.setHeader("Access-Control-Allow-Origin", settings.allowed_origin)
if conf.settings.allowed_origin:
request.setHeader("Access-Control-Allow-Origin", conf.settings.allowed_origin)
request.setHeader("Content-Type", "text/json")
request.setHeader("Content-Length", str(len(data)))
if update_secret:
@ -239,12 +240,12 @@ class AuthJSONRPCServer(AuthorizedBase):
def _check_source_of_request(self, source):
if source is None:
return True
if settings.API_INTERFACE == '0.0.0.0':
if conf.settings.API_INTERFACE == '0.0.0.0':
return True
server, port = self.get_server_port(source)
return (
server == settings.API_INTERFACE and
port == settings.api_port)
server == conf.settings.API_INTERFACE and
port == conf.settings.api_port)
def get_server_port(self, origin):
parsed = urlparse.urlparse(origin)

View file

@ -1,4 +1,4 @@
from lbrynet.conf import settings
from lbrynet import conf
from twisted.web.client import Agent, FileBodyProducer, Headers, ResponseDone
from twisted.internet import threads, defer, protocol
@ -47,7 +47,7 @@ def get_body_from_request(path, data):
jsondata = FileBodyProducer(StringIO(json.dumps(data)))
agent = Agent(reactor)
d = agent.request(
'POST', settings.pointtrader_server + path,
'POST', conf.settings.pointtrader_server + path,
Headers({'Content-Type': ['application/json']}), jsondata)
d.addCallback(get_body)
return d

View file

@ -7,7 +7,7 @@ from twisted.internet import reactor
from lbrynet.lbrynet_daemon import DaemonControl
from lbrynet import analytics
from lbrynet.conf import settings
from lbrynet import conf
from lbrynet.core import utils
@ -27,7 +27,7 @@ class LBRYDaemonApp(AppKit.NSApplication):
self.connection = False
statusbar = AppKit.NSStatusBar.systemStatusBar()
self.statusitem = statusbar.statusItemWithLength_(AppKit.NSVariableStatusItemLength)
self.icon = AppKit.NSImage.alloc().initByReferencingFile_(settings.ICON_PATH)
self.icon = AppKit.NSImage.alloc().initByReferencingFile_(conf.settings.ICON_PATH)
self.icon.setScalesWhenResized_(True)
self.icon.setSize_((20, 20))
self.statusitem.setImage_(self.icon)
@ -39,7 +39,7 @@ class LBRYDaemonApp(AppKit.NSApplication):
"Quit", "applicationShouldTerminate:", "")
self.menubarMenu.addItem_(self.quit)
self.statusitem.setMenu_(self.menubarMenu)
self.statusitem.setToolTip_(settings.APP_NAME)
self.statusitem.setToolTip_(conf.settings.APP_NAME)
if test_internet_connection():
notify("Starting LBRY")
@ -53,7 +53,7 @@ class LBRYDaemonApp(AppKit.NSApplication):
)
def openui_(self, sender):
webbrowser.open(settings.UI_ADDRESS)
webbrowser.open(conf.settings.UI_ADDRESS)
# this code is from the example
# https://pythonhosted.org/pyobjc/examples/Cocoa/Twisted/WebServicesTool/index.html

View file

@ -2,14 +2,14 @@
import os
from setuptools import setup
from lbrynet.conf import settings
from lbrynet import conf
APP = [os.path.join('lbrygui', 'main.py')]
DATA_FILES = []
DATA_FILES.append('app.icns')
OPTIONS = {
'iconfile': settings.ICON_PATH,
'iconfile': conf.ICON_PATH,
'plist': {
'CFBundleIdentifier': 'io.lbry.LBRY',
'LSUIElement': True,
@ -22,7 +22,7 @@ OPTIONS = {
setup(
name=settings.APP_NAME,
name=conf.APP_NAME,
app=APP,
options={'py2app': OPTIONS},
data_files=DATA_FILES,

View file

@ -1,6 +1,6 @@
from setuptools import setup
import os
from lbrynet.conf import settings
from lbrynet import conf
APP = [os.path.join('lbry_uri_handler', 'LBRYURIHandler.py')]
DATA_FILES = []
@ -12,7 +12,7 @@ OPTIONS = {'argv_emulation': True,
'CFBundleURLTypes': [
{
'CFBundleURLTypes': 'LBRYURIHandler',
'CFBundleURLSchemes': [settings.PROTOCOL_PREFIX]
'CFBundleURLSchemes': [conf.PROTOCOL_PREFIX]
}
]
}

View file

@ -5,7 +5,7 @@ import sys
from time import sleep
from lbrynet.lbrynet_daemon.auth.client import LBRYAPIClient
from lbrynet.conf import settings
from lbrynet import conf
class LBRYURIHandler(object):
@ -69,9 +69,9 @@ class LBRYURIHandler(object):
@staticmethod
def open_address(lbry_name):
if lbry_name == "lbry" or lbry_name == "" or lbry_name is None:
webbrowser.open(settings.UI_ADDRESS)
webbrowser.open(conf.settings.UI_ADDRESS)
else:
webbrowser.open(settings.UI_ADDRESS + "/?show=" + lbry_name)
webbrowser.open(conf.settings.UI_ADDRESS + "/?show=" + lbry_name)
def main(args):

View file

@ -19,7 +19,7 @@ from lbrynet import conf, analytics
from lbrynet.core import log_support
from lbrynet.core import utils
from lbrynet.lbrynet_daemon import DaemonControl
from lbrynet.conf import settings
from lbrynet import conf
from packaging.uri_handler.LBRYURIHandler import LBRYURIHandler
@ -240,7 +240,7 @@ def main(lbry_name=None):
return SysTrayIcon(icon, hover_text, menu_options, on_quit=stop)
def openui_(sender):
webbrowser.open(settings.UI_ADDRESS)
webbrowser.open(conf.settings.UI_ADDRESS)
def replyToApplicationShouldTerminate_():
try:
@ -252,11 +252,11 @@ def main(lbry_name=None):
replyToApplicationShouldTerminate_()
if getattr(sys, 'frozen', False) and os.name == "nt":
icon = os.path.join(os.path.dirname(sys.executable), settings.ICON_PATH, 'lbry16.ico')
icon = os.path.join(os.path.dirname(sys.executable), conf.settings.ICON_PATH, 'lbry16.ico')
else:
icon = os.path.join(settings.ICON_PATH, 'lbry16.ico')
icon = os.path.join(conf.settings.ICON_PATH, 'lbry16.ico')
hover_text = settings.APP_NAME
hover_text = conf.settings.APP_NAME
menu_options = (('Open', icon, openui_),)
if not test_internet_connection():
@ -278,10 +278,10 @@ if __name__ == '__main__':
utils.setup_certs_for_windows()
conf.update_settings_from_file()
log_file = settings.get_log_filename()
log_file = conf.settings.get_log_filename()
log_support.configure_logging(log_file, console=True)
lbry_daemon = JSONRPCProxy.from_url(settings.API_CONNECTION_STRING)
lbry_daemon = JSONRPCProxy.from_url(conf.settings.API_CONNECTION_STRING)
try:
daemon_running = lbry_daemon.is_running()

View file

@ -11,7 +11,7 @@ import unittest
from Crypto.PublicKey import RSA
from Crypto import Random
from Crypto.Hash import MD5
from lbrynet.conf import settings
from lbrynet import conf
from lbrynet.lbrylive.LiveStreamCreator import FileLiveStreamCreator
from lbrynet.lbrylive.LiveStreamMetadataManager import DBLiveStreamMetadataManager
from lbrynet.lbrylive.LiveStreamMetadataManager import TempLiveStreamMetadataManager
@ -117,7 +117,7 @@ class LbryUploader(object):
db_dir = "server"
os.mkdir(db_dir)
self.session = Session(
settings.data_rate, db_dir=db_dir, lbryid="abcd",
conf.settings.data_rate, db_dir=db_dir, lbryid="abcd",
peer_finder=peer_finder, hash_announcer=hash_announcer, peer_port=5553,
use_upnp=False, rate_limiter=rate_limiter, wallet=wallet,
blob_tracker_class=DummyBlobAvailabilityTracker,
@ -222,11 +222,11 @@ def start_lbry_reuploader(sd_hash, kill_event, dead_event,
os.mkdir(db_dir)
os.mkdir(blob_dir)
session = Session(settings.data_rate, db_dir=db_dir, lbryid="abcd" + str(n),
session = Session(conf.settings.data_rate, db_dir=db_dir, lbryid="abcd" + str(n),
peer_finder=peer_finder, hash_announcer=hash_announcer,
blob_dir=None, peer_port=peer_port,
use_upnp=False, rate_limiter=rate_limiter, wallet=wallet,
blob_tracker_class=DummyBlobAvailabilityTracker, is_generous=settings.is_generous_host)
blob_tracker_class=DummyBlobAvailabilityTracker, is_generous=conf.settings.is_generous_host)
stream_info_manager = TempEncryptedFileMetadataManager()
@ -329,10 +329,10 @@ def start_live_server(sd_hash_queue, kill_event, dead_event):
db_dir = "server"
os.mkdir(db_dir)
session = Session(settings.data_rate, db_dir=db_dir, lbryid="abcd",
session = Session(conf.settings.data_rate, db_dir=db_dir, lbryid="abcd",
peer_finder=peer_finder, hash_announcer=hash_announcer, peer_port=5553,
use_upnp=False, rate_limiter=rate_limiter, wallet=wallet,
blob_tracker_class=DummyBlobAvailabilityTracker, is_generous=settings.is_generous_host)
blob_tracker_class=DummyBlobAvailabilityTracker, is_generous=conf.settings.is_generous_host)
stream_info_manager = DBLiveStreamMetadataManager(session.db_dir, hash_announcer)
logging.debug("Created the session")
@ -457,11 +457,11 @@ def start_blob_uploader(blob_hash_queue, kill_event, dead_event, slow, is_genero
os.mkdir(db_dir)
os.mkdir(blob_dir)
session = Session(settings.data_rate, db_dir=db_dir, lbryid="efgh",
session = Session(conf.settings.data_rate, db_dir=db_dir, lbryid="efgh",
peer_finder=peer_finder, hash_announcer=hash_announcer,
blob_dir=blob_dir, peer_port=peer_port,
use_upnp=False, rate_limiter=rate_limiter, wallet=wallet,
blob_tracker_class=DummyBlobAvailabilityTracker, is_generous=settings.is_generous_host)
blob_tracker_class=DummyBlobAvailabilityTracker, is_generous=conf.settings.is_generous_host)
if slow is True:
session.rate_limiter.set_ul_limit(2 ** 11)
@ -635,7 +635,7 @@ class TestTransfer(TestCase):
os.mkdir(blob_dir)
self.session = Session(
settings.data_rate, db_dir=db_dir, lbryid="abcd",
conf.settings.data_rate, db_dir=db_dir, lbryid="abcd",
peer_finder=peer_finder, hash_announcer=hash_announcer,
blob_dir=blob_dir, peer_port=5553,
use_upnp=False, rate_limiter=rate_limiter, wallet=wallet,
@ -725,7 +725,7 @@ class TestTransfer(TestCase):
os.mkdir(db_dir)
self.session = Session(
settings.data_rate, db_dir=db_dir, lbryid="abcd",
conf.settings.data_rate, db_dir=db_dir, lbryid="abcd",
peer_finder=peer_finder, hash_announcer=hash_announcer, blob_dir=None,
peer_port=5553, use_upnp=False, rate_limiter=rate_limiter, wallet=wallet,
blob_tracker_class=DummyBlobAvailabilityTracker, dht_node_class=Node
@ -827,12 +827,12 @@ class TestTransfer(TestCase):
os.mkdir(blob_dir)
self.session = Session(
settings.data_rate, db_dir=db_dir, lbryid="abcd",
conf.settings.data_rate, db_dir=db_dir, lbryid="abcd",
peer_finder=peer_finder, hash_announcer=hash_announcer,
blob_dir=blob_dir, peer_port=5553,
use_upnp=False, rate_limiter=rate_limiter, wallet=wallet,
blob_tracker_class=DummyBlobAvailabilityTracker,
is_generous=settings.is_generous_host)
is_generous=conf.settings.is_generous_host)
d1 = self.wait_for_hash_from_queue(blob_hash_queue_1)
d2 = self.wait_for_hash_from_queue(blob_hash_queue_2)
@ -905,11 +905,11 @@ class TestTransfer(TestCase):
os.mkdir(db_dir)
os.mkdir(blob_dir)
self.session = Session(settings.data_rate, db_dir=db_dir, lbryid="abcd",
self.session = Session(conf.settings.data_rate, db_dir=db_dir, lbryid="abcd",
peer_finder=peer_finder, hash_announcer=hash_announcer,
blob_dir=blob_dir, peer_port=5553, use_upnp=False,
rate_limiter=rate_limiter, wallet=wallet,
blob_tracker_class=DummyBlobAvailabilityTracker, is_generous=settings.is_generous_host)
blob_tracker_class=DummyBlobAvailabilityTracker, is_generous=conf.settings.is_generous_host)
self.stream_info_manager = DBEncryptedFileMetadataManager(self.session.db_dir)
self.lbry_file_manager = EncryptedFileManager(self.session, self.stream_info_manager, sd_identifier)
@ -1022,12 +1022,12 @@ class TestTransfer(TestCase):
os.mkdir(db_dir)
os.mkdir(blob_dir)
self.session = Session(settings.data_rate, db_dir=db_dir, lbryid="abcd",
self.session = Session(conf.settings.data_rate, db_dir=db_dir, lbryid="abcd",
peer_finder=peer_finder, hash_announcer=hash_announcer,
blob_dir=None, peer_port=5553,
use_upnp=False, rate_limiter=rate_limiter, wallet=wallet,
blob_tracker_class=DummyBlobAvailabilityTracker,
is_generous=settings.is_generous_host)
is_generous=conf.settings.is_generous_host)
self.stream_info_manager = TempEncryptedFileMetadataManager()

View file

@ -4,7 +4,7 @@ import shutil
from twisted.internet import defer, threads, error
from twisted.trial import unittest
from lbrynet.conf import settings
from lbrynet import conf
from lbrynet import lbryfile
from lbrynet import reflector
from lbrynet.core import BlobManager
@ -83,7 +83,7 @@ class TestReflector(unittest.TestCase):
os.mkdir(db_dir)
self.session = Session.Session(
settings.data_rate,
conf.settings.data_rate,
db_dir=db_dir,
lbryid="abcd",
peer_finder=peer_finder,

View file

@ -6,7 +6,7 @@ from Crypto.Hash import MD5
from twisted.trial.unittest import TestCase
from twisted.internet import defer, threads
from lbrynet.conf import settings
from lbrynet import conf
from lbrynet.lbryfile.EncryptedFileMetadataManager import TempEncryptedFileMetadataManager
from lbrynet.lbryfile.EncryptedFileMetadataManager import DBEncryptedFileMetadataManager
from lbrynet.lbryfilemanager.EncryptedFileManager import EncryptedFileManager
@ -70,7 +70,7 @@ class TestStreamify(TestCase):
os.mkdir(blob_dir)
self.session = Session(
settings.data_rate, db_dir=db_dir, lbryid="abcd",
conf.settings.data_rate, db_dir=db_dir, lbryid="abcd",
peer_finder=peer_finder, hash_announcer=hash_announcer,
blob_dir=blob_dir, peer_port=5553,
use_upnp=False, rate_limiter=rate_limiter, wallet=wallet,
@ -126,7 +126,7 @@ class TestStreamify(TestCase):
os.mkdir(blob_dir)
self.session = Session(
settings.data_rate, db_dir=db_dir, lbryid="abcd",
conf.settings.data_rate, db_dir=db_dir, lbryid="abcd",
peer_finder=peer_finder, hash_announcer=hash_announcer,
blob_dir=blob_dir, peer_port=5553,
use_upnp=False, rate_limiter=rate_limiter, wallet=wallet,