From 32cc077e1f9988046b8ebe8b731ced5bea911e4b Mon Sep 17 00:00:00 2001 From: Miroslav Kovar Date: Sun, 8 Sep 2019 15:44:54 +0200 Subject: [PATCH] enable to set max_key_fee to null via cli --- lbry/lbry/conf.py | 14 +++++++++----- lbry/tests/unit/test_conf.py | 13 +++++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/lbry/lbry/conf.py b/lbry/lbry/conf.py index de2ad6864..4beb4b34d 100644 --- a/lbry/lbry/conf.py +++ b/lbry/lbry/conf.py @@ -148,7 +148,10 @@ class MaxKeyFee(Setting[dict]): @staticmethod def _parse_list(l): - assert len(l) == 2, 'Max key fee is made up of two values: "AMOUNT CURRENCY".' + if len(l) == 1 and (l[0] == 'null' or not l[0]): + return None + assert len(l) == 2, ('Max key fee is made up of either two values: ' + '"AMOUNT CURRENCY", or "null" (to set no limit)') try: amount = float(l[0]) except ValueError: @@ -159,8 +162,8 @@ class MaxKeyFee(Setting[dict]): return {'amount': amount, 'currency': currency} def deserialize(self, value): - if value is None: - return + if not value: + return None if isinstance(value, dict): return { 'currency': value['currency'], @@ -176,7 +179,7 @@ class MaxKeyFee(Setting[dict]): parser.add_argument( self.cli_name, help=self.doc, - nargs=2, + nargs='+', metavar=('AMOUNT', 'CURRENCY'), default=NOT_SET ) @@ -527,7 +530,8 @@ class Config(CLIConfig): "peers are not found or are slow", 2.0 ) max_key_fee = MaxKeyFee( - "Don't download streams with fees exceeding this amount", {'currency': 'USD', 'amount': 50.0} + "Don't download streams with fees exceeding this amount. When set to " + "null, the amount is unbounded.", {'currency': 'USD', 'amount': 50.0} ) # reflector settings diff --git a/lbry/tests/unit/test_conf.py b/lbry/tests/unit/test_conf.py index dd5d62721..17a347a1a 100644 --- a/lbry/tests/unit/test_conf.py +++ b/lbry/tests/unit/test_conf.py @@ -207,6 +207,11 @@ class ConfigurationTests(unittest.TestCase): c.max_key_fee = None with open(config, 'r') as fd: self.assertEqual(fd.read(), 'max_key_fee: null\n') + c = Config.create_from_arguments( + types.SimpleNamespace(config=config) + ) + with open(config, 'r') as fd: + self.assertEqual(c.max_key_fee, None) def test_max_key_fee_from_args(self): parser = argparse.ArgumentParser() @@ -222,6 +227,14 @@ class ConfigurationTests(unittest.TestCase): c = Config.create_from_arguments(args) self.assertEqual(c.max_key_fee, None) + args = parser.parse_args(['--max-key-fee', 'null']) + c = Config.create_from_arguments(args) + self.assertEqual(c.max_key_fee, None) + + args = parser.parse_args(['--max-key-fee', '']) + c = Config.create_from_arguments(args) + self.assertEqual(c.max_key_fee, None) + # set args = parser.parse_args(['--max-key-fee', '1.0', 'BTC']) c = Config.create_from_arguments(args)