From 34976c76021748db7fdfa30ca7d787680e0a6289 Mon Sep 17 00:00:00 2001 From: Antonio Quartulli Date: Mon, 29 Jan 2018 16:05:11 +0800 Subject: [PATCH 1/2] DaemonCLI: add --conf flag When starting a daemon with a different configuration, the same should also be used by the cli tool. Add the --conf flag to the cli command to allow using a custom config file. Signed-off-by: Antonio Quartulli --- CHANGELOG.md | 1 + lbrynet/daemon/DaemonCLI.py | 29 ++++++++++++++++++++++------- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 54e777a2a..e8b1ed089 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,6 +56,7 @@ at anytime. * Added abandon information (claim name, id, address, amount, balance_delta and nout) about claims, supports, and updates to `transaction_list` results under `abandon_info` key * Added `permanent_url` attribute to `channel_list_mine`, `claim_list`, `claim_show`, `resolve` and `resolve_name` API calls through lbryio/lbryum#203 * + * Added `--conf` CLI flag to lbrynet-cli tool to specify an alternative config file ### Changed * claim_show API command no longer takes name as argument diff --git a/lbrynet/daemon/DaemonCLI.py b/lbrynet/daemon/DaemonCLI.py index fe16806fa..af954dbb0 100644 --- a/lbrynet/daemon/DaemonCLI.py +++ b/lbrynet/daemon/DaemonCLI.py @@ -38,8 +38,22 @@ def set_flag_vals(flag_names, parsed_args): def main(): - if len(sys.argv[1:]): - method, args = sys.argv[1], sys.argv[2:] + argv = sys.argv[1:] + + # check if a config file has been specified. If so, shift + # all the arguments so that the parsing can continue without + # noticing + if len(argv) and argv[0] == "--conf": + if len(argv) < 2: + print_error("No config file specified for --conf option") + print_help() + return + + conf.conf_file = argv[1] + argv = argv[2:] + + if len(argv): + method, args = argv[0], argv[1:] else: print_help() return @@ -176,13 +190,14 @@ def print_help(): " lbrynet-cli - LBRY command line client.", "", "USAGE", - " lbrynet-cli []", + " lbrynet-cli [--conf ] []", "", "EXAMPLES", - " lbrynet-cli commands # list available commands", - " lbrynet-cli status # get daemon status", - " lbrynet-cli resolve_name what # resolve a name", - " lbrynet-cli help resolve_name # get help for a command", + " lbrynet-cli commands # list available commands", + " lbrynet-cli status # get daemon status", + " lbrynet-cli --conf ~/l1.conf status # like above but using ~/l1.conf as config file", + " lbrynet-cli resolve_name what # resolve a name", + " lbrynet-cli help resolve_name # get help for a command", ]) From 639744e047e745b7eeaa92090a54cadceaebc559 Mon Sep 17 00:00:00 2001 From: Antonio Quartulli Date: Mon, 29 Jan 2018 17:16:41 +0800 Subject: [PATCH 2/2] conf: initialize IDs after reading config file Installation_id and node_id are stored in the data dir. For this reason they should be read/created only after the config has been parsed. This way they can be retrieved or stored at the right location. Signed-off-by: Antonio Quartulli --- lbrynet/conf.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lbrynet/conf.py b/lbrynet/conf.py index 94b4eb941..cbeaac87f 100644 --- a/lbrynet/conf.py +++ b/lbrynet/conf.py @@ -509,6 +509,10 @@ class Config(object): converted[k] = v return converted + def initialize_post_conf_load(self): + settings.installation_id = settings.get_installation_id() + settings.node_id = settings.get_node_id() + def load_conf_file_settings(self): if conf_file: path = conf_file @@ -528,6 +532,9 @@ class Config(object): except (IOError, OSError) as err: log.info('%s: Failed to update settings from %s', err, path) + #initialize members depending on config file + self.initialize_post_conf_load() + def _fix_old_conf_file_settings(self, settings_dict): if 'API_INTERFACE' in settings_dict: settings_dict['api_host'] = settings_dict['API_INTERFACE'] @@ -628,7 +635,5 @@ def initialize_settings(load_conf_file=True): if settings is None: settings = Config(FIXED_SETTINGS, ADJUSTABLE_SETTINGS, environment=get_default_env()) - settings.installation_id = settings.get_installation_id() - settings.node_id = settings.get_node_id() if load_conf_file: settings.load_conf_file_settings()