summaryrefslogtreecommitdiff
path: root/kvmd
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2021-01-23 07:00:49 +0300
committerDevaev Maxim <[email protected]>2021-01-23 07:00:49 +0300
commit4d4fb69d2eb2e9b3d677b82098d888bd899c8c33 (patch)
treec193f2a0db5fb34f5f58bd96d6ccd771177b1753 /kvmd
parentebe40697a5935d5d35a36d0825715ca8c3824c6a (diff)
refactoring
Diffstat (limited to 'kvmd')
-rw-r--r--kvmd/apps/kvmd/info/extras.py3
-rw-r--r--kvmd/apps/kvmd/streamer.py2
-rw-r--r--kvmd/apps/vnc/server.py4
-rw-r--r--kvmd/clients/streamer.py7
-rw-r--r--kvmd/plugins/hid/bt/server.py13
-rw-r--r--kvmd/plugins/hid/otg/device.py16
-rw-r--r--kvmd/plugins/hid/otg/usb.py3
-rw-r--r--kvmd/plugins/ugpio/hidrelay.py13
-rw-r--r--kvmd/tools.py5
9 files changed, 34 insertions, 32 deletions
diff --git a/kvmd/apps/kvmd/info/extras.py b/kvmd/apps/kvmd/info/extras.py
index b471a6ca..6024aebc 100644
--- a/kvmd/apps/kvmd/info/extras.py
+++ b/kvmd/apps/kvmd/info/extras.py
@@ -34,6 +34,7 @@ from ....logging import get_logger
from ....yamlconf import Section
from ....yamlconf.loader import load_yaml_file
+from .... import tools
from .... import aiotools
from .base import BaseInfoSubmanager
@@ -98,5 +99,5 @@ class ExtrasInfoSubmanager(BaseInfoSubmanager):
return (enabled or (manager.GetUnitFileState(name) in ["enabled", "enabled-runtime", "static", "indirect", "generated"]))
except Exception as err:
- get_logger(0).error("Can't get info about the service %r: %s: %s", name, type(err).__name__, err)
+ get_logger(0).error("Can't get info about the service %r: %s", name, tools.efmt(err))
return True
diff --git a/kvmd/apps/kvmd/streamer.py b/kvmd/apps/kvmd/streamer.py
index 77c1302c..0069ad94 100644
--- a/kvmd/apps/kvmd/streamer.py
+++ b/kvmd/apps/kvmd/streamer.py
@@ -325,7 +325,7 @@ class Streamer: # pylint: disable=too-many-instance-attributes
return snapshot
logger.error("Stream is offline, no signal or so")
except (aiohttp.ClientConnectionError, aiohttp.ServerConnectionError) as err:
- logger.error("Can't connect to streamer: %s: %s", type(err).__name__, err)
+ logger.error("Can't connect to streamer: %s", tools.efmt(err))
except Exception:
logger.exception("Invalid streamer response from /snapshot")
return None
diff --git a/kvmd/apps/vnc/server.py b/kvmd/apps/vnc/server.py
index 14617311..d00360a6 100644
--- a/kvmd/apps/vnc/server.py
+++ b/kvmd/apps/vnc/server.py
@@ -50,6 +50,8 @@ from ...clients.streamer import BaseStreamerClient
from ...clients.streamer import StreamerHttpClient
from ...clients.streamer import StreamerMemsinkClient
+from ... import tools
+
from .rfb import RfbClient
from .rfb.stream import rfb_format_remote
from .rfb.stream import rfb_close_writer
@@ -397,7 +399,7 @@ class VncServer: # pylint: disable=too-many-instance-attributes
async with kvmd.make_session("", "") as kvmd_session:
none_auth_only = await kvmd_session.auth.check()
except (aiohttp.ClientError, asyncio.TimeoutError) as err:
- logger.error("[entry] %s: Can't check KVMD auth mode: %s: %s", remote, type(err).__name__, err)
+ logger.error("[entry] %s: Can't check KVMD auth mode: %s", remote, tools.efmt(err))
return
await _Client(
diff --git a/kvmd/clients/streamer.py b/kvmd/clients/streamer.py
index a955b407..ea08500e 100644
--- a/kvmd/clients/streamer.py
+++ b/kvmd/clients/streamer.py
@@ -33,6 +33,7 @@ try:
except ImportError:
ustreamer = None
+from .. import tools
from .. import aiotools
from .. import htclient
@@ -119,7 +120,7 @@ class StreamerHttpClient(BaseStreamerClient):
except Exception as err: # Тут бывают и ассерты, и KeyError, и прочая херня
if isinstance(err, StreamerTempError):
raise
- raise StreamerTempError(f"{type(err).__name__}: {err}")
+ raise StreamerTempError(tools.efmt(err))
raise StreamerTempError("Reached EOF")
def __make_http_session(self) -> aiohttp.ClientSession:
@@ -165,6 +166,6 @@ class StreamerMemsinkClient(BaseStreamerClient):
if frame is not None:
yield (frame["online"], frame["width"], frame["height"], frame["data"])
except FileNotFoundError as err:
- raise StreamerTempError(f"{type(err).__name__}: {err}")
+ raise StreamerTempError(tools.efmt(err))
except Exception as err:
- raise StreamerPermError(f"{type(err).__name__}: {err}")
+ raise StreamerPermError(tools.efmt(err))
diff --git a/kvmd/plugins/hid/bt/server.py b/kvmd/plugins/hid/bt/server.py
index 3332467a..af91a6f8 100644
--- a/kvmd/plugins/hid/bt/server.py
+++ b/kvmd/plugins/hid/bt/server.py
@@ -187,8 +187,7 @@ class BtServer: # pylint: disable=too-many-instance-attributes
elif data == b"\x71":
sock.send(b"\x00")
except Exception as err:
- get_logger(0).exception("CTL socket error on %s: %s: %s",
- client.addr, type(err).__name__, err)
+ get_logger(0).exception("CTL socket error on %s: %s", client.addr, tools.efmt(err))
self.__close_client("CTL", client, "ctl_sock")
continue
@@ -202,8 +201,7 @@ class BtServer: # pylint: disable=too-many-instance-attributes
elif data[:2] == b"\xA2\x01":
self.__process_leds(data[2])
except Exception as err:
- get_logger(0).exception("INT socket error on %s: %s: %s",
- client.addr, type(err).__name__, err)
+ get_logger(0).exception("INT socket error on %s: %s", client.addr, tools.efmt(err))
self.__close_client("INT", client, "ctl_sock")
if qr in ready_read:
@@ -286,8 +284,7 @@ class BtServer: # pylint: disable=too-many-instance-attributes
try:
client.int_sock.send(report)
except Exception as err:
- get_logger(0).info("Can't send %s report to %s: %s: %s",
- name, client.addr, type(err).__name__, err)
+ get_logger(0).info("Can't send %s report to %s: %s", name, client.addr, tools.efmt(err))
self.__close_client_pair(client)
def __clear_modifiers(self) -> None:
@@ -379,7 +376,7 @@ class BtServer: # pylint: disable=too-many-instance-attributes
try:
self.__iface.set_public(public)
except Exception as err:
- logger.error("Can't change public mode: %s: %s", type(err).__name__, err)
+ logger.error("Can't change public mode: %s", tools.efmt(err))
def __unpair_client(self, client: _BtClient) -> None:
logger = get_logger(0)
@@ -387,4 +384,4 @@ class BtServer: # pylint: disable=too-many-instance-attributes
try:
self.__iface.unpair(client.addr)
except Exception as err:
- logger.error("Can't unpair %s: %s: %s", client.addr, type(err).__name__, err)
+ logger.error("Can't unpair %s: %s", client.addr, tools.efmt(err))
diff --git a/kvmd/plugins/hid/otg/device.py b/kvmd/plugins/hid/otg/device.py
index 7757efe8..958f0d4d 100644
--- a/kvmd/plugins/hid/otg/device.py
+++ b/kvmd/plugins/hid/otg/device.py
@@ -167,8 +167,7 @@ class BaseDeviceProcess(multiprocessing.Process): # pylint: disable=too-many-in
err.errno == errno.EAGAIN # pylint: disable=no-member
or err.errno == errno.ESHUTDOWN # pylint: disable=no-member
):
- logger.debug("HID-%s busy/unplugged (write): %s: %s",
- self.__name, type(err).__name__, err)
+ logger.debug("HID-%s busy/unplugged (write): %s", self.__name, tools.efmt(err))
else:
logger.exception("Can't write report to HID-%s", self.__name)
@@ -193,7 +192,7 @@ class BaseDeviceProcess(multiprocessing.Process): # pylint: disable=too-many-in
try:
read = bool(select.select([self.__fd], [], [], 0)[0])
except Exception as err:
- logger.error("Can't select() for read HID-%s: %s: %s", self.__name, type(err).__name__, err)
+ logger.error("Can't select() for read HID-%s: %s", self.__name, tools.efmt(err))
break
if read:
@@ -201,8 +200,7 @@ class BaseDeviceProcess(multiprocessing.Process): # pylint: disable=too-many-in
report = os.read(self.__fd, self.__read_size)
except Exception as err:
if isinstance(err, OSError) and err.errno == errno.EAGAIN: # pylint: disable=no-member
- logger.debug("HID-%s busy/unplugged (read): %s: %s",
- self.__name, type(err).__name__, err)
+ logger.debug("HID-%s busy/unplugged (read): %s", self.__name, tools.efmt(err))
else:
logger.exception("Can't read report from HID-%s", self.__name)
else:
@@ -220,12 +218,8 @@ class BaseDeviceProcess(multiprocessing.Process): # pylint: disable=too-many-in
flags = os.O_NONBLOCK
flags |= (os.O_RDWR if self.__read_size else os.O_WRONLY)
self.__fd = os.open(self.__device_path, flags)
- except FileNotFoundError:
- logger.error("Missing HID-%s device: %s", self.__name, self.__device_path)
- time.sleep(self.__reopen_delay)
except Exception as err:
- logger.error("Can't open HID-%s device: %s: %s: %s",
- self.__name, self.__device_path, type(err).__name__, err)
+ logger.error("Can't open HID-%s device %s: %s", self.__name, self.__device_path, tools.efmt(err))
time.sleep(self.__reopen_delay)
else:
time.sleep(self.__reopen_delay)
@@ -238,7 +232,7 @@ class BaseDeviceProcess(multiprocessing.Process): # pylint: disable=too-many-in
else:
logger.debug("HID-%s is busy/unplugged (write select)", self.__name)
except Exception as err:
- logger.error("Can't select() for write HID-%s: %s: %s", self.__name, type(err).__name__, err)
+ logger.error("Can't select() for write HID-%s: %s", self.__name, tools.efmt(err))
self.__close_device()
self.__state_flags.update(online=False)
diff --git a/kvmd/plugins/hid/otg/usb.py b/kvmd/plugins/hid/otg/usb.py
index 17979003..e4615669 100644
--- a/kvmd/plugins/hid/otg/usb.py
+++ b/kvmd/plugins/hid/otg/usb.py
@@ -25,6 +25,7 @@ import os
from ....logging import get_logger
from .... import env
+from .... import tools
# =====
@@ -47,7 +48,7 @@ class UsbDeviceController:
try:
candidates = sorted(os.listdir(path))
except Exception as err:
- logger.error("Can't list %s: %s: %s: ignored", path, type(err).__name__, err)
+ logger.error("Can't list %s: %s: ignored", path, tools.efmt(err))
return
udc = ""
diff --git a/kvmd/plugins/ugpio/hidrelay.py b/kvmd/plugins/ugpio/hidrelay.py
index 828a17b8..e17e513f 100644
--- a/kvmd/plugins/ugpio/hidrelay.py
+++ b/kvmd/plugins/ugpio/hidrelay.py
@@ -31,6 +31,7 @@ import hid
from ...logging import get_logger
+from ... import tools
from ... import aiotools
from ...yamlconf import Option
@@ -91,8 +92,8 @@ class Plugin(BaseUserGpioDriver):
with self.__ensure_device("probing"):
pass
except Exception as err:
- logger.error("Can't probe %s on %s: %s: %s",
- self, self.__device_path, type(err).__name__, err)
+ logger.error("Can't probe %s on %s: %s",
+ self, self.__device_path, tools.efmt(err))
self.__reset_pins()
async def run(self) -> None:
@@ -135,8 +136,8 @@ class Plugin(BaseUserGpioDriver):
try:
self.__inner_write(pin, state)
except Exception as err:
- logger.error("Can't reset pin=%d of %s on %s: %s: %s",
- pin, self, self.__device_path, type(err).__name__, err)
+ logger.error("Can't reset pin=%d of %s on %s: %s",
+ pin, self, self.__device_path, tools.efmt(err))
def __inner_read(self, pin: int) -> bool:
if self.__check_pin(pin):
@@ -173,8 +174,8 @@ class Plugin(BaseUserGpioDriver):
try:
yield self.__device
except Exception as err:
- get_logger(0).error("Error occured on %s on %s while %s: %s: %s",
- self, self.__device_path, context, type(err).__name__, err)
+ get_logger(0).error("Error occured on %s on %s while %s: %s",
+ self, self.__device_path, context, tools.efmt(err))
self.__close_device()
raise
diff --git a/kvmd/tools.py b/kvmd/tools.py
index e75dd02a..8857796d 100644
--- a/kvmd/tools.py
+++ b/kvmd/tools.py
@@ -33,6 +33,11 @@ from typing import TypeVar
# =====
+def efmt(err: Exception) -> str:
+ return f"{type(err).__name__}: {err}"
+
+
+# =====
def merge(dest: Dict, src: Dict) -> None:
for key in src:
if key in dest: