diff options
author | Maxim Devaev <[email protected]> | 2022-03-31 16:17:52 +0300 |
---|---|---|
committer | Maxim Devaev <[email protected]> | 2022-03-31 16:17:52 +0300 |
commit | b775239d7265a1bcbb6e32f06546e53d389802d6 (patch) | |
tree | 98c7112425e79e0075c5e3859567b085bf9bab17 /kvmd/plugins | |
parent | ab09f88d80ac67c76f012b2fcb853f2d69ab6b7d (diff) |
refactoring
Diffstat (limited to 'kvmd/plugins')
-rw-r--r-- | kvmd/plugins/msd/otg/drive.py | 21 | ||||
-rw-r--r-- | kvmd/plugins/ugpio/otgbind.py | 15 |
2 files changed, 14 insertions, 22 deletions
diff --git a/kvmd/plugins/msd/otg/drive.py b/kvmd/plugins/msd/otg/drive.py index 1bbb2558..ee54e5e9 100644 --- a/kvmd/plugins/msd/otg/drive.py +++ b/kvmd/plugins/msd/otg/drive.py @@ -25,7 +25,7 @@ import errno from typing import List -from .... import env +from .... import usb from .. import MsdOperationError @@ -39,23 +39,16 @@ class MsdDriveLockedError(MsdOperationError): # ===== class Drive: def __init__(self, gadget: str, instance: int, lun: int) -> None: - self.__lun_path = os.path.join( - f"{env.SYSFS_PREFIX}/sys/kernel/config/usb_gadget", - gadget, - f"functions/mass_storage.usb{instance}/lun.{lun}", - ) - self.__configs_root_path = os.path.join( - f"{env.SYSFS_PREFIX}/sys/kernel/config/usb_gadget", - gadget, - "configs/c.1", - ) - self.__func_path = os.path.join(self.__configs_root_path, f"mass_storage.usb{instance}") + func = f"mass_storage.usb{instance}" + self.__profile_func_path = usb.get_gadget_path(gadget, usb.G_PROFILE, func) + self.__profile_path = usb.get_gadget_path(gadget, usb.G_PROFILE) + self.__lun_path = usb.get_gadget_path(gadget, usb.G_FUNCTIONS, func, f"lun.{lun}") def is_enabled(self) -> bool: - return os.path.exists(self.__func_path) + return os.path.exists(self.__profile_func_path) def get_watchable_paths(self) -> List[str]: - return [self.__lun_path, self.__configs_root_path] + return [self.__lun_path, self.__profile_path] # ===== diff --git a/kvmd/plugins/ugpio/otgbind.py b/kvmd/plugins/ugpio/otgbind.py index 17da02a8..4be96aeb 100644 --- a/kvmd/plugins/ugpio/otgbind.py +++ b/kvmd/plugins/ugpio/otgbind.py @@ -31,7 +31,6 @@ from ...logging import get_logger from ...inotify import InotifyMask from ...inotify import Inotify -from ... import env from ... import aiotools from ... import usb @@ -53,7 +52,7 @@ class Plugin(BaseUserGpioDriver): self.__udc = udc - self.__ctl_path = f"{env.SYSFS_PREFIX}/sys/kernel/config/usb_gadget/{gadget}/UDC" + self.__udc_path = usb.get_gadget_path(gadget, usb.G_UDC) @classmethod def get_pin_validator(cls) -> Callable[[Any], Any]: @@ -69,12 +68,12 @@ class Plugin(BaseUserGpioDriver): try: while True: await self._notifier.notify() - if os.path.isfile(self.__ctl_path): + if os.path.isfile(self.__udc_path): break await asyncio.sleep(5) with Inotify() as inotify: - inotify.watch(os.path.dirname(self.__ctl_path), InotifyMask.ALL_MODIFY_EVENTS) + inotify.watch(os.path.dirname(self.__udc_path), InotifyMask.ALL_MODIFY_EVENTS) await self._notifier.notify() while True: need_restart = False @@ -94,13 +93,13 @@ class Plugin(BaseUserGpioDriver): async def read(self, pin: str) -> bool: _ = pin - with open(self.__ctl_path) as ctl_file: - return bool(ctl_file.read().strip()) + with open(self.__udc_path) as udc_file: + return bool(udc_file.read().strip()) async def write(self, pin: str, state: bool) -> None: _ = pin - with open(self.__ctl_path, "w") as ctl_file: - ctl_file.write(self.__udc if state else "\n") + with open(self.__udc_path, "w") as udc_file: + udc_file.write(self.__udc if state else "\n") def __str__(self) -> str: return f"GPIO({self._instance_name})" |