summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--kvmd/aiofs.py35
-rw-r--r--kvmd/aiotools.py11
-rw-r--r--kvmd/plugins/msd/otg/__init__.py3
-rw-r--r--kvmd/plugins/msd/relay.py5
4 files changed, 40 insertions, 14 deletions
diff --git a/kvmd/aiofs.py b/kvmd/aiofs.py
new file mode 100644
index 00000000..c7bbd10d
--- /dev/null
+++ b/kvmd/aiofs.py
@@ -0,0 +1,35 @@
+# ========================================================================== #
+# #
+# KVMD - The main Pi-KVM daemon. #
+# #
+# Copyright (C) 2018 Maxim Devaev <[email protected]> #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <https://www.gnu.org/licenses/>. #
+# #
+# ========================================================================== #
+
+
+import os
+
+import aiofiles
+import aiofiles.base
+
+from . import aiotools
+
+
+# =====
+async def afile_write_now(afile: aiofiles.base.AiofilesContextManager, data: bytes) -> None:
+ await afile.write(data)
+ await afile.flush()
+ await aiotools.run_async(os.fsync, afile.fileno())
diff --git a/kvmd/aiotools.py b/kvmd/aiotools.py
index 15aa5b9c..d790158d 100644
--- a/kvmd/aiotools.py
+++ b/kvmd/aiotools.py
@@ -20,7 +20,6 @@
# ========================================================================== #
-import os
import asyncio
import asyncio.queues
import functools
@@ -39,9 +38,6 @@ from typing import TypeVar
from typing import Optional
from typing import Any
-import aiofiles
-import aiofiles.base
-
from .logging import get_logger
@@ -94,13 +90,6 @@ async def wait_first(*aws: Awaitable) -> Tuple[Set[asyncio.Future], Set[asyncio.
# =====
-async def afile_write_now(afile: aiofiles.base.AiofilesContextManager, data: bytes) -> None:
- await afile.write(data)
- await afile.flush()
- await run_async(os.fsync, afile.fileno())
-
-
-# =====
class AioNotifier:
def __init__(self) -> None:
self.__queue: asyncio.queues.Queue = asyncio.Queue()
diff --git a/kvmd/plugins/msd/otg/__init__.py b/kvmd/plugins/msd/otg/__init__.py
index 377c1c73..25585302 100644
--- a/kvmd/plugins/msd/otg/__init__.py
+++ b/kvmd/plugins/msd/otg/__init__.py
@@ -45,6 +45,7 @@ from ....validators.os import valid_abs_dir
from ....validators.os import valid_command
from .... import aiotools
+from .... import aiofs
from .. import MsdError
from .. import MsdIsBusyError
@@ -340,7 +341,7 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes
async def write_image_chunk(self, chunk: bytes) -> int:
assert self.__new_file
- await aiotools.afile_write_now(self.__new_file, chunk)
+ await aiofs.afile_write_now(self.__new_file, chunk)
self.__new_file_written += len(chunk)
now = time.time()
if self.__new_file_tick + 1 < now:
diff --git a/kvmd/plugins/msd/relay.py b/kvmd/plugins/msd/relay.py
index 43baeadc..1254351a 100644
--- a/kvmd/plugins/msd/relay.py
+++ b/kvmd/plugins/msd/relay.py
@@ -39,6 +39,7 @@ import aiofiles.base
from ...logging import get_logger
from ... import aiotools
+from ... import aiofs
from ... import gpio
from ...yamlconf import Option
@@ -325,7 +326,7 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes
async def write_image_chunk(self, chunk: bytes) -> int:
assert self.__device_file
- await aiotools.afile_write_now(self.__device_file, chunk)
+ await aiofs.afile_write_now(self.__device_file, chunk)
self.__written += len(chunk)
return self.__written
@@ -349,7 +350,7 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes
assert self.__device_info
if self.__device_info.size - self.__written > _IMAGE_INFO_SIZE:
await self.__device_file.seek(self.__device_info.size - _IMAGE_INFO_SIZE)
- await aiotools.afile_write_now(self.__device_file, _make_image_info_bytes(name, self.__written, complete))
+ await aiofs.afile_write_now(self.__device_file, _make_image_info_bytes(name, self.__written, complete))
await self.__device_file.seek(0)
else:
get_logger().error("Can't write image info because device is full")