diff options
author | Maxim Devaev <[email protected]> | 2022-07-23 11:17:36 +0300 |
---|---|---|
committer | Maxim Devaev <[email protected]> | 2022-07-24 05:38:26 +0300 |
commit | de140537254a517559c78de048791a197011c1f6 (patch) | |
tree | 48560052d4f49bd4a1d6bb08b1e7ce1a4e2874b8 /kvmd | |
parent | baeb2bc35b82ea12777100d70156e74fb162325a (diff) |
refactoring
Diffstat (limited to 'kvmd')
-rw-r--r-- | kvmd/plugins/msd/__init__.py | 25 | ||||
-rw-r--r-- | kvmd/plugins/msd/otg/__init__.py | 9 | ||||
-rw-r--r-- | kvmd/plugins/msd/relay/__init__.py | 9 |
3 files changed, 20 insertions, 23 deletions
diff --git a/kvmd/plugins/msd/__init__.py b/kvmd/plugins/msd/__init__.py index ac285f7b..741c0beb 100644 --- a/kvmd/plugins/msd/__init__.py +++ b/kvmd/plugins/msd/__init__.py @@ -187,15 +187,22 @@ class MsdImageWriter: async def close(self) -> None: assert self.__file is not None - if self.__written == self.__size: - (log, result) = (get_logger().info, "OK") - elif self.__written < self.__size: - (log, result) = (get_logger().error, "INCOMPLETE") - else: # written > size - (log, result) = (get_logger().warning, "OVERFLOW") - log("Written %d of %d bytes to MSD image %r: %s", self.__written, self.__size, self.__name, result) - await aiofs.afile_sync(self.__file) - await self.__file.close() # type: ignore + logger = get_logger() + logger.info("Closing image writer ...") + try: + if self.__written == self.__size: + (log, result) = (logger.info, "OK") + elif self.__written < self.__size: + (log, result) = (logger.error, "INCOMPLETE") + else: # written > size + (log, result) = (logger.warning, "OVERFLOW") + log("Written %d of %d bytes to MSD image %r: %s", self.__written, self.__size, self.__name, result) + try: + await aiofs.afile_sync(self.__file) + finally: + await self.__file.close() # type: ignore + except Exception: + logger.exception("Can't close image writer") # ===== diff --git a/kvmd/plugins/msd/otg/__init__.py b/kvmd/plugins/msd/otg/__init__.py index dde50fa1..1f670de5 100644 --- a/kvmd/plugins/msd/otg/__init__.py +++ b/kvmd/plugins/msd/otg/__init__.py @@ -388,13 +388,8 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes # ===== async def __close_writer(self) -> None: - try: - if self.__writer: - get_logger().info("Closing new image file ...") - await self.__writer.close() - except Exception: - get_logger().exception("Can't close image file") - finally: + if self.__writer: + await self.__writer.close() self.__writer = None # ===== diff --git a/kvmd/plugins/msd/relay/__init__.py b/kvmd/plugins/msd/relay/__init__.py index 125f5fb9..2cdc5796 100644 --- a/kvmd/plugins/msd/relay/__init__.py +++ b/kvmd/plugins/msd/relay/__init__.py @@ -262,13 +262,8 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes get_logger().error("Can't write image info because device is full") async def __close_device_writer(self) -> None: - try: - if self.__device_writer: - get_logger().info("Closing device file ...") - await self.__device_writer.close() # type: ignore - except Exception: - get_logger().exception("Can't close device file") - finally: + if self.__device_writer: + await self.__device_writer.close() # type: ignore self.__device_writer = None async def __load_device_info(self) -> None: |