Fix issue #930. Disallow positional arguments for CLI settings_set and fix error reporting when settings_set fails.

This commit is contained in:
rick batka 2018-02-09 11:29:37 -05:00
parent b3d3c1c93b
commit 69a99a61ba
5 changed files with 78 additions and 76 deletions

View file

@ -13,6 +13,7 @@ at anytime.
* *
### Fixed ### Fixed
* Fixed improper parsing of arguments to CLI settings_set (https://github.com/lbryio/lbry/issues/930)
* Fixed unnecessarily verbose exchange rate error (https://github.com/lbryio/lbry/issues/984) * Fixed unnecessarily verbose exchange rate error (https://github.com/lbryio/lbry/issues/984)
* Merged two separate dht test folders into one * Merged two separate dht test folders into one
* Fixed value error due to a race condition when saving to the claim cache (https://github.com/lbryio/lbry/issues/1013) * Fixed value error due to a race condition when saving to the claim cache (https://github.com/lbryio/lbry/issues/1013)
@ -29,6 +30,7 @@ at anytime.
* `get_availability`, replaced with `stream_availability` * `get_availability`, replaced with `stream_availability`
### Changed ### Changed
* Removed support for positional arguments in cli `settings_set`. Now only accepts settings changes in the form `--setting_key=value`
* Check claim schema in `publish` before trying to make the claim, return better error messages * Check claim schema in `publish` before trying to make the claim, return better error messages
* Renamed `channel_list_mine` to `channel_list` * Renamed `channel_list_mine` to `channel_list`
* Changed `channel_list` to include channels where the certificate info has been imported but the claim is not in the wallet * Changed `channel_list` to include channels where the certificate info has been imported but the claim is not in the wallet

View file

@ -832,28 +832,27 @@ Returns:
Set daemon settings Set daemon settings
Usage: Usage:
settings_set [<download_directory> | --download_directory=<download_directory>] settings_set [--download_directory=<download_directory>]
[<data_rate> | --data_rate=<data_rate>] [--data_rate=<data_rate>]
[<download_timeout> | --download_timeout=<download_timeout>] [--download_timeout=<download_timeout>]
[<peer_port> | --peer_port=<peer_port>] [--peer_port=<peer_port>]
[<max_key_fee> | --max_key_fee=<max_key_fee>] [--max_key_fee=<max_key_fee>]
[<disable_max_key_fee> | --disable_max_key_fee=<disable_max_key_fee>] [--disable_max_key_fee=<disable_max_key_fee>]
[<use_upnp> | --use_upnp=<use_upnp>] [--use_upnp=<use_upnp>]
[<run_reflector_server> | --run_reflector_server=<run_reflector_server>] [--run_reflector_server=<run_reflector_server>]
[<cache_time> | --cache_time=<cache_time>] [--cache_time=<cache_time>]
[<reflect_uploads> | --reflect_uploads=<reflect_uploads>] [--reflect_uploads=<reflect_uploads>]
[<share_usage_data> | --share_usage_data=<share_usage_data>] [--share_usage_data=<share_usage_data>]
[<peer_search_timeout> | --peer_search_timeout=<peer_search_timeout>] [--peer_search_timeout=<peer_search_timeout>]
[<sd_download_timeout> | --sd_download_timeout=<sd_download_timeout>] [--sd_download_timeout=<sd_download_timeout>]
[<auto_renew_claim_height_delta> [--auto_renew_claim_height_delta=<auto_renew_claim_height_delta>]
| --auto_renew_claim_height_delta=<auto_renew_claim_height_delta]
Options: Options:
<download_directory>, --download_directory=<download_directory> : (str) --download_directory=<download_directory> : (str)
<data_rate>, --data_rate=<data_rate> : (float), 0.0001 --data_rate=<data_rate> : (float), 0.0001
<download_timeout>, --download_timeout=<download_timeout> : (int), 180 --download_timeout=<download_timeout> : (int), 180
<peer_port>, --peer_port=<peer_port> : (int), 3333 --peer_port=<peer_port> : (int), 3333
<max_key_fee>, --max_key_fee=<max_key_fee> : (dict) maximum key fee for downloads, --max_key_fee=<max_key_fee> : (dict) maximum key fee for downloads,
in the format: { in the format: {
"currency": <currency_symbol>, "currency": <currency_symbol>,
"amount": <amount> "amount": <amount>
@ -863,16 +862,15 @@ Options:
LBC LBC
BTC BTC
USD USD
<disable_max_key_fee>, --disable_max_key_fee=<disable_max_key_fee> : (bool), False --disable_max_key_fee=<disable_max_key_fee> : (bool), False
<use_upnp>, --use_upnp=<use_upnp> : (bool), True --use_upnp=<use_upnp> : (bool), True
<run_reflector_server>, --run_reflector_server=<run_reflector_server> : (bool), False --run_reflector_server=<run_reflector_server> : (bool), False
<cache_time>, --cache_time=<cache_time> : (int), 150 --cache_time=<cache_time> : (int), 150
<reflect_uploads>, --reflect_uploads=<reflect_uploads> : (bool), True --reflect_uploads=<reflect_uploads> : (bool), True
<share_usage_data>, --share_usage_data=<share_usage_data> : (bool), True --share_usage_data=<share_usage_data> : (bool), True
<peer_search_timeout>, --peer_search_timeout=<peer_search_timeout> : (int), 3 --peer_search_timeout=<peer_search_timeout> : (int), 3
<sd_download_timeout>, --sd_download_timeout=<sd_download_timeout> : (int), 3 --sd_download_timeout=<sd_download_timeout> : (int), 3
<auto_renew_claim_height_delta>, --auto_renew_claim_height_delta=<auto_renew_claim_height_delta> : (int), 0
--auto_renew_claim_height_delta=<auto_renew_claim_height_delta> : (int), 0
claims set to expire within this many blocks will be claims set to expire within this many blocks will be
automatically renewed after startup (if set to 0, renews automatically renewed after startup (if set to 0, renews
will not be made automatically) will not be made automatically)

View file

@ -8,7 +8,7 @@ import yaml
import envparse import envparse
from appdirs import user_data_dir, user_config_dir from appdirs import user_data_dir, user_config_dir
from lbrynet.core import utils from lbrynet.core import utils
from lbrynet.core.Error import InvalidCurrencyError from lbrynet.core.Error import InvalidCurrencyError, NoSuchDirectoryError
from lbrynet.androidhelpers.paths import ( from lbrynet.androidhelpers.paths import (
android_internal_storage_dir, android_internal_storage_dir,
android_app_internal_storage_dir android_app_internal_storage_dir
@ -392,9 +392,15 @@ class Config(object):
if name in self._fixed_defaults: if name in self._fixed_defaults:
raise ValueError('{} is not an editable setting'.format(name)) raise ValueError('{} is not an editable setting'.format(name))
def _validate_currency(self, currency): def _assert_valid_setting_value(self, name, value):
if currency not in self._fixed_defaults['CURRENCIES'].keys(): if name == "max_key_fee":
raise InvalidCurrencyError(currency) currency = str(value["currency"]).upper()
if currency not in self._fixed_defaults['CURRENCIES'].keys():
raise InvalidCurrencyError(currency)
elif name == "download_directory":
directory = str(value)
if not os.path.exists(directory):
raise NoSuchDirectoryError(directory)
def is_default(self, name): def is_default(self, name):
"""Check if a config value is wasn't specified by the user """Check if a config value is wasn't specified by the user
@ -455,11 +461,9 @@ class Config(object):
data types (e.g. PERSISTED values to save to a file, CLI values from parsed data types (e.g. PERSISTED values to save to a file, CLI values from parsed
command-line options, etc), you can specify that with the data_types param command-line options, etc), you can specify that with the data_types param
""" """
if name == "max_key_fee":
currency = str(value["currency"]).upper()
self._validate_currency(currency)
self._assert_editable_setting(name) self._assert_editable_setting(name)
self._assert_valid_setting_value(name, value)
for data_type in data_types: for data_type in data_types:
self._assert_valid_data_type(data_type) self._assert_valid_data_type(data_type)
self._data[data_type][name] = value self._data[data_type][name] = value

View file

@ -160,3 +160,8 @@ class InvalidCurrencyError(Exception):
self.currency = currency self.currency = currency
Exception.__init__( Exception.__init__(
self, 'Invalid currency: {} is not a supported currency.'.format(currency)) self, 'Invalid currency: {} is not a supported currency.'.format(currency))
class NoSuchDirectoryError(Exception):
def __init__(self, directory):
self.directory = directory
Exception.__init__(self, 'No such directory {}'.format(directory))

View file

@ -453,14 +453,9 @@ class Daemon(AuthJSONRPCServer):
conf.settings.update({key: decoded}, conf.settings.update({key: decoded},
data_types=(conf.TYPE_RUNTIME, conf.TYPE_PERSISTED)) data_types=(conf.TYPE_RUNTIME, conf.TYPE_PERSISTED))
else: else:
try: converted = setting_type(settings[key])
converted = setting_type(settings[key]) conf.settings.update({key: converted},
conf.settings.update({key: converted}, data_types=(conf.TYPE_RUNTIME, conf.TYPE_PERSISTED))
data_types=(conf.TYPE_RUNTIME, conf.TYPE_PERSISTED))
except Exception as err:
log.warning(err.message)
log.warning("error converting setting '%s' to type %s from type %s", key,
setting_type, str(type(settings[key])))
conf.settings.save_conf_file_settings() conf.settings.save_conf_file_settings()
self.data_rate = conf.settings['data_rate'] self.data_rate = conf.settings['data_rate']
@ -1190,28 +1185,27 @@ class Daemon(AuthJSONRPCServer):
Set daemon settings Set daemon settings
Usage: Usage:
settings_set [<download_directory> | --download_directory=<download_directory>] settings_set [--download_directory=<download_directory>]
[<data_rate> | --data_rate=<data_rate>] [--data_rate=<data_rate>]
[<download_timeout> | --download_timeout=<download_timeout>] [--download_timeout=<download_timeout>]
[<peer_port> | --peer_port=<peer_port>] [--peer_port=<peer_port>]
[<max_key_fee> | --max_key_fee=<max_key_fee>] [--max_key_fee=<max_key_fee>]
[<disable_max_key_fee> | --disable_max_key_fee=<disable_max_key_fee>] [--disable_max_key_fee=<disable_max_key_fee>]
[<use_upnp> | --use_upnp=<use_upnp>] [--use_upnp=<use_upnp>]
[<run_reflector_server> | --run_reflector_server=<run_reflector_server>] [--run_reflector_server=<run_reflector_server>]
[<cache_time> | --cache_time=<cache_time>] [--cache_time=<cache_time>]
[<reflect_uploads> | --reflect_uploads=<reflect_uploads>] [--reflect_uploads=<reflect_uploads>]
[<share_usage_data> | --share_usage_data=<share_usage_data>] [--share_usage_data=<share_usage_data>]
[<peer_search_timeout> | --peer_search_timeout=<peer_search_timeout>] [--peer_search_timeout=<peer_search_timeout>]
[<sd_download_timeout> | --sd_download_timeout=<sd_download_timeout>] [--sd_download_timeout=<sd_download_timeout>]
[<auto_renew_claim_height_delta> [--auto_renew_claim_height_delta=<auto_renew_claim_height_delta>]
| --auto_renew_claim_height_delta=<auto_renew_claim_height_delta]
Options: Options:
<download_directory>, --download_directory=<download_directory> : (str) --download_directory=<download_directory> : (str)
<data_rate>, --data_rate=<data_rate> : (float), 0.0001 --data_rate=<data_rate> : (float), 0.0001
<download_timeout>, --download_timeout=<download_timeout> : (int), 180 --download_timeout=<download_timeout> : (int), 180
<peer_port>, --peer_port=<peer_port> : (int), 3333 --peer_port=<peer_port> : (int), 3333
<max_key_fee>, --max_key_fee=<max_key_fee> : (dict) maximum key fee for downloads, --max_key_fee=<max_key_fee> : (dict) maximum key fee for downloads,
in the format: { in the format: {
"currency": <currency_symbol>, "currency": <currency_symbol>,
"amount": <amount> "amount": <amount>
@ -1221,16 +1215,15 @@ class Daemon(AuthJSONRPCServer):
LBC LBC
BTC BTC
USD USD
<disable_max_key_fee>, --disable_max_key_fee=<disable_max_key_fee> : (bool), False --disable_max_key_fee=<disable_max_key_fee> : (bool), False
<use_upnp>, --use_upnp=<use_upnp> : (bool), True --use_upnp=<use_upnp> : (bool), True
<run_reflector_server>, --run_reflector_server=<run_reflector_server> : (bool), False --run_reflector_server=<run_reflector_server> : (bool), False
<cache_time>, --cache_time=<cache_time> : (int), 150 --cache_time=<cache_time> : (int), 150
<reflect_uploads>, --reflect_uploads=<reflect_uploads> : (bool), True --reflect_uploads=<reflect_uploads> : (bool), True
<share_usage_data>, --share_usage_data=<share_usage_data> : (bool), True --share_usage_data=<share_usage_data> : (bool), True
<peer_search_timeout>, --peer_search_timeout=<peer_search_timeout> : (int), 3 --peer_search_timeout=<peer_search_timeout> : (int), 3
<sd_download_timeout>, --sd_download_timeout=<sd_download_timeout> : (int), 3 --sd_download_timeout=<sd_download_timeout> : (int), 3
<auto_renew_claim_height_delta>, --auto_renew_claim_height_delta=<auto_renew_claim_height_delta> : (int), 0
--auto_renew_claim_height_delta=<auto_renew_claim_height_delta> : (int), 0
claims set to expire within this many blocks will be claims set to expire within this many blocks will be
automatically renewed after startup (if set to 0, renews automatically renewed after startup (if set to 0, renews
will not be made automatically) will not be made automatically)