diff options
author | Maxim Devaev <[email protected]> | 2022-04-18 12:46:18 +0300 |
---|---|---|
committer | Maxim Devaev <[email protected]> | 2022-04-18 12:46:18 +0300 |
commit | b4aeb866491c01b8ce8768039f1f315cce88400a (patch) | |
tree | 4a503f9800e86a2a5ff230213684d6042104979d /kvmd/apps/otg/__init__.py | |
parent | e83764c501ee64a2ba513d071031b7d2320d7b10 (diff) |
refactoring
Diffstat (limited to 'kvmd/apps/otg/__init__.py')
-rw-r--r-- | kvmd/apps/otg/__init__.py | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/kvmd/apps/otg/__init__.py b/kvmd/apps/otg/__init__.py index 44b1bd84..cbf7a197 100644 --- a/kvmd/apps/otg/__init__.py +++ b/kvmd/apps/otg/__init__.py @@ -31,6 +31,7 @@ from os.path import join # pylint: disable=ungrouped-imports from typing import List from typing import Optional +from typing import Union from ...logging import get_logger @@ -77,14 +78,10 @@ def _unlink(path: str, optional: bool=False) -> None: os.unlink(path) -def _write(path: str, text: str, optional: bool=False) -> None: - logger = get_logger() - if optional and not os.access(path, os.F_OK): - logger.info("SKIP ---- %s", path) - return - logger.info("WRITE --- %s", path) +def _write(path: str, value: Union[str, int]) -> None: + get_logger().info("WRITE --- %s", path) with open(path, "w") as param_file: - param_file.write(text) + param_file.write(str(value)) def _write_bytes(path: str, data: bytes) -> None: @@ -161,12 +158,12 @@ class _GadgetConfig: func = f"hid.usb{self.__hid_instance}" func_path = join(self.__gadget_path, "functions", func) _mkdir(func_path) - _write(join(func_path, "no_out_endpoint"), "1", optional=True) + _write(join(func_path, "no_out_endpoint"), "1") if remote_wakeup: - _write(join(func_path, "wakeup_on_write"), "1", optional=True) - _write(join(func_path, "protocol"), str(hid.protocol)) - _write(join(func_path, "subclass"), str(hid.subclass)) - _write(join(func_path, "report_length"), str(hid.report_length)) + _write(join(func_path, "wakeup_on_write"), "1") + _write(join(func_path, "protocol"), hid.protocol) + _write(join(func_path, "subclass"), hid.subclass) + _write(join(func_path, "report_length"), hid.report_length) _write_bytes(join(func_path, "report_desc"), hid.report_descriptor) _symlink(func_path, join(self.__profile_path, func)) self.__create_meta(func, name) @@ -176,11 +173,11 @@ class _GadgetConfig: func = f"mass_storage.usb{self.__msd_instance}" func_path = join(self.__gadget_path, "functions", func) _mkdir(func_path) - _write(join(func_path, "stall"), str(int(stall))) - _write(join(func_path, "lun.0/cdrom"), str(int(cdrom))) - _write(join(func_path, "lun.0/ro"), str(int(not rw))) - _write(join(func_path, "lun.0/removable"), str(int(removable))) - _write(join(func_path, "lun.0/nofua"), str(int(not fua))) + _write(join(func_path, "stall"), int(stall)) + _write(join(func_path, "lun.0/cdrom"), int(cdrom)) + _write(join(func_path, "lun.0/ro"), int(not rw)) + _write(join(func_path, "lun.0/removable"), int(removable)) + _write(join(func_path, "lun.0/nofua"), int(not fua)) if user != "root": _chown(join(func_path, "lun.0/cdrom"), user) _chown(join(func_path, "lun.0/ro"), user) @@ -238,7 +235,7 @@ def _cmd_start(config: Section) -> None: # pylint: disable=too-many-statements, _mkdir(profile_path) _mkdir(join(profile_path, "strings/0x409")) _write(join(profile_path, "strings/0x409/configuration"), f"Config 1: {config.otg.config}") - _write(join(profile_path, "MaxPower"), str(config.otg.max_power)) + _write(join(profile_path, "MaxPower"), config.otg.max_power) if config.otg.remote_wakeup: # XXX: Should we use MaxPower=100 with Remote Wakeup? _write(join(profile_path, "bmAttributes"), "0xA0") |