diff --git a/lbrynet/conf.py b/lbrynet/conf.py index 014019806..3fad69588 100644 --- a/lbrynet/conf.py +++ b/lbrynet/conf.py @@ -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 diff --git a/lbrynet/daemon/DaemonControl.py b/lbrynet/daemon/DaemonControl.py index db60ce01c..2638bca4b 100644 --- a/lbrynet/daemon/DaemonControl.py +++ b/lbrynet/daemon/DaemonControl.py @@ -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):