conf: make config file a CLI parameter
The config file might be stores in an alternate location for several reasons (i.e. testing different configs or running multiple nodes on the same host). Make the config file a CLI parameter so that it can be specified when launching the lbrynet-daemon. Related to #1039 Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
This commit is contained in:
parent
0d3493ef73
commit
79054037a7
2 changed files with 26 additions and 3 deletions
|
@ -56,6 +56,8 @@ settings_encoders = {
|
|||
'.yml': yaml.safe_dump
|
||||
}
|
||||
|
||||
# set by CLI when the user specifies an alternate config file path
|
||||
conf_file = None
|
||||
|
||||
def _win_path_to_bytes(path):
|
||||
"""
|
||||
|
@ -476,7 +478,11 @@ class Config(object):
|
|||
}
|
||||
|
||||
def save_conf_file_settings(self):
|
||||
path = self.get_conf_filename()
|
||||
if conf_file:
|
||||
path = conf_file
|
||||
else:
|
||||
path = self.get_conf_filename()
|
||||
|
||||
ext = os.path.splitext(path)[1]
|
||||
encoder = settings_encoders.get(ext, False)
|
||||
assert encoder is not False, 'Unknown settings format %s' % ext
|
||||
|
@ -484,7 +490,11 @@ class Config(object):
|
|||
settings_file.write(encoder(self._data[TYPE_PERSISTED]))
|
||||
|
||||
def load_conf_file_settings(self):
|
||||
path = self.get_conf_filename()
|
||||
if conf_file:
|
||||
path = conf_file
|
||||
else:
|
||||
path = self.get_conf_filename()
|
||||
|
||||
ext = os.path.splitext(path)[1]
|
||||
decoder = settings_decoders.get(ext, False)
|
||||
assert decoder is not False, 'Unknown settings format %s' % ext
|
||||
|
|
|
@ -20,9 +20,18 @@ def test_internet_connection():
|
|||
|
||||
def start():
|
||||
"""The primary entry point for launching the daemon."""
|
||||
conf.initialize_settings()
|
||||
|
||||
# postpone loading the config file to after the CLI arguments
|
||||
# have been parsed, as they may contain an alternate config file location
|
||||
conf.initialize_settings(load_conf_file=False)
|
||||
|
||||
parser = argparse.ArgumentParser(description="Launch lbrynet-daemon")
|
||||
parser.add_argument(
|
||||
"--conf",
|
||||
help="specify an alternative configuration file",
|
||||
type=str,
|
||||
default=None
|
||||
)
|
||||
parser.add_argument(
|
||||
"--wallet",
|
||||
help="lbryum or ptc for testing, default lbryum",
|
||||
|
@ -49,6 +58,8 @@ def start():
|
|||
args = parser.parse_args()
|
||||
update_settings_from_args(args)
|
||||
|
||||
conf.settings.load_conf_file_settings()
|
||||
|
||||
if args.version:
|
||||
version = system_info.get_platform(get_ip=False)
|
||||
version['installation_id'] = conf.settings.installation_id
|
||||
|
@ -83,6 +94,8 @@ def update_settings_from_args(args):
|
|||
'wallet': args.wallet,
|
||||
}, data_types=(conf.TYPE_CLI,))
|
||||
|
||||
conf.conf_file = args.conf
|
||||
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def start_server_and_listen(use_auth, analytics_manager):
|
||||
|
|
Loading…
Reference in a new issue