summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2020-05-25 01:39:12 +0300
committerDevaev Maxim <[email protected]>2020-05-25 01:39:18 +0300
commit499cbb0cc57346708525dd1d0059e65a74598980 (patch)
tree1985fdcfdafcddc2d34bbce0c16fe3cc5ba4617d
parenteeece34312dc39f001c0718d07f12d90a279f736 (diff)
improved some logging
-rw-r--r--kvmd/apps/ipmi/auth.py15
-rw-r--r--kvmd/apps/vnc/vncauth.py12
-rw-r--r--kvmd/keyboard/keysym.py56
3 files changed, 40 insertions, 43 deletions
diff --git a/kvmd/apps/ipmi/auth.py b/kvmd/apps/ipmi/auth.py
index 29804140..7d17edc3 100644
--- a/kvmd/apps/ipmi/auth.py
+++ b/kvmd/apps/ipmi/auth.py
@@ -28,8 +28,8 @@ from typing import Dict
# =====
class IpmiPasswdError(Exception):
- def __init__(self, msg: str) -> None:
- super().__init__("Incorrect IPMI passwd file: " + msg)
+ def __init__(self, path: str, number: int, msg: str) -> None:
+ super().__init__(f"Syntax error at {path}:{number}: {msg}")
@dataclasses.dataclass(frozen=True)
@@ -42,6 +42,7 @@ class IpmiUserCredentials:
class IpmiAuthManager:
def __init__(self, path: str) -> None:
+ self.__path = path
with open(path) as passwd_file:
self.__credentials = self.__parse_passwd_file(passwd_file.read().split("\n"))
@@ -61,25 +62,25 @@ class IpmiAuthManager:
continue
if " -> " not in line:
- raise IpmiPasswdError(f"Missing ' -> ' operator at line #{number}")
+ raise IpmiPasswdError(self.__path, number, "Missing ' -> ' operator")
(left, right) = map(str.lstrip, line.split(" -> ", 1))
for (name, pair) in [("left", left), ("right", right)]:
if ":" not in pair:
- raise IpmiPasswdError(f"Missing ':' operator in {name} credentials at line #{number}")
+ raise IpmiPasswdError(self.__path, number, f"Missing ':' operator in {name} credentials")
(ipmi_user, ipmi_passwd) = left.split(":")
ipmi_user = ipmi_user.strip()
if len(ipmi_user) == 0:
- raise IpmiPasswdError(f"Empty IPMI user (left) at line #{number}")
+ raise IpmiPasswdError(self.__path, number, "Empty IPMI user (left)")
(kvmd_user, kvmd_passwd) = right.split(":")
kvmd_user = kvmd_user.strip()
if len(kvmd_user) == 0:
- raise IpmiPasswdError(f"Empty KVMD user (left) at line #{number}")
+ raise IpmiPasswdError(self.__path, number, "Empty KVMD user (left)")
if ipmi_user in credentials:
- raise IpmiPasswdError(f"Found duplicating user {ipmi_user!r} (left) at line #{number}")
+ raise IpmiPasswdError(self.__path, number, f"Found duplicating user {ipmi_user!r} (left)")
credentials[ipmi_user] = IpmiUserCredentials(
ipmi_user=ipmi_user,
diff --git a/kvmd/apps/vnc/vncauth.py b/kvmd/apps/vnc/vncauth.py
index b27d74d5..0689b9ca 100644
--- a/kvmd/apps/vnc/vncauth.py
+++ b/kvmd/apps/vnc/vncauth.py
@@ -32,8 +32,8 @@ from ...logging import get_logger
# =====
class VncAuthError(Exception):
- def __init__(self, msg: str) -> None:
- super().__init__(f"Incorrect VNCAuth passwd file: {msg}")
+ def __init__(self, path: str, number: int, msg: str) -> None:
+ super().__init__(f"Syntax error at {path}:{number}: {msg}")
# =====
@@ -73,19 +73,19 @@ class VncAuthManager:
continue
if " -> " not in line:
- raise VncAuthError(f"Missing ' -> ' operator at line #{number}")
+ raise VncAuthError(self.__path, number, "Missing ' -> ' operator")
(vnc_passwd, kvmd_userpass) = map(str.lstrip, line.split(" -> ", 1))
if ":" not in kvmd_userpass:
- raise VncAuthError(f"Missing ':' operator in KVMD credentials (right part) at line #{number}")
+ raise VncAuthError(self.__path, number, "Missing ':' operator in KVMD credentials (right part)")
(kvmd_user, kvmd_passwd) = kvmd_userpass.split(":")
kvmd_user = kvmd_user.strip()
if len(kvmd_user) == 0:
- raise VncAuthError(f"Empty KVMD user (right part) at line #{number}")
+ raise VncAuthError(self.__path, number, "Empty KVMD user (right part)")
if vnc_passwd in credentials:
- raise VncAuthError(f"Found duplicating VNC password (left part) at line #{number}")
+ raise VncAuthError(self.__path, number, "Duplicating VNC password (left part)")
credentials[vnc_passwd] = VncAuthKvmdCredentials(kvmd_user, kvmd_passwd)
return credentials
diff --git a/kvmd/keyboard/keysym.py b/kvmd/keyboard/keysym.py
index 6517c7e1..3749f7da 100644
--- a/kvmd/keyboard/keysym.py
+++ b/kvmd/keyboard/keysym.py
@@ -25,7 +25,6 @@ import pkgutil
import functools
from typing import Dict
-from typing import Optional
import Xlib.keysymdef
@@ -47,35 +46,32 @@ class SymmapWebKey:
def build_symmap(path: str) -> Dict[int, SymmapWebKey]:
# https://github.com/qemu/qemu/blob/95a9457fd44ad97c518858a4e1586a5498f9773c/ui/keymaps.c
- return {
- x11_code: web_key
- for (x11_code, at1_key) in [
- *list(X11_TO_AT1.items()),
- *list(_read_keyboard_layout(path).items()),
- ]
- if (web_key := _make_safe_web_key(at1_key)) is not None
- }
+ logger = get_logger()
+
+ symmap: Dict[int, SymmapWebKey] = {}
+ for (src, items) in [
+ ("<builtin>", list(X11_TO_AT1.items())),
+ (path, list(_read_keyboard_layout(path).items())),
+ ]:
+ for (code, key) in items:
+ if (web_name := AT1_TO_WEB.get(key.code)) is not None:
+ if (
+ (web_name in ["ShiftLeft", "ShiftRight"] and key.shift) # pylint: disable=too-many-boolean-expressions
+ or (web_name in ["AltLeft", "AltRight"] and key.altgr)
+ or (web_name in ["ControlLeft", "ControlRight"] and key.ctrl)
+ ):
+ logger.error("Invalid modifier key at mapping %s: %s / %s", src, web_name, key)
+ continue
+ symmap[code] = SymmapWebKey(
+ name=web_name,
+ shift=key.shift,
+ altgr=key.altgr,
+ ctrl=key.ctrl,
+ )
+ return symmap
# =====
-def _make_safe_web_key(key: At1Key) -> Optional[SymmapWebKey]:
- if (web_name := AT1_TO_WEB.get(key.code)) is not None:
- if (
- (web_name in ["ShiftLeft", "ShiftRight"] and key.shift) # pylint: disable=too-many-boolean-expressions
- or (web_name in ["AltLeft", "AltRight"] and key.altgr)
- or (web_name in ["ControlLeft", "ControlRight"] and key.ctrl)
- ):
- get_logger().error("Invalid modifier key: %s / %s", web_name, key)
- return None # Ехал модификатор через модификатор
- return SymmapWebKey(
- name=web_name,
- shift=key.shift,
- altgr=key.altgr,
- ctrl=key.ctrl,
- )
- return None
-
-
@functools.lru_cache()
def _get_keysyms() -> Dict[str, int]:
keysyms: Dict[str, int] = {}
@@ -117,14 +113,14 @@ def _read_keyboard_layout(path: str) -> Dict[int, At1Key]: # Keysym to evdev (a
parts = line.split()
if len(parts) >= 2:
- if (x11_code := _resolve_keysym(parts[0])) != 0:
+ if (code := _resolve_keysym(parts[0])) != 0:
try:
- layout[x11_code] = At1Key(
+ layout[code] = At1Key(
code=int(parts[1], 16),
shift=("shift" in parts[2:]),
altgr=("altgr" in parts[2:]),
ctrl=("ctrl" in parts[2:]),
)
except ValueError as err:
- logger.error("Can't parse layout line #%d: %s", number, str(err))
+ logger.error("Syntax error at %s:%d: %s", path, number, err)
return layout