mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-12 09:10:30 +08:00
validate drivers
This commit is contained in:
parent
7098eab258
commit
d932a937ca
@ -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),
|
||||
|
||||
@ -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:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user