forked from LBRYCommunity/lbry-sdk
Merge remote-tracking branch 'origin/add-conf-file-flag'
This commit is contained in:
commit
7a020bec05
3 changed files with 54 additions and 3 deletions
|
@ -41,6 +41,7 @@ at anytime.
|
|||
* Add `peer_port` to settings configurable using `settings_set`
|
||||
* Added an option to disable max key fee check.
|
||||
* Add `wallet_unlock`, a command available during startup to unlock an encrypted wallet
|
||||
* Add `--conf` CLI flag to specify an alternate config file
|
||||
|
||||
### Changed
|
||||
* claim_show API command no longer takes name as argument
|
||||
|
|
|
@ -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):
|
||||
"""
|
||||
|
@ -311,6 +313,11 @@ class Config(object):
|
|||
TYPE_RUNTIME, TYPE_CLI, TYPE_ENV, TYPE_PERSISTED, TYPE_DEFAULT
|
||||
)
|
||||
|
||||
# types of data where user specified config values can be stored
|
||||
self._user_specified = (
|
||||
TYPE_RUNTIME, TYPE_CLI, TYPE_ENV, TYPE_PERSISTED
|
||||
)
|
||||
|
||||
self._data[TYPE_DEFAULT].update(self._fixed_defaults)
|
||||
self._data[TYPE_DEFAULT].update(
|
||||
{k: v[1] for (k, v) in self._adjustable_defaults.iteritems()})
|
||||
|
@ -383,6 +390,28 @@ class Config(object):
|
|||
if currency not in self._fixed_defaults['CURRENCIES'].keys():
|
||||
raise InvalidCurrencyError(currency)
|
||||
|
||||
def is_default(self, name):
|
||||
"""Check if a config value is wasn't specified by the user
|
||||
|
||||
Args:
|
||||
name: the name of the value to check
|
||||
|
||||
Returns: true if config value is the default one, false if it was specified by
|
||||
the user
|
||||
|
||||
Sometimes it may be helpful to understand if a config value was specified
|
||||
by the user or if it still holds its default value. This function will return
|
||||
true when the config value is still the default. Note that when the user
|
||||
specifies a value that is equal to the default one, it will still be considered
|
||||
as 'user specified'
|
||||
"""
|
||||
|
||||
self._assert_valid_setting(name)
|
||||
for possible_data_type in self._user_specified:
|
||||
if name in self._data[possible_data_type]:
|
||||
return False
|
||||
return True
|
||||
|
||||
def get(self, name, data_type=None):
|
||||
"""Get a config value
|
||||
|
||||
|
@ -449,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
|
||||
|
@ -457,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