forked from LBRYCommunity/lbry-sdk
Initialize settings, along with lbryid and session_id on startup
This commit is contained in:
parent
39b2e44492
commit
8f61fb3fc4
6 changed files with 34 additions and 8 deletions
|
@ -1,3 +1,4 @@
|
|||
import base58
|
||||
import copy
|
||||
import json
|
||||
import logging
|
||||
|
@ -8,6 +9,9 @@ import yaml
|
|||
from appdirs import user_data_dir
|
||||
import envparse
|
||||
|
||||
from lbrynet.core import utils
|
||||
|
||||
|
||||
LBRYCRD_WALLET = 'lbrycrd'
|
||||
LBRYUM_WALLET = 'lbryum'
|
||||
PTC_WALLET = 'ptc'
|
||||
|
@ -366,9 +370,23 @@ def save_settings(path=None):
|
|||
settings_file.write(encoder(to_save))
|
||||
|
||||
|
||||
# TODO: don't load the configuration automatically. The configuration
|
||||
# should be loaded at runtime, not at module import time. Module
|
||||
# import should have no side-effects. This is also bad because
|
||||
# it means that settings are read from the environment even for
|
||||
# tests, which is rarely what you want to happen.
|
||||
settings = Config()
|
||||
settings = None
|
||||
|
||||
|
||||
def initialize_settings():
|
||||
global settings
|
||||
settings = Config()
|
||||
settings.lbryid = get_lbryid()
|
||||
settings.session_id = base58.b58encode(utils.generate_id())
|
||||
|
||||
|
||||
def get_lbryid():
|
||||
lbryid_filename = os.path.join(settings.ensure_data_dir(), "lbryid")
|
||||
if os.path.isfile(lbryid_filename):
|
||||
with open(lbryid_filename, "r") as lbryid_file:
|
||||
return base58.b58decode(lbryid_file.read())
|
||||
else:
|
||||
lbryid = utils.generate_id()
|
||||
with open(lbryid_filename, "w") as lbryid_file:
|
||||
lbryid_file.write(base58.b58encode(lbryid))
|
||||
return lbryid
|
||||
|
|
|
@ -259,14 +259,14 @@ class Daemon(AuthJSONRPCServer):
|
|||
self.db_revision_file = conf.settings.get_db_revision_filename()
|
||||
self.session = None
|
||||
self.uploaded_temp_files = []
|
||||
self._session_id = base58.b58encode(utils.generate_id())
|
||||
self._session_id = conf.settings.session_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
|
||||
self.log_uploader = log_support.LogUploader.load('lbrynet', self.log_file)
|
||||
|
||||
self.analytics_manager = analytics_manager
|
||||
self.lbryid = PENDING_ID
|
||||
self.lbryid = conf.settings.lbryid
|
||||
self.daemon_conf = conf.settings.get_conf_filename()
|
||||
|
||||
self.wallet_user = None
|
||||
|
|
|
@ -63,6 +63,7 @@ def start():
|
|||
'should selectively be applied.'))
|
||||
args = parser.parse_args()
|
||||
|
||||
conf.initialize_settings()
|
||||
utils.setup_certs_for_windows()
|
||||
|
||||
conf.update_settings_from_file()
|
||||
|
|
|
@ -14,6 +14,7 @@ log = logging.getLogger()
|
|||
|
||||
|
||||
def main():
|
||||
conf.initialize_settings()
|
||||
conf.update_settings_from_file()
|
||||
log_file = conf.settings.get_log_filename()
|
||||
log_support.configure_logging(log_file, console=True)
|
||||
|
|
|
@ -276,6 +276,7 @@ def main(lbry_name=None):
|
|||
|
||||
if __name__ == '__main__':
|
||||
utils.setup_certs_for_windows()
|
||||
conf.initialize_settings()
|
||||
conf.update_settings_from_file()
|
||||
|
||||
log_file = conf.settings.get_log_filename()
|
||||
|
|
|
@ -2,3 +2,8 @@
|
|||
# and so we need to ensure that it is also
|
||||
# setup for the tests
|
||||
from lbrynet.core import log_support
|
||||
from lbrynet import conf
|
||||
|
||||
|
||||
# TODO: stop doing this, would be better to mock out the settings
|
||||
conf.initialize_settings()
|
||||
|
|
Loading…
Reference in a new issue