forked from LBRYCommunity/lbry-sdk
Merge branch 'master' into unicode-settings
This commit is contained in:
commit
2294e6bf36
13 changed files with 107 additions and 92 deletions
|
@ -1,5 +1,5 @@
|
||||||
[bumpversion]
|
[bumpversion]
|
||||||
current_version = 0.7.2
|
current_version = 0.7.3
|
||||||
commit = True
|
commit = True
|
||||||
tag = True
|
tag = True
|
||||||
|
|
||||||
|
|
|
@ -293,7 +293,8 @@ ignored-modules=twisted.internet.reactor,leveldb
|
||||||
# List of classes names for which member attributes should not be checked
|
# List of classes names for which member attributes should not be checked
|
||||||
# (useful for classes with attributes dynamically set). This supports can work
|
# (useful for classes with attributes dynamically set). This supports can work
|
||||||
# with qualified names.
|
# with qualified names.
|
||||||
ignored-classes=twisted.internet,RequestMessage
|
ignored-classes=twisted.internet.reactor,RequestMessage
|
||||||
|
|
||||||
|
|
||||||
# List of members which are set dynamically and missed by pylint inference
|
# List of members which are set dynamically and missed by pylint inference
|
||||||
# system, and so shouldn't trigger E1101 when accessed. Python regular
|
# system, and so shouldn't trigger E1101 when accessed. Python regular
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
__version__ = "0.7.2"
|
__version__ = "0.7.3"
|
||||||
version = tuple(__version__.split('.'))
|
version = tuple(__version__.split('.'))
|
||||||
|
|
||||||
logging.getLogger(__name__).addHandler(logging.NullHandler())
|
logging.getLogger(__name__).addHandler(logging.NullHandler())
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
import copy
|
import copy
|
||||||
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import yaml
|
||||||
|
|
||||||
from appdirs import user_data_dir
|
from appdirs import user_data_dir
|
||||||
|
|
||||||
|
@ -248,20 +250,66 @@ class Config(DefaultSettings):
|
||||||
def UI_ADDRESS(self):
|
def UI_ADDRESS(self):
|
||||||
return "http://%s:%i" % (DEFAULT_SETTINGS.API_INTERFACE, self.api_port)
|
return "http://%s:%i" % (DEFAULT_SETTINGS.API_INTERFACE, self.api_port)
|
||||||
|
|
||||||
|
def ensure_data_dir(self):
|
||||||
|
# although there is a risk of a race condition here we don't
|
||||||
|
# expect there to be multiple processes accessing this
|
||||||
|
# directory so the risk can be ignored
|
||||||
|
if not os.path.isdir(self.data_dir):
|
||||||
|
os.makedirs(self.data_dir)
|
||||||
|
return self.data_dir
|
||||||
|
|
||||||
def get_data_dir():
|
def get_log_filename(self):
|
||||||
data_dir = default_data_dir
|
"""Return the log file for this platform.
|
||||||
if not os.path.isdir(data_dir):
|
|
||||||
os.mkdir(data_dir)
|
Also ensure the containing directory exists
|
||||||
return data_dir
|
"""
|
||||||
|
return os.path.join(self.ensure_data_dir(), self.LOG_FILE_NAME)
|
||||||
|
|
||||||
|
def get_conf_filename(self):
|
||||||
|
return os.path.join(self.ensure_data_dir(), "daemon_settings.yml")
|
||||||
|
|
||||||
|
|
||||||
def get_log_filename():
|
def update_settings_from_file(filename=None):
|
||||||
"""Return the log file for this platform.
|
filename = filename or settings.get_conf_filename()
|
||||||
|
try:
|
||||||
|
updates = load_settings(filename)
|
||||||
|
log.info("Loaded settings file: %s", updates)
|
||||||
|
settings.update(updates)
|
||||||
|
except OSError as ex:
|
||||||
|
log.info('%s: Failed to update settings from %s', ex, filename)
|
||||||
|
|
||||||
Also ensure the containing directory exists
|
|
||||||
"""
|
settings_decoders = {
|
||||||
return os.path.join(get_data_dir(), settings.LOG_FILE_NAME)
|
'.json': json.loads,
|
||||||
|
'.yml': yaml.load
|
||||||
|
}
|
||||||
|
|
||||||
|
settings_encoders = {
|
||||||
|
'.json': json.dumps,
|
||||||
|
'.yml': yaml.safe_dump
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def load_settings(path=None):
|
||||||
|
path = path or settings.get_conf_filename()
|
||||||
|
ext = os.path.splitext(path)[1]
|
||||||
|
with open(path, 'r') as settings_file:
|
||||||
|
data = settings_file.read()
|
||||||
|
decoder = settings_decoders.get(ext, False)
|
||||||
|
assert decoder is not False, "Unknown settings format .%s" % ext
|
||||||
|
return decoder(data)
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: be careful with this. If a setting is overriden by an environment variable
|
||||||
|
# or command line flag we don't want to persist it for future settings.
|
||||||
|
def save_settings(path=None):
|
||||||
|
path = path or settings.get_conf_filename()
|
||||||
|
to_save = {k: v for k, v in settings.__dict__.iteritems() if k in ADJUSTABLE_SETTINGS}
|
||||||
|
ext = os.path.splitext(path)[1]
|
||||||
|
encoder = settings_encoders.get(ext, False)
|
||||||
|
assert encoder is not False, "Unknown settings format .%s" % ext
|
||||||
|
with open(path, 'w') as settings_file:
|
||||||
|
settings_file.write(encoder(to_save))
|
||||||
|
|
||||||
|
|
||||||
# TODO: don't load the configuration automatically. The configuration
|
# TODO: don't load the configuration automatically. The configuration
|
||||||
|
|
|
@ -462,10 +462,7 @@ class Wallet(object):
|
||||||
|
|
||||||
def _claim_or_update(claim, metadata, _bid):
|
def _claim_or_update(claim, metadata, _bid):
|
||||||
if not claim:
|
if not claim:
|
||||||
log.info("No claim yet, making a new one")
|
log.info("No own claim yet, making a new one")
|
||||||
return self._send_name_claim(name, metadata, _bid)
|
|
||||||
if not claim['is_mine']:
|
|
||||||
log.info("Making a contesting claim")
|
|
||||||
return self._send_name_claim(name, metadata, _bid)
|
return self._send_name_claim(name, metadata, _bid)
|
||||||
else:
|
else:
|
||||||
log.info("Updating over own claim")
|
log.info("Updating over own claim")
|
||||||
|
@ -474,8 +471,7 @@ class Wallet(object):
|
||||||
return d
|
return d
|
||||||
|
|
||||||
meta = Metadata(m)
|
meta = Metadata(m)
|
||||||
|
d = self.get_my_claim(name)
|
||||||
d = self.get_claim_info(name)
|
|
||||||
d.addCallback(lambda claim: _claim_or_update(claim, meta, bid))
|
d.addCallback(lambda claim: _claim_or_update(claim, meta, bid))
|
||||||
d.addCallback(lambda txid: _save_metadata(txid, meta))
|
d.addCallback(lambda txid: _save_metadata(txid, meta))
|
||||||
return d
|
return d
|
||||||
|
|
|
@ -2,15 +2,11 @@ import base64
|
||||||
import datetime
|
import datetime
|
||||||
import distutils.version
|
import distutils.version
|
||||||
import logging
|
import logging
|
||||||
import json
|
|
||||||
import random
|
import random
|
||||||
import os
|
import os
|
||||||
import socket
|
import socket
|
||||||
import sys
|
import sys
|
||||||
import yaml
|
|
||||||
|
|
||||||
from lbrynet.conf import settings
|
|
||||||
from lbrynet.conf import AdjustableSettings
|
|
||||||
from lbrynet.core.cryptoutils import get_lbry_hash_obj
|
from lbrynet.core.cryptoutils import get_lbry_hash_obj
|
||||||
|
|
||||||
|
|
||||||
|
@ -34,6 +30,7 @@ def isonow():
|
||||||
"""Return utc now in isoformat with timezone"""
|
"""Return utc now in isoformat with timezone"""
|
||||||
return utcnow().isoformat() + 'Z'
|
return utcnow().isoformat() + 'Z'
|
||||||
|
|
||||||
|
|
||||||
def today():
|
def today():
|
||||||
return datetime.datetime.today()
|
return datetime.datetime.today()
|
||||||
|
|
||||||
|
@ -78,37 +75,6 @@ def obfuscate(plain):
|
||||||
return base64.b64encode(plain).encode('rot13')
|
return base64.b64encode(plain).encode('rot13')
|
||||||
|
|
||||||
|
|
||||||
settings_decoders = {
|
|
||||||
'.json': json.loads,
|
|
||||||
'.yml': yaml.load
|
|
||||||
}
|
|
||||||
|
|
||||||
settings_encoders = {
|
|
||||||
'.json': json.dumps,
|
|
||||||
'.yml': yaml.safe_dump
|
|
||||||
}
|
|
||||||
|
|
||||||
ADJUSTABLE_SETTINGS = AdjustableSettings().get_dict()
|
|
||||||
|
|
||||||
|
|
||||||
def load_settings(path):
|
|
||||||
ext = os.path.splitext(path)[1]
|
|
||||||
with open(path, 'r') as settings_file:
|
|
||||||
data = settings_file.read()
|
|
||||||
decoder = settings_decoders.get(ext, False)
|
|
||||||
assert decoder is not False, "Unknown settings format .%s" % ext
|
|
||||||
return decoder(data)
|
|
||||||
|
|
||||||
|
|
||||||
def save_settings(path):
|
|
||||||
to_save = {k: v for k, v in settings.__dict__.iteritems() if k in ADJUSTABLE_SETTINGS}
|
|
||||||
ext = os.path.splitext(path)[1]
|
|
||||||
encoder = settings_encoders.get(ext, False)
|
|
||||||
assert encoder is not False, "Unknown settings format .%s" % ext
|
|
||||||
with open(path, 'w') as settings_file:
|
|
||||||
settings_file.write(encoder(to_save))
|
|
||||||
|
|
||||||
|
|
||||||
def check_connection(server="www.lbry.io", port=80):
|
def check_connection(server="www.lbry.io", port=80):
|
||||||
"""Attempts to open a socket to server:port and returns True if successful."""
|
"""Attempts to open a socket to server:port and returns True if successful."""
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -26,9 +26,9 @@ from lbrynet import __version__ as lbrynet_version
|
||||||
from lbryum.version import LBRYUM_VERSION as lbryum_version
|
from lbryum.version import LBRYUM_VERSION as lbryum_version
|
||||||
|
|
||||||
from lbrynet import __version__ as lbrynet_version
|
from lbrynet import __version__ as lbrynet_version
|
||||||
|
from lbrynet import conf
|
||||||
from lbrynet.conf import settings as lbrynet_settings
|
from lbrynet.conf import settings as lbrynet_settings
|
||||||
from lbrynet import analytics
|
from lbrynet import analytics
|
||||||
from lbrynet import conf
|
|
||||||
from lbrynet import reflector
|
from lbrynet import reflector
|
||||||
from lbrynet.metadata.Metadata import Metadata, verify_name_characters
|
from lbrynet.metadata.Metadata import Metadata, verify_name_characters
|
||||||
from lbrynet.metadata.Fee import FeeValidator
|
from lbrynet.metadata.Fee import FeeValidator
|
||||||
|
@ -273,7 +273,7 @@ class Daemon(AuthJSONRPCServer):
|
||||||
self.ui_version = None
|
self.ui_version = None
|
||||||
self.ip = None
|
self.ip = None
|
||||||
self.first_run = None
|
self.first_run = None
|
||||||
self.log_file = conf.get_log_filename()
|
self.log_file = lbrynet_settings.get_log_filename()
|
||||||
self.current_db_revision = 1
|
self.current_db_revision = 1
|
||||||
self.session = None
|
self.session = None
|
||||||
self.uploaded_temp_files = []
|
self.uploaded_temp_files = []
|
||||||
|
@ -281,11 +281,11 @@ class Daemon(AuthJSONRPCServer):
|
||||||
# TODO: this should probably be passed into the daemon, or
|
# TODO: this should probably be passed into the daemon, or
|
||||||
# possibly have the entire log upload functionality taken out
|
# possibly have the entire log upload functionality taken out
|
||||||
# of the daemon, but I don't want to deal with that now
|
# of the daemon, but I don't want to deal with that now
|
||||||
self.log_uploader = log_support.LogUploader.load('lbrynet', conf.get_log_filename())
|
self.log_uploader = log_support.LogUploader.load('lbrynet', self.log_file)
|
||||||
|
|
||||||
self.analytics_manager = None
|
self.analytics_manager = None
|
||||||
self.lbryid = PENDING_LBRY_ID
|
self.lbryid = PENDING_LBRY_ID
|
||||||
self.daemon_conf = os.path.join(self.db_dir, 'daemon_settings.yml')
|
self.daemon_conf = lbrynet_settings.get_conf_filename()
|
||||||
|
|
||||||
self.wallet_user = None
|
self.wallet_user = None
|
||||||
self.wallet_password = None
|
self.wallet_password = None
|
||||||
|
@ -1071,8 +1071,7 @@ class Daemon(AuthJSONRPCServer):
|
||||||
remaining_scripts = [s for s in self.startup_scripts if 'run_once' not in s.keys()]
|
remaining_scripts = [s for s in self.startup_scripts if 'run_once' not in s.keys()]
|
||||||
startup_scripts = self.startup_scripts
|
startup_scripts = self.startup_scripts
|
||||||
self.startup_scripts = lbrynet_settings.startup_scripts = remaining_scripts
|
self.startup_scripts = lbrynet_settings.startup_scripts = remaining_scripts
|
||||||
conf = os.path.join(lbrynet_settings.data_dir, "daemon_settings.yml")
|
conf.save_settings()
|
||||||
utils.save_settings(conf)
|
|
||||||
|
|
||||||
for script in startup_scripts:
|
for script in startup_scripts:
|
||||||
if script['script_name'] == 'migrateto025':
|
if script['script_name'] == 'migrateto025':
|
||||||
|
|
|
@ -69,22 +69,12 @@ def start():
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
utils.setup_certs_for_windows()
|
utils.setup_certs_for_windows()
|
||||||
lbrynet_log = conf.get_log_filename()
|
|
||||||
log_support.configure_logging(lbrynet_log, args.logtoconsole, args.verbose)
|
|
||||||
|
|
||||||
to_pass = {}
|
conf.update_settings_from_file()
|
||||||
settings_path = os.path.join(settings.data_dir, "daemon_settings.yml")
|
update_settings_from_args(args)
|
||||||
if os.path.isfile(settings_path):
|
|
||||||
to_pass.update(utils.load_settings(settings_path))
|
lbrynet_log = settings.get_log_filename()
|
||||||
log.info("Loaded settings file")
|
log_support.configure_logging(lbrynet_log, args.logtoconsole, args.verbose)
|
||||||
if args.ui:
|
|
||||||
to_pass.update({'local_ui_path': args.ui})
|
|
||||||
if args.branch:
|
|
||||||
to_pass.update({'ui_branch': args.branch})
|
|
||||||
to_pass.update({'use_auth_http': args.useauth})
|
|
||||||
to_pass.update({'wallet_type': args.wallet})
|
|
||||||
log.debug('Settings overrides: %s', to_pass)
|
|
||||||
settings.update(to_pass)
|
|
||||||
log.debug('Final Settings: %s', settings.__dict__)
|
log.debug('Final Settings: %s', settings.__dict__)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -92,8 +82,6 @@ def start():
|
||||||
log.info("lbrynet-daemon is already running")
|
log.info("lbrynet-daemon is already running")
|
||||||
if not args.logtoconsole:
|
if not args.logtoconsole:
|
||||||
print "lbrynet-daemon is already running"
|
print "lbrynet-daemon is already running"
|
||||||
if args.launchui:
|
|
||||||
webbrowser.open(settings.UI_ADDRESS)
|
|
||||||
return
|
return
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
@ -120,12 +108,23 @@ def start():
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
def update_settings_from_args(args):
|
||||||
|
to_pass = {}
|
||||||
|
if args.ui:
|
||||||
|
to_pass['local_ui_path'] = args.ui
|
||||||
|
if args.branch:
|
||||||
|
to_pass['ui_branch'] = args.branch
|
||||||
|
to_pass['use_auth_http'] = args.useauth
|
||||||
|
to_pass['wallet_type'] = args.wallet
|
||||||
|
settings.update(to_pass)
|
||||||
|
|
||||||
|
|
||||||
def log_and_kill(failure):
|
def log_and_kill(failure):
|
||||||
log_support.failure(failure, log, 'Failed to startup: %s')
|
log_support.failure(failure, log, 'Failed to startup: %s')
|
||||||
reactor.stop()
|
reactor.stop()
|
||||||
|
|
||||||
|
|
||||||
def start_server_and_listen(launchui, use_auth, **kwargs):
|
def start_server_and_listen(launchui, use_auth):
|
||||||
"""The primary entry point for launching the daemon.
|
"""The primary entry point for launching the daemon.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
@ -135,7 +134,7 @@ def start_server_and_listen(launchui, use_auth, **kwargs):
|
||||||
"""
|
"""
|
||||||
lbry = DaemonServer()
|
lbry = DaemonServer()
|
||||||
|
|
||||||
d = lbry.start(**kwargs)
|
d = lbry.start()
|
||||||
d.addCallback(lambda _: listen(lbry, use_auth))
|
d.addCallback(lambda _: listen(lbry, use_auth))
|
||||||
if launchui:
|
if launchui:
|
||||||
d.addCallback(lambda _: webbrowser.open(settings.UI_ADDRESS))
|
d.addCallback(lambda _: webbrowser.open(settings.UI_ADDRESS))
|
||||||
|
|
|
@ -3,7 +3,7 @@ import os
|
||||||
|
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
|
|
||||||
from lbrynet import conf
|
from lbrynet.conf import settings
|
||||||
from lbrynet.lbrynet_daemon.Daemon import Daemon
|
from lbrynet.lbrynet_daemon.Daemon import Daemon
|
||||||
from lbrynet.lbrynet_daemon.Resources import LBRYindex, HostedEncryptedFile, EncryptedFileUpload
|
from lbrynet.lbrynet_daemon.Resources import LBRYindex, HostedEncryptedFile, EncryptedFileUpload
|
||||||
from lbrynet.conf import settings
|
from lbrynet.conf import settings
|
||||||
|
@ -14,7 +14,7 @@ log = logging.getLogger(__name__)
|
||||||
|
|
||||||
class DaemonServer(object):
|
class DaemonServer(object):
|
||||||
def _setup_server(self):
|
def _setup_server(self):
|
||||||
ui_path = os.path.join(conf.get_data_dir(), "lbry-ui", "active")
|
ui_path = os.path.join(settings.ensure_data_dir(), "lbry-ui", "active")
|
||||||
self.root = LBRYindex(ui_path)
|
self.root = LBRYindex(ui_path)
|
||||||
self._api = Daemon(self.root)
|
self._api = Daemon(self.root)
|
||||||
self.root.putChild("view", HostedEncryptedFile(self._api))
|
self.root.putChild("view", HostedEncryptedFile(self._api))
|
||||||
|
|
|
@ -57,11 +57,9 @@ class LBRYDaemonApp(AppKit.NSApplication):
|
||||||
self.statusitem.setToolTip_(settings.APP_NAME)
|
self.statusitem.setToolTip_(settings.APP_NAME)
|
||||||
|
|
||||||
if test_internet_connection():
|
if test_internet_connection():
|
||||||
if platform.mac_ver()[0] >= "10.10":
|
notify("Starting LBRY")
|
||||||
LBRYNotify("Starting LBRY")
|
|
||||||
else:
|
else:
|
||||||
if platform.mac_ver()[0] >= "10.10":
|
notify("LBRY needs an internet connection to start, try again when one is available")
|
||||||
LBRYNotify("LBRY needs an internet connection to start, try again when one is available")
|
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
DaemonControl.start_server_and_listen(launchui=True, use_auth=False)
|
DaemonControl.start_server_and_listen(launchui=True, use_auth=False)
|
||||||
|
@ -70,6 +68,10 @@ class LBRYDaemonApp(AppKit.NSApplication):
|
||||||
webbrowser.open(settings.UI_ADDRESS)
|
webbrowser.open(settings.UI_ADDRESS)
|
||||||
|
|
||||||
def replyToApplicationShouldTerminate_(self, shouldTerminate):
|
def replyToApplicationShouldTerminate_(self, shouldTerminate):
|
||||||
if platform.mac_ver()[0] >= "10.10":
|
notify("Goodbye!")
|
||||||
LBRYNotify("Goodbye!")
|
|
||||||
reactor.stop()
|
reactor.stop()
|
||||||
|
|
||||||
|
|
||||||
|
def notify(msg):
|
||||||
|
if platform.mac_ver()[0] >= "10.10":
|
||||||
|
LBRYNotify(msg)
|
||||||
|
|
|
@ -14,8 +14,9 @@ log = logging.getLogger()
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
log_file = conf.get_log_filename()
|
conf.update_settings_from_file()
|
||||||
log_support.configure_logging(log_file, console=False)
|
log_file = settings.get_log_filename()
|
||||||
|
log_support.configure_logging(log_file, console=True)
|
||||||
app = LBRYDaemonApp.sharedApplication()
|
app = LBRYDaemonApp.sharedApplication()
|
||||||
reactor.addSystemEventTrigger("after", "shutdown", AppHelper.stopEventLoop)
|
reactor.addSystemEventTrigger("after", "shutdown", AppHelper.stopEventLoop)
|
||||||
reactor.run()
|
reactor.run()
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
[Desktop Entry]
|
[Desktop Entry]
|
||||||
Version=0.7.2
|
Version=0.7.3
|
||||||
Name=LBRY
|
Name=LBRY
|
||||||
Comment=The world's first user-owned content marketplace
|
Comment=The world's first user-owned content marketplace
|
||||||
Icon=lbry
|
Icon=lbry
|
||||||
|
|
|
@ -276,8 +276,11 @@ def main(lbry_name=None):
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
utils.setup_certs_for_windows()
|
utils.setup_certs_for_windows()
|
||||||
log_file = conf.get_log_filename()
|
conf.update_settings_from_file()
|
||||||
log_support.configure_logging(log_file, console=False)
|
|
||||||
|
log_file = 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(settings.API_CONNECTION_STRING)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in a new issue