diff options
author | Devaev Maxim <[email protected]> | 2020-09-10 09:57:12 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2020-09-10 09:58:31 +0300 |
commit | ec6d13dc34071bf6673e532d767c25219ba52327 (patch) | |
tree | 15fe321ed2c92012ab3adf660a66b2fd23f06d7b /kvmd | |
parent | 9cb5582565aa2301a238ca382a32dc80106f6c15 (diff) |
refactoring
Diffstat (limited to 'kvmd')
-rw-r--r-- | kvmd/apps/__init__.py | 16 | ||||
-rw-r--r-- | kvmd/plugins/msd/otg/__init__.py | 3 | ||||
-rw-r--r-- | kvmd/tools.py | 6 |
3 files changed, 16 insertions, 9 deletions
diff --git a/kvmd/apps/__init__.py b/kvmd/apps/__init__.py index a1bdb916..1932265a 100644 --- a/kvmd/apps/__init__.py +++ b/kvmd/apps/__init__.py @@ -259,7 +259,7 @@ def _get_config_scheme() -> Dict: "unix_rm": Option(True, type=valid_bool), "unix_mode": Option(0o660, type=valid_unix_mode), "heartbeat": Option(3.0, type=valid_float_f01), - "sync_chunk_size": Option(65536, type=(lambda arg: valid_number(arg, min=1024))), + "sync_chunk_size": Option(65536, type=functools.partial(valid_number, min=1024)), "access_log_format": Option("[%P / %{X-Real-IP}i] '%r' => %s; size=%b ---" " referer='%{Referer}i'; user_agent='%{User-Agent}i'"), }, @@ -284,14 +284,14 @@ def _get_config_scheme() -> Dict: "extras": Option("/usr/share/kvmd/extras", type=valid_abs_dir), "hw": { "vcgencmd_cmd": Option(["/opt/vc/bin/vcgencmd"], type=valid_command), - "procfs_prefix": Option("", type=(lambda arg: str(arg).strip())), - "sysfs_prefix": Option("", type=(lambda arg: str(arg).strip())), + "procfs_prefix": Option("", type=tools.str_strip), + "sysfs_prefix": Option("", type=tools.str_strip), "state_poll": Option(10.0, type=valid_float_f01), }, }, "wol": { - "ip": Option("255.255.255.255", type=(lambda arg: valid_ip(arg, v6=False))), + "ip": Option("255.255.255.255", type=functools.partial(valid_ip, v6=False)), "port": Option(9, type=valid_port), "mac": Option("", type=(lambda arg: (valid_mac(arg) if arg else ""))), }, @@ -326,7 +326,7 @@ def _get_config_scheme() -> Dict: "desired_fps": Option(30, type=valid_stream_fps), "max_fps": Option(60, type=valid_stream_fps), "resolution": Option("", type=(lambda arg: (valid_stream_resolution(arg) if arg else ""))), - "available_resolutions": Option([], type=(lambda arg: valid_string_list(arg, subval=valid_stream_resolution))), + "available_resolutions": Option([], type=functools.partial(valid_string_list, subval=valid_stream_resolution)), "host": Option("localhost", type=valid_ip_or_host), "port": Option(0, type=valid_port), @@ -433,9 +433,9 @@ def _get_config_scheme() -> Dict: "no_delay": Option(True, type=valid_bool), "keepalive": { "enabled": Option(True, type=valid_bool, unpack_as="keepalive_enabled"), - "idle": Option(10, type=(lambda arg: valid_number(arg, min=1, max=3600)), unpack_as="keepalive_idle"), - "interval": Option(3, type=(lambda arg: valid_number(arg, min=1, max=60)), unpack_as="keepalive_interval"), - "count": Option(3, type=(lambda arg: valid_number(arg, min=1, max=10)), unpack_as="keepalive_count"), + "idle": Option(10, type=functools.partial(valid_number, min=1, max=3600), unpack_as="keepalive_idle"), + "interval": Option(3, type=functools.partial(valid_number, min=1, max=60), unpack_as="keepalive_interval"), + "count": Option(3, type=functools.partial(valid_number, min=1, max=10), unpack_as="keepalive_count"), }, "tls": { diff --git a/kvmd/plugins/msd/otg/__init__.py b/kvmd/plugins/msd/otg/__init__.py index bb5ebd66..2c795970 100644 --- a/kvmd/plugins/msd/otg/__init__.py +++ b/kvmd/plugins/msd/otg/__init__.py @@ -44,6 +44,7 @@ from ....yamlconf import Option from ....validators.os import valid_abs_dir from ....validators.os import valid_command +from .... import tools from .... import aiotools from .... import aiofs @@ -169,7 +170,7 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes "storage": Option("/var/lib/kvmd/msd", type=valid_abs_dir, unpack_as="storage_path"), "remount_cmd": Option([*sudo, "/usr/bin/kvmd-helper-otgmsd-remount", "{mode}"], type=valid_command), "unlock_cmd": Option([*sudo, "/usr/bin/kvmd-helper-otgmsd-unlock", "unlock"], type=valid_command), - "sysfs_prefix": Option("", type=(lambda arg: str(arg).strip())), + "sysfs_prefix": Option("", type=tools.str_strip), } async def get_state(self) -> Dict: diff --git a/kvmd/tools.py b/kvmd/tools.py index 6d10e227..679a7e8d 100644 --- a/kvmd/tools.py +++ b/kvmd/tools.py @@ -28,6 +28,12 @@ from typing import List from typing import Dict from typing import Hashable from typing import TypeVar +from typing import Any + + +# ===== +def str_strip(arg: Any) -> str: + return str(arg).strip() # ===== |