Browse Source

pylightning: Merge option_values into options

Suggested-by: Rusty Russell <@rustyrussell>
Signed-off-by: Christian Decker <decker.christian@gmail.com>
plugin-6
Christian Decker 6 years ago
parent
commit
5dbc836106
No known key found for this signature in database GPG Key ID: 1416D83DC4F0E86D
  1. 15
      contrib/pylightning/lightning/plugin.py

15
contrib/pylightning/lightning/plugin.py

@ -17,7 +17,6 @@ class Plugin(object):
def __init__(self, stdout=None, stdin=None, autopatch=True): def __init__(self, stdout=None, stdin=None, autopatch=True):
self.methods = {} self.methods = {}
self.options = {} self.options = {}
self.option_values = {}
if not stdout: if not stdout:
self.stdout = sys.stdout self.stdout = sys.stdout
@ -77,16 +76,18 @@ class Plugin(object):
'default': default, 'default': default,
'description': description, 'description': description,
'type': 'string', 'type': 'string',
'value': None,
} }
def get_option(self, name): def get_option(self, name):
if name in self.option_values: if name not in self.options:
return self.option_values[name]
elif name in self.options:
return self.options[name]['default']
else:
raise ValueError("No option with name {} registered".format(name)) raise ValueError("No option with name {} registered".format(name))
if self.options[name]['value'] is not None:
return self.options[name]['value']
else:
return self.options[name]['default']
def method(self, method_name, *args, **kwargs): def method(self, method_name, *args, **kwargs):
"""Decorator to add a plugin method to the dispatch table. """Decorator to add a plugin method to the dispatch table.
@ -209,7 +210,7 @@ class Plugin(object):
self.rpc_filename = configuration['rpc-file'] self.rpc_filename = configuration['rpc-file']
self.lightning_dir = configuration['lightning-dir'] self.lightning_dir = configuration['lightning-dir']
for name, value in options.items(): for name, value in options.items():
self.option_values[name] = value self.options[name]['value'] = value
# Swap the registered `init` method handler back in and # Swap the registered `init` method handler back in and
# re-dispatch # re-dispatch

Loading…
Cancel
Save