diff options
author | Devaev Maxim <[email protected]> | 2020-09-08 12:13:44 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2020-09-08 12:13:44 +0300 |
commit | d932a937caede7f54c0f4384ce08f7ecc291af23 (patch) | |
tree | 4456fa977af7efd026cc1b8ccf415f87a3ea952f /kvmd/apps | |
parent | 7098eab2585bfb64992e50c0ebb64141cc2bd925 (diff) |
validate drivers
Diffstat (limited to 'kvmd/apps')
-rw-r--r-- | kvmd/apps/__init__.py | 10 | ||||
-rw-r--r-- | kvmd/apps/kvmd/ugpio.py | 4 |
2 files changed, 10 insertions, 4 deletions
diff --git a/kvmd/apps/__init__.py b/kvmd/apps/__init__.py index a4babdbf..4afd6b3a 100644 --- a/kvmd/apps/__init__.py +++ b/kvmd/apps/__init__.py @@ -52,6 +52,8 @@ from ..yamlconf import build_raw_from_options from ..yamlconf.dumper import make_config_dump from ..yamlconf.loader import load_yaml_file +from ..validators import check_string_in_list + from ..validators.basic import valid_stripped_string from ..validators.basic import valid_stripped_string_not_empty from ..validators.basic import valid_bool @@ -179,6 +181,7 @@ def _patch_dynamic( # pylint: disable=too-many-locals rebuild = True if load_gpio: + drivers: List[str] = [] for (driver, params) in { # type: ignore "__gpio__": {}, **tools.rget(raw_config, "kvmd", "gpio", "drivers"), @@ -189,12 +192,17 @@ def _patch_dynamic( # pylint: disable=too-many-locals "type": Option(driver_type, type=valid_stripped_string_not_empty), **get_ugpio_driver_class(driver_type).get_plugin_options() } + drivers.append(driver) for (channel, params) in tools.rget(raw_config, "kvmd", "gpio", "scheme").items(): channel = valid_ugpio_channel(channel) mode = valid_ugpio_mode(params.get("mode", "")) scheme["kvmd"]["gpio"]["scheme"][channel] = { - "driver": Option("__gpio__"), + "driver": Option("__gpio__", type=(lambda arg: check_string_in_list( + arg=valid_stripped_string_not_empty(arg), + name="configured GPIO driver", + variants=drivers, + ))), "pin": Option(-1, type=valid_gpio_pin), "mode": Option("", type=valid_ugpio_mode), "inverted": Option(False, type=valid_bool), diff --git a/kvmd/apps/kvmd/ugpio.py b/kvmd/apps/kvmd/ugpio.py index b678cd0b..c51b4c81 100644 --- a/kvmd/apps/kvmd/ugpio.py +++ b/kvmd/apps/kvmd/ugpio.py @@ -235,9 +235,7 @@ class UserGpio: self.__outputs: Dict[str, _GpioOutput] = {} for (channel, ch_config) in sorted(config.scheme.items(), key=operator.itemgetter(0)): - driver = self.__drivers.get(ch_config.driver) - if driver is None: - raise RuntimeError(f"Missing User-GPIO driver configuration: {ch_config.driver}") + driver = self.__drivers[ch_config.driver] if ch_config.mode == "input": self.__inputs[channel] = _GpioInput(channel, ch_config, driver) else: # output: |