summaryrefslogtreecommitdiff
path: root/kvmd/plugins
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/plugins
parentebe40697a5935d5d35a36d0825715ca8c3824c6a (diff)
refactoring
Diffstat (limited to 'kvmd/plugins')
-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
4 files changed, 19 insertions, 26 deletions
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