mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-12 01:00:29 +08:00
removed aiofs
This commit is contained in:
parent
6c0f5cccb9
commit
22db176ef0
@ -1,39 +0,0 @@
|
||||
# ========================================================================== #
|
||||
# #
|
||||
# KVMD - The main PiKVM daemon. #
|
||||
# #
|
||||
# Copyright (C) 2018-2022 Maxim Devaev <mdevaev@gmail.com> #
|
||||
# #
|
||||
# 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 read(path: str) -> str:
|
||||
async with aiofiles.open(path) as afile: # type: ignore
|
||||
return (await afile.read())
|
||||
|
||||
|
||||
async def afile_sync(afile: aiofiles.base.AiofilesContextManager) -> None:
|
||||
await afile.flush() # type: ignore
|
||||
await aiotools.run_async(os.fsync, afile.fileno()) # type: ignore
|
||||
@ -26,7 +26,6 @@ import asyncio
|
||||
import ssl
|
||||
import functools
|
||||
import types
|
||||
|
||||
import typing
|
||||
|
||||
from typing import Callable
|
||||
@ -35,9 +34,17 @@ from typing import Coroutine
|
||||
from typing import TypeVar
|
||||
from typing import Any
|
||||
|
||||
import aiofiles
|
||||
|
||||
from .logging import get_logger
|
||||
|
||||
|
||||
# =====
|
||||
async def read_file(path: str) -> str:
|
||||
async with aiofiles.open(path) as file:
|
||||
return (await file.read())
|
||||
|
||||
|
||||
# =====
|
||||
def run(coro: Coroutine, final: (Coroutine | None)=None) -> None:
|
||||
# https://github.com/aio-libs/aiohttp/blob/a1d4dac1d/aiohttp/web.py#L515
|
||||
|
||||
@ -31,7 +31,7 @@ from ....logging import get_logger
|
||||
|
||||
from .... import env
|
||||
from .... import tools
|
||||
from .... import aiofs
|
||||
from .... import aiotools
|
||||
from .... import aioproc
|
||||
|
||||
from .base import BaseInfoSubmanager
|
||||
@ -90,7 +90,7 @@ class HwInfoSubmanager(BaseInfoSubmanager):
|
||||
if name not in self.__dt_cache:
|
||||
path = os.path.join(f"{env.PROCFS_PREFIX}/proc/device-tree", name)
|
||||
try:
|
||||
self.__dt_cache[name] = (await aiofs.read(path)).strip(" \t\r\n\0")
|
||||
self.__dt_cache[name] = (await aiotools.read_file(path)).strip(" \t\r\n\0")
|
||||
except Exception as err:
|
||||
get_logger(0).error("Can't read DT %s from %s: %s", name, path, err)
|
||||
return None
|
||||
@ -99,7 +99,7 @@ class HwInfoSubmanager(BaseInfoSubmanager):
|
||||
async def __get_cpu_temp(self) -> (float | None):
|
||||
temp_path = f"{env.SYSFS_PREFIX}/sys/class/thermal/thermal_zone0/temp"
|
||||
try:
|
||||
return int((await aiofs.read(temp_path)).strip()) / 1000
|
||||
return int((await aiotools.read_file(temp_path)).strip()) / 1000
|
||||
except Exception as err:
|
||||
get_logger(0).error("Can't read CPU temp from %s: %s", temp_path, err)
|
||||
return None
|
||||
|
||||
@ -24,7 +24,7 @@ import dataclasses
|
||||
|
||||
from ...logging import get_logger
|
||||
|
||||
from ... import aiofs
|
||||
from ... import aiotools
|
||||
|
||||
|
||||
# =====
|
||||
@ -61,8 +61,7 @@ class VncAuthManager:
|
||||
return ({}, (not self.__enabled))
|
||||
|
||||
async def __inner_read_credentials(self) -> dict[str, VncAuthKvmdCredentials]:
|
||||
lines = (await aiofs.read(self.__path)).split("\n")
|
||||
|
||||
lines = (await aiotools.read_file(self.__path)).split("\n")
|
||||
credentials: dict[str, VncAuthKvmdCredentials] = {}
|
||||
for (lineno, line) in enumerate(lines):
|
||||
if len(line.strip()) == 0 or line.lstrip().startswith("#"):
|
||||
|
||||
@ -36,7 +36,6 @@ from ...errors import OperationError
|
||||
from ...errors import IsBusyError
|
||||
|
||||
from ... import aiotools
|
||||
from ... import aiofs
|
||||
|
||||
from .. import BasePlugin
|
||||
from .. import get_plugin_class
|
||||
@ -254,7 +253,7 @@ class MsdFileWriter(BaseMsdWriter): # pylint: disable=too-many-instance-attribu
|
||||
|
||||
self.__unsynced += len(chunk)
|
||||
if self.__unsynced >= self.__sync_size:
|
||||
await aiofs.afile_sync(self.__file)
|
||||
await self.__sync()
|
||||
self.__unsynced = 0
|
||||
|
||||
now = time.monotonic()
|
||||
@ -287,12 +286,17 @@ class MsdFileWriter(BaseMsdWriter): # pylint: disable=too-many-instance-attribu
|
||||
(log, result) = (logger.warning, "OVERFLOW")
|
||||
log("Written %d of %d bytes to MSD image %r: %s", self.__written, self.__file_size, self.__name, result)
|
||||
try:
|
||||
await aiofs.afile_sync(self.__file)
|
||||
await self.__sync()
|
||||
finally:
|
||||
await self.__file.close() # type: ignore
|
||||
except Exception:
|
||||
logger.exception("Can't close image writer")
|
||||
|
||||
async def __sync(self) -> None:
|
||||
assert self.__file is not None
|
||||
await self.__file.flush() # type: ignore
|
||||
await aiotools.run_async(os.fsync, self.__file.fileno()) # type: ignore
|
||||
|
||||
|
||||
# =====
|
||||
def get_msd_class(name: str) -> type[BaseMsd]:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user