diff options
author | Devaev Maxim <[email protected]> | 2019-06-11 03:37:55 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2019-06-11 03:37:55 +0300 |
commit | bf34f7b3fa69483d5154edeca27230f60ef505e6 (patch) | |
tree | 5bba66818cdfcbbe0fbbc392857e3f12d5da766a /kvmd | |
parent | 8d83a8b8988e83c35de72eb548224ce84668c8db (diff) |
separate busy and uploading flag
Diffstat (limited to 'kvmd')
-rw-r--r-- | kvmd/apps/kvmd/msd.py | 55 |
1 files changed, 29 insertions, 26 deletions
diff --git a/kvmd/apps/kvmd/msd.py b/kvmd/apps/kvmd/msd.py index ecca6131..23671408 100644 --- a/kvmd/apps/kvmd/msd.py +++ b/kvmd/apps/kvmd/msd.py @@ -254,10 +254,11 @@ class MassStorageDevice: # pylint: disable=too-many-instance-attributes return { "enabled": self._enabled, "online": online, - "connected_to": (("kvm" if self.__on_kvm else "server") if online else None), "busy": self.__region.is_busy(), + "uploading": bool(self.__device_file), "written": self.__written, "info": (dataclasses.asdict(self._device_info) if online else None), + "connected_to": (("kvm" if self.__on_kvm else "server") if online else None), } async def poll_state(self) -> AsyncGenerator[Dict, None]: @@ -289,12 +290,9 @@ class MassStorageDevice: # pylint: disable=too-many-instance-attributes gpio.write(self.__target_pin, True) raise self.__on_kvm = True - - state = self.get_state() - await self.__state_queue.put(state) - get_logger().info("Mass-storage device switched to KVM: %s", self._device_info) - return state + + return (await self.__queue_current_state()) @_msd_working @aiotools.atomic @@ -305,33 +303,33 @@ class MassStorageDevice: # pylint: disable=too-many-instance-attributes gpio.write(self.__target_pin, True) self.__on_kvm = False - - state = self.get_state() - await self.__state_queue.put(state) - get_logger().info("Mass-storage device switched to Server") - return state + + return (await self.__queue_current_state()) @aiotools.tasked @aiotools.atomic async def reset(self) -> None: - with self.__region: - if not self._enabled: - raise MsdDisabledError() + notify = False + try: + with self.__region: + if not self._enabled: + raise MsdDisabledError() - get_logger(0).info("Mass-storage device reset") + notify = True + get_logger(0).info("Mass-storage device reset") - gpio.write(self.__reset_pin, True) - await asyncio.sleep(self.__reset_delay) - gpio.write(self.__target_pin, False) - self.__on_kvm = True - await asyncio.sleep(self.__reset_delay) - gpio.write(self.__reset_pin, False) + gpio.write(self.__reset_pin, True) + await asyncio.sleep(self.__reset_delay) + gpio.write(self.__target_pin, False) + self.__on_kvm = True + await asyncio.sleep(self.__reset_delay) + gpio.write(self.__reset_pin, False) - try: await self.__load_device_info() - finally: - await self.__state_queue.put(self.get_state()) + finally: + if notify: + await self.__queue_current_state() @_msd_working @aiotools.atomic @@ -348,7 +346,7 @@ class MassStorageDevice: # pylint: disable=too-many-instance-attributes self.__region.exit() raise finally: - await self.__state_queue.put(self.get_state()) + await self.__queue_current_state() @aiotools.atomic async def write_image_info(self, name: str, complete: bool) -> None: @@ -379,8 +377,13 @@ class MassStorageDevice: # pylint: disable=too-many-instance-attributes await self.__close_device_file() await self.__load_device_info() finally: - await self.__state_queue.put(self.get_state()) self.__region.exit() + await self.__queue_current_state() + + async def __queue_current_state(self) -> Dict: + state = self.get_state() + await self.__state_queue.put(state) + return state async def __write_to_device_file(self, data: bytes) -> None: assert self.__device_file |