diff options
author | Maxim Devaev <[email protected]> | 2024-09-18 04:37:43 +0300 |
---|---|---|
committer | Maxim Devaev <[email protected]> | 2024-09-18 04:37:43 +0300 |
commit | 7a53f1445619fc471c2823e7081de8b6039b938e (patch) | |
tree | 961dd0072cc976504fe4570743d801c79512e9a6 /kvmd/apps | |
parent | 45270a09d7b5076bac96887a1e36d752882e3adf (diff) |
refactoring
Diffstat (limited to 'kvmd/apps')
33 files changed, 211 insertions, 210 deletions
diff --git a/kvmd/apps/__init__.py b/kvmd/apps/__init__.py index 035b3cc4..dd1b8ff9 100644 --- a/kvmd/apps/__init__.py +++ b/kvmd/apps/__init__.py @@ -171,8 +171,8 @@ def _init_config(config_path: str, override_options: list[str], **load_flags: bo config_path = os.path.expanduser(config_path) try: raw_config: dict = load_yaml_file(config_path) - except Exception as err: - raise SystemExit(f"ConfigError: Can't read config file {config_path!r}:\n{tools.efmt(err)}") + except Exception as ex: + raise SystemExit(f"ConfigError: Can't read config file {config_path!r}:\n{tools.efmt(ex)}") if not isinstance(raw_config, dict): raise SystemExit(f"ConfigError: Top-level of the file {config_path!r} must be a dictionary") @@ -187,8 +187,8 @@ def _init_config(config_path: str, override_options: list[str], **load_flags: bo config = make_config(raw_config, scheme) return config - except (ConfigError, UnknownPluginError) as err: - raise SystemExit(f"ConfigError: {err}") + except (ConfigError, UnknownPluginError) as ex: + raise SystemExit(f"ConfigError: {ex}") def _patch_raw(raw_config: dict) -> None: # pylint: disable=too-many-branches diff --git a/kvmd/apps/edidconf/__init__.py b/kvmd/apps/edidconf/__init__.py index aabc8a8f..d213a871 100644 --- a/kvmd/apps/edidconf/__init__.py +++ b/kvmd/apps/edidconf/__init__.py @@ -402,5 +402,5 @@ def main(argv: (list[str] | None)=None) -> None: # pylint: disable=too-many-bra f"--set-edid=file={orig_edid_path}", "--info-edid", ], stdout=sys.stderr, check=True) - except subprocess.CalledProcessError as err: - raise SystemExit(str(err)) + except subprocess.CalledProcessError as ex: + raise SystemExit(str(ex)) diff --git a/kvmd/apps/htpasswd/__init__.py b/kvmd/apps/htpasswd/__init__.py index fd006ee2..9e857abc 100644 --- a/kvmd/apps/htpasswd/__init__.py +++ b/kvmd/apps/htpasswd/__init__.py @@ -155,5 +155,5 @@ def main(argv: (list[str] | None)=None) -> None: options = parser.parse_args(argv[1:]) try: options.cmd(config, options) - except ValidatorError as err: - raise SystemExit(str(err)) + except ValidatorError as ex: + raise SystemExit(str(ex)) diff --git a/kvmd/apps/ipmi/server.py b/kvmd/apps/ipmi/server.py index c6e35fae..2fc897f9 100644 --- a/kvmd/apps/ipmi/server.py +++ b/kvmd/apps/ipmi/server.py @@ -101,6 +101,7 @@ class IpmiServer(BaseIpmiServer): # pylint: disable=too-many-instance-attribute # ===== def handle_raw_request(self, request: dict, session: IpmiServerSession) -> None: + # Parameter 'request' has been renamed to 'req' in overriding method handler = { (6, 1): (lambda _, session: self.send_device_id(session)), # Get device ID (6, 7): self.__get_power_state_handler, # Power state @@ -145,13 +146,13 @@ class IpmiServer(BaseIpmiServer): # pylint: disable=too-many-instance-attribute data = [int(result["leds"]["power"]), 0, 0] session.send_ipmi_response(data=data) - def __chassis_control_handler(self, request: dict, session: IpmiServerSession) -> None: + def __chassis_control_handler(self, req: dict, session: IpmiServerSession) -> None: action = { 0: "off_hard", 1: "on", 3: "reset_hard", 5: "off", - }.get(request["data"][0], "") + }.get(req["data"][0], "") if action: if not self.__make_request(session, f"atx.switch_power({action})", "atx.switch_power", action=action): code = 0xC0 # Try again later @@ -171,8 +172,8 @@ class IpmiServer(BaseIpmiServer): # pylint: disable=too-many-instance-attribute async with self.__kvmd.make_session(credentials.kvmd_user, credentials.kvmd_passwd) as kvmd_session: func = functools.reduce(getattr, func_path.split("."), kvmd_session) return (await func(**kwargs)) - except (aiohttp.ClientError, asyncio.TimeoutError) as err: - logger.error("[%s]: Can't perform request %s: %s", session.sockaddr[0], name, err) + except (aiohttp.ClientError, asyncio.TimeoutError) as ex: + logger.error("[%s]: Can't perform request %s: %s", session.sockaddr[0], name, ex) raise return aiotools.run_sync(runner()) diff --git a/kvmd/apps/janus/runner.py b/kvmd/apps/janus/runner.py index c5ba26f2..9e426021 100644 --- a/kvmd/apps/janus/runner.py +++ b/kvmd/apps/janus/runner.py @@ -113,8 +113,8 @@ class JanusRunner: # pylint: disable=too-many-instance-attributes for proto in [socket.AF_INET, socket.AF_INET6]: if proto in addrs: return addrs[proto][0]["addr"] - except Exception as err: - get_logger().error("Can't get default IP: %s", tools.efmt(err)) + except Exception as ex: + get_logger().error("Can't get default IP: %s", tools.efmt(ex)) return "" # ===== diff --git a/kvmd/apps/janus/stun.py b/kvmd/apps/janus/stun.py index d597192b..41cd86e7 100644 --- a/kvmd/apps/janus/stun.py +++ b/kvmd/apps/janus/stun.py @@ -93,8 +93,8 @@ class Stun: self.__sock.bind(src_addr) (nat_type, resp) = await self.__get_nat_type(src_ip) ext_ip = (resp.ext.ip if resp.ext is not None else "") - except Exception as err: - get_logger(0).error("Can't get STUN info: %s", tools.efmt(err)) + except Exception as ex: + get_logger(0).error("Can't get STUN info: %s", tools.efmt(ex)) finally: self.__sock = None @@ -201,16 +201,16 @@ class Stun: try: await aiotools.run_async(self.__sock.sendto, req, addr) - except Exception as err: - return (b"", f"Send error: {tools.efmt(err)}") + except Exception as ex: + return (b"", f"Send error: {tools.efmt(ex)}") try: resp = (await aiotools.run_async(self.__sock.recvfrom, 2048))[0] - except Exception as err: - return (b"", f"Recv error: {tools.efmt(err)}") + except Exception as ex: + return (b"", f"Recv error: {tools.efmt(ex)}") - (response_type, payload_len) = struct.unpack(">HH", resp[:4]) - if response_type != 0x0101: - return (b"", f"Invalid response type: {response_type:#06x}") + (resp_type, payload_len) = struct.unpack(">HH", resp[:4]) + if resp_type != 0x0101: + return (b"", f"Invalid response type: {resp_type:#06x}") if trans_id != resp[4:20]: return (b"", "Transaction ID mismatch") diff --git a/kvmd/apps/kvmd/api/atx.py b/kvmd/apps/kvmd/api/atx.py index b7f74c99..df952b7b 100644 --- a/kvmd/apps/kvmd/api/atx.py +++ b/kvmd/apps/kvmd/api/atx.py @@ -45,9 +45,9 @@ class AtxApi: return make_json_response(await self.__atx.get_state()) @exposed_http("POST", "/atx/power") - async def __power_handler(self, request: Request) -> Response: - action = valid_atx_power_action(request.query.get("action")) - wait = valid_bool(request.query.get("wait", False)) + async def __power_handler(self, req: Request) -> Response: + action = valid_atx_power_action(req.query.get("action")) + wait = valid_bool(req.query.get("wait", False)) await ({ "on": self.__atx.power_on, "off": self.__atx.power_off, @@ -57,9 +57,9 @@ class AtxApi: return make_json_response() @exposed_http("POST", "/atx/click") - async def __click_handler(self, request: Request) -> Response: - button = valid_atx_button(request.query.get("button")) - wait = valid_bool(request.query.get("wait", False)) + async def __click_handler(self, req: Request) -> Response: + button = valid_atx_button(req.query.get("button")) + wait = valid_bool(req.query.get("wait", False)) await ({ "power": self.__atx.click_power, "power_long": self.__atx.click_power_long, diff --git a/kvmd/apps/kvmd/api/auth.py b/kvmd/apps/kvmd/api/auth.py index 0c7d5484..dee4a85d 100644 --- a/kvmd/apps/kvmd/api/auth.py +++ b/kvmd/apps/kvmd/api/auth.py @@ -43,34 +43,34 @@ from ..auth import AuthManager _COOKIE_AUTH_TOKEN = "auth_token" -async def check_request_auth(auth_manager: AuthManager, exposed: HttpExposed, request: Request) -> None: +async def check_request_auth(auth_manager: AuthManager, exposed: HttpExposed, req: Request) -> None: if auth_manager.is_auth_required(exposed): - user = request.headers.get("X-KVMD-User", "") + user = req.headers.get("X-KVMD-User", "") if user: user = valid_user(user) - passwd = request.headers.get("X-KVMD-Passwd", "") - set_request_auth_info(request, f"{user} (xhdr)") + passwd = req.headers.get("X-KVMD-Passwd", "") + set_request_auth_info(req, f"{user} (xhdr)") if not (await auth_manager.authorize(user, valid_passwd(passwd))): raise ForbiddenError() return - token = request.cookies.get(_COOKIE_AUTH_TOKEN, "") + token = req.cookies.get(_COOKIE_AUTH_TOKEN, "") if token: user = auth_manager.check(valid_auth_token(token)) # type: ignore if not user: - set_request_auth_info(request, "- (token)") + set_request_auth_info(req, "- (token)") raise ForbiddenError() - set_request_auth_info(request, f"{user} (token)") + set_request_auth_info(req, f"{user} (token)") return - basic_auth = request.headers.get("Authorization", "") + basic_auth = req.headers.get("Authorization", "") if basic_auth and basic_auth[:6].lower() == "basic ": try: (user, passwd) = base64.b64decode(basic_auth[6:]).decode("utf-8").split(":") except Exception: raise UnauthorizedError() user = valid_user(user) - set_request_auth_info(request, f"{user} (basic)") + set_request_auth_info(req, f"{user} (basic)") if not (await auth_manager.authorize(user, valid_passwd(passwd))): raise ForbiddenError() return @@ -85,9 +85,9 @@ class AuthApi: # ===== @exposed_http("POST", "/auth/login", auth_required=False) - async def __login_handler(self, request: Request) -> Response: + async def __login_handler(self, req: Request) -> Response: if self.__auth_manager.is_auth_enabled(): - credentials = await request.post() + credentials = await req.post() token = await self.__auth_manager.login( user=valid_user(credentials.get("user", "")), passwd=valid_passwd(credentials.get("passwd", "")), @@ -98,9 +98,9 @@ class AuthApi: return make_json_response() @exposed_http("POST", "/auth/logout") - async def __logout_handler(self, request: Request) -> Response: + async def __logout_handler(self, req: Request) -> Response: if self.__auth_manager.is_auth_enabled(): - token = valid_auth_token(request.cookies.get(_COOKIE_AUTH_TOKEN, "")) + token = valid_auth_token(req.cookies.get(_COOKIE_AUTH_TOKEN, "")) self.__auth_manager.logout(token) return make_json_response() diff --git a/kvmd/apps/kvmd/api/hid.py b/kvmd/apps/kvmd/api/hid.py index 326daf44..107fc858 100644 --- a/kvmd/apps/kvmd/api/hid.py +++ b/kvmd/apps/kvmd/api/hid.py @@ -85,22 +85,22 @@ class HidApi: return make_json_response(await self.__hid.get_state()) @exposed_http("POST", "/hid/set_params") - async def __set_params_handler(self, request: Request) -> Response: + async def __set_params_handler(self, req: Request) -> Response: params = { - key: validator(request.query.get(key)) + key: validator(req.query.get(key)) for (key, validator) in [ ("keyboard_output", valid_hid_keyboard_output), ("mouse_output", valid_hid_mouse_output), ("jiggler", valid_bool), ] - if request.query.get(key) is not None + if req.query.get(key) is not None } self.__hid.set_params(**params) # type: ignore return make_json_response() @exposed_http("POST", "/hid/set_connected") - async def __set_connected_handler(self, request: Request) -> Response: - self.__hid.set_connected(valid_bool(request.query.get("connected"))) + async def __set_connected_handler(self, req: Request) -> Response: + self.__hid.set_connected(valid_bool(req.query.get("connected"))) return make_json_response() @exposed_http("POST", "/hid/reset") @@ -128,12 +128,12 @@ class HidApi: return make_json_response(await self.get_keymaps()) @exposed_http("POST", "/hid/print") - async def __print_handler(self, request: Request) -> Response: - text = await request.text() - limit = int(valid_int_f0(request.query.get("limit", 1024))) + async def __print_handler(self, req: Request) -> Response: + text = await req.text() + limit = int(valid_int_f0(req.query.get("limit", 1024))) if limit > 0: text = text[:limit] - symmap = self.__ensure_symmap(request.query.get("keymap", self.__default_keymap_name)) + symmap = self.__ensure_symmap(req.query.get("keymap", self.__default_keymap_name)) self.__hid.send_key_events(text_to_web_keys(text, symmap)) return make_json_response() @@ -257,21 +257,21 @@ class HidApi: # ===== @exposed_http("POST", "/hid/events/send_key") - async def __events_send_key_handler(self, request: Request) -> Response: - key = valid_hid_key(request.query.get("key")) + async def __events_send_key_handler(self, req: Request) -> Response: + key = valid_hid_key(req.query.get("key")) if key not in self.__ignore_keys: - if "state" in request.query: - state = valid_bool(request.query["state"]) + if "state" in req.query: + state = valid_bool(req.query["state"]) self.__hid.send_key_events([(key, state)]) else: self.__hid.send_key_events([(key, True), (key, False)]) return make_json_response() @exposed_http("POST", "/hid/events/send_mouse_button") - async def __events_send_mouse_button_handler(self, request: Request) -> Response: - button = valid_hid_mouse_button(request.query.get("button")) - if "state" in request.query: - state = valid_bool(request.query["state"]) + async def __events_send_mouse_button_handler(self, req: Request) -> Response: + button = valid_hid_mouse_button(req.query.get("button")) + if "state" in req.query: + state = valid_bool(req.query["state"]) self.__hid.send_mouse_button_event(button, state) else: self.__hid.send_mouse_button_event(button, True) @@ -279,23 +279,23 @@ class HidApi: return make_json_response() @exposed_http("POST", "/hid/events/send_mouse_move") - async def __events_send_mouse_move_handler(self, request: Request) -> Response: - to_x = valid_hid_mouse_move(request.query.get("to_x")) - to_y = valid_hid_mouse_move(request.query.get("to_y")) + async def __events_send_mouse_move_handler(self, req: Request) -> Response: + to_x = valid_hid_mouse_move(req.query.get("to_x")) + to_y = valid_hid_mouse_move(req.query.get("to_y")) self.__send_mouse_move_event(to_x, to_y) return make_json_response() @exposed_http("POST", "/hid/events/send_mouse_relative") - async def __events_send_mouse_relative_handler(self, request: Request) -> Response: - return self.__process_http_delta_event(request, self.__hid.send_mouse_relative_event) + async def __events_send_mouse_relative_handler(self, req: Request) -> Response: + return self.__process_http_delta_event(req, self.__hid.send_mouse_relative_event) @exposed_http("POST", "/hid/events/send_mouse_wheel") - async def __events_send_mouse_wheel_handler(self, request: Request) -> Response: - return self.__process_http_delta_event(request, self.__hid.send_mouse_wheel_event) + async def __events_send_mouse_wheel_handler(self, req: Request) -> Response: + return self.__process_http_delta_event(req, self.__hid.send_mouse_wheel_event) - def __process_http_delta_event(self, request: Request, handler: Callable[[int, int], None]) -> Response: - delta_x = valid_hid_mouse_delta(request.query.get("delta_x")) - delta_y = valid_hid_mouse_delta(request.query.get("delta_y")) + def __process_http_delta_event(self, req: Request, handler: Callable[[int, int], None]) -> Response: + delta_x = valid_hid_mouse_delta(req.query.get("delta_x")) + delta_y = valid_hid_mouse_delta(req.query.get("delta_y")) handler(delta_x, delta_y) return make_json_response() diff --git a/kvmd/apps/kvmd/api/info.py b/kvmd/apps/kvmd/api/info.py index 6a7fbf4e..a0be01a5 100644 --- a/kvmd/apps/kvmd/api/info.py +++ b/kvmd/apps/kvmd/api/info.py @@ -41,17 +41,17 @@ class InfoApi: # ===== @exposed_http("GET", "/info") - async def __common_state_handler(self, request: Request) -> Response: - fields = self.__valid_info_fields(request) + async def __common_state_handler(self, req: Request) -> Response: + fields = self.__valid_info_fields(req) results = dict(zip(fields, await asyncio.gather(*[ self.__info_manager.get_submanager(field).get_state() for field in fields ]))) return make_json_response(results) - def __valid_info_fields(self, request: Request) -> list[str]: + def __valid_info_fields(self, req: Request) -> list[str]: subs = self.__info_manager.get_subs() return sorted(valid_info_fields( - arg=request.query.get("fields", ",".join(subs)), + arg=req.query.get("fields", ",".join(subs)), variants=subs, ) or subs) diff --git a/kvmd/apps/kvmd/api/log.py b/kvmd/apps/kvmd/api/log.py index 5bead7f7..c82d6bd9 100644 --- a/kvmd/apps/kvmd/api/log.py +++ b/kvmd/apps/kvmd/api/log.py @@ -47,12 +47,12 @@ class LogApi: # ===== @exposed_http("GET", "/log") - async def __log_handler(self, request: Request) -> StreamResponse: + async def __log_handler(self, req: Request) -> StreamResponse: if self.__log_reader is None: raise LogReaderDisabledError() - seek = valid_log_seek(request.query.get("seek", 0)) - follow = valid_bool(request.query.get("follow", False)) - response = await start_streaming(request, "text/plain") + seek = valid_log_seek(req.query.get("seek", 0)) + follow = valid_bool(req.query.get("follow", False)) + response = await start_streaming(req, "text/plain") async for record in self.__log_reader.poll_log(seek, follow): await response.write(("[%s %s] --- %s" % ( record["dt"].strftime("%Y-%m-%d %H:%M:%S"), diff --git a/kvmd/apps/kvmd/api/msd.py b/kvmd/apps/kvmd/api/msd.py index dcb6ef62..2fa2eb9b 100644 --- a/kvmd/apps/kvmd/api/msd.py +++ b/kvmd/apps/kvmd/api/msd.py @@ -66,29 +66,29 @@ class MsdApi: return make_json_response(await self.__msd.get_state()) @exposed_http("POST", "/msd/set_params") - async def __set_params_handler(self, request: Request) -> Response: + async def __set_params_handler(self, req: Request) -> Response: params = { - key: validator(request.query.get(param)) + key: validator(req.query.get(param)) for (param, key, validator) in [ ("image", "name", (lambda arg: str(arg).strip() and valid_msd_image_name(arg))), ("cdrom", "cdrom", valid_bool), ("rw", "rw", valid_bool), ] - if request.query.get(param) is not None + if req.query.get(param) is not None } await self.__msd.set_params(**params) # type: ignore return make_json_response() @exposed_http("POST", "/msd/set_connected") - async def __set_connected_handler(self, request: Request) -> Response: - await self.__msd.set_connected(valid_bool(request.query.get("connected"))) + async def __set_connected_handler(self, req: Request) -> Response: + await self.__msd.set_connected(valid_bool(req.query.get("connected"))) return make_json_response() # ===== @exposed_http("GET", "/msd/read") - async def __read_handler(self, request: Request) -> StreamResponse: - name = valid_msd_image_name(request.query.get("image")) + async def __read_handler(self, req: Request) -> StreamResponse: + name = valid_msd_image_name(req.query.get("image")) compressors = { "": ("", None), "none": ("", None), @@ -96,7 +96,7 @@ class MsdApi: "zstd": (".zst", (lambda: zstandard.ZstdCompressor().compressobj())), # pylint: disable=unnecessary-lambda } (suffix, make_compressor) = compressors[check_string_in_list( - arg=request.query.get("compress", ""), + arg=req.query.get("compress", ""), name="Compression mode", variants=set(compressors), )] @@ -127,7 +127,7 @@ class MsdApi: src = compressed() size = -1 - response = await start_streaming(request, "application/octet-stream", size, name + suffix) + response = await start_streaming(req, "application/octet-stream", size, name + suffix) async for chunk in src: await response.write(chunk) return response @@ -135,28 +135,28 @@ class MsdApi: # ===== @exposed_http("POST", "/msd/write") - async def __write_handler(self, request: Request) -> Response: - unsafe_prefix = request.query.get("prefix", "") + "/" - name = valid_msd_image_name(unsafe_prefix + request.query.get("image", "")) - size = valid_int_f0(request.content_length) - remove_incomplete = self.__get_remove_incomplete(request) + async def __write_handler(self, req: Request) -> Response: + unsafe_prefix = req.query.get("prefix", "") + "/" + name = valid_msd_image_name(unsafe_prefix + req.query.get("image", "")) + size = valid_int_f0(req.content_length) + remove_incomplete = self.__get_remove_incomplete(req) written = 0 async with self.__msd.write_image(name, size, remove_incomplete) as writer: chunk_size = writer.get_chunk_size() while True: - chunk = await request.content.read(chunk_size) + chunk = await req.content.read(chunk_size) if not chunk: break written = await writer.write_chunk(chunk) return make_json_response(self.__make_write_info(name, size, written)) @exposed_http("POST", "/msd/write_remote") - async def __write_remote_handler(self, request: Request) -> (Response | StreamResponse): # pylint: disable=too-many-locals - unsafe_prefix = request.query.get("prefix", "") + "/" - url = valid_url(request.query.get("url")) - insecure = valid_bool(request.query.get("insecure", False)) - timeout = valid_float_f01(request.query.get("timeout", 10.0)) - remove_incomplete = self.__get_remove_incomplete(request) + async def __write_remote_handler(self, req: Request) -> (Response | StreamResponse): # pylint: disable=too-many-locals + unsafe_prefix = req.query.get("prefix", "") + "/" + url = valid_url(req.query.get("url")) + insecure = valid_bool(req.query.get("insecure", False)) + timeout = valid_float_f01(req.query.get("timeout", 10.0)) + remove_incomplete = self.__get_remove_incomplete(req) name = "" size = written = 0 @@ -174,7 +174,7 @@ class MsdApi: read_timeout=(7 * 24 * 3600), ) as remote: - name = str(request.query.get("image", "")).strip() + name = str(req.query.get("image", "")).strip() if len(name) == 0: name = htclient.get_filename(remote) name = valid_msd_image_name(unsafe_prefix + name) @@ -184,7 +184,7 @@ class MsdApi: get_logger(0).info("Downloading image %r as %r to MSD ...", url, name) async with self.__msd.write_image(name, size, remove_incomplete) as writer: chunk_size = writer.get_chunk_size() - response = await start_streaming(request, "application/x-ndjson") + response = await start_streaming(req, "application/x-ndjson") await stream_write_info() last_report_ts = 0 async for chunk in remote.content.iter_chunked(chunk_size): @@ -197,16 +197,16 @@ class MsdApi: await stream_write_info() return response - except Exception as err: + except Exception as ex: if response is not None: await stream_write_info() - await stream_json_exception(response, err) - elif isinstance(err, aiohttp.ClientError): - return make_json_exception(err, 400) + await stream_json_exception(response, ex) + elif isinstance(ex, aiohttp.ClientError): + return make_json_exception(ex, 400) raise - def __get_remove_incomplete(self, request: Request) -> (bool | None): - flag: (str | None) = request.query.get("remove_incomplete") + def __get_remove_incomplete(self, req: Request) -> (bool | None): + flag: (str | None) = req.query.get("remove_incomplete") return (valid_bool(flag) if flag is not None else None) def __make_write_info(self, name: str, size: int, written: int) -> dict: @@ -215,8 +215,8 @@ class MsdApi: # ===== @exposed_http("POST", "/msd/remove") - async def __remove_handler(self, request: Request) -> Response: - await self.__msd.remove(valid_msd_image_name(request.query.get("image"))) + async def __remove_handler(self, req: Request) -> Response: + await self.__msd.remove(valid_msd_image_name(req.query.get("image"))) return make_json_response() @exposed_http("POST", "/msd/reset") diff --git a/kvmd/apps/kvmd/api/redfish.py b/kvmd/apps/kvmd/api/redfish.py index 3aaa1812..e1822496 100644 --- a/kvmd/apps/kvmd/api/redfish.py +++ b/kvmd/apps/kvmd/api/redfish.py @@ -111,10 +111,10 @@ class RedfishApi: }, wrap_result=False) @exposed_http("POST", "/redfish/v1/Systems/0/Actions/ComputerSystem.Reset") - async def __power_handler(self, request: Request) -> Response: + async def __power_handler(self, req: Request) -> Response: try: action = check_string_in_list( - arg=(await request.json())["ResetType"], + arg=(await req.json()).get("ResetType"), name="Redfish ResetType", variants=set(self.__actions), lower=False, diff --git a/kvmd/apps/kvmd/api/streamer.py b/kvmd/apps/kvmd/api/streamer.py index f384eb17..fc8e01de 100644 --- a/kvmd/apps/kvmd/api/streamer.py +++ b/kvmd/apps/kvmd/api/streamer.py @@ -52,36 +52,36 @@ class StreamerApi: return make_json_response(await self.__streamer.get_state()) @exposed_http("GET", "/streamer/snapshot") - async def __take_snapshot_handler(self, request: Request) -> Response: + async def __take_snapshot_handler(self, req: Request) -> Response: snapshot = await self.__streamer.take_snapshot( - save=valid_bool(request.query.get("save", False)), - load=valid_bool(request.query.get("load", False)), - allow_offline=valid_bool(request.query.get("allow_offline", False)), + save=valid_bool(req.query.get("save", False)), + load=valid_bool(req.query.get("load", False)), + allow_offline=valid_bool(req.query.get("allow_offline", False)), ) if snapshot: - if valid_bool(request.query.get("ocr", False)): + if valid_bool(req.query.get("ocr", False)): langs = self.__ocr.get_available_langs() return Response( body=(await self.__ocr.recognize( data=snapshot.data, langs=valid_string_list( - arg=str(request.query.get("ocr_langs", "")).strip(), + arg=str(req.query.get("ocr_langs", "")).strip(), subval=(lambda lang: check_string_in_list(lang, "OCR lang", langs)), name="OCR langs list", ), - left=int(valid_number(request.query.get("ocr_left", -1))), - top=int(valid_number(request.query.get("ocr_top", -1))), - right=int(valid_number(request.query.get("ocr_right", -1))), - bottom=int(valid_number(request.query.get("ocr_bottom", -1))), + left=int(valid_number(req.query.get("ocr_left", -1))), + top=int(valid_number(req.query.get("ocr_top", -1))), + right=int(valid_number(req.query.get("ocr_right", -1))), + bottom=int(valid_number(req.query.get("ocr_bottom", -1))), )), headers=dict(snapshot.headers), content_type="text/plain", ) - elif valid_bool(request.query.get("preview", False)): + elif valid_bool(req.query.get("preview", False)): data = await snapshot.make_preview( - max_width=valid_int_f0(request.query.get("preview_max_width", 0)), - max_height=valid_int_f0(request.query.get("preview_max_height", 0)), - quality=valid_stream_quality(request.query.get("preview_quality", 80)), + max_width=valid_int_f0(req.query.get("preview_max_width", 0)), + max_height=valid_int_f0(req.query.get("preview_max_height", 0)), + quality=valid_stream_quality(req.query.get("preview_quality", 80)), ) else: data = snapshot.data diff --git a/kvmd/apps/kvmd/api/ugpio.py b/kvmd/apps/kvmd/api/ugpio.py index 3e5f7ca3..ddaefefa 100644 --- a/kvmd/apps/kvmd/api/ugpio.py +++ b/kvmd/apps/kvmd/api/ugpio.py @@ -48,17 +48,17 @@ class UserGpioApi: }) @exposed_http("POST", "/gpio/switch") - async def __switch_handler(self, request: Request) -> Response: - channel = valid_ugpio_channel(request.query.get("channel")) - state = valid_bool(request.query.get("state")) - wait = valid_bool(request.query.get("wait", False)) + async def __switch_handler(self, req: Request) -> Response: + channel = valid_ugpio_channel(req.query.get("channel")) + state = valid_bool(req.query.get("state")) + wait = valid_bool(req.query.get("wait", False)) await self.__user_gpio.switch(channel, state, wait) return make_json_response() @exposed_http("POST", "/gpio/pulse") - async def __pulse_handler(self, request: Request) -> Response: - channel = valid_ugpio_channel(request.query.get("channel")) - delay = valid_float_f0(request.query.get("delay", 0.0)) - wait = valid_bool(request.query.get("wait", False)) + async def __pulse_handler(self, req: Request) -> Response: + channel = valid_ugpio_channel(req.query.get("channel")) + delay = valid_float_f0(req.query.get("delay", 0.0)) + wait = valid_bool(req.query.get("wait", False)) await self.__user_gpio.pulse(channel, delay, wait) return make_json_response() diff --git a/kvmd/apps/kvmd/info/extras.py b/kvmd/apps/kvmd/info/extras.py index a5f803bc..07225013 100644 --- a/kvmd/apps/kvmd/info/extras.py +++ b/kvmd/apps/kvmd/info/extras.py @@ -46,8 +46,8 @@ class ExtrasInfoSubmanager(BaseInfoSubmanager): try: sui = sysunit.SystemdUnitInfo() await sui.open() - except Exception as err: - get_logger(0).error("Can't open systemd bus to get extras state: %s", tools.efmt(err)) + except Exception as ex: + get_logger(0).error("Can't open systemd bus to get extras state: %s", tools.efmt(ex)) sui = None try: extras: dict[str, dict] = {} @@ -85,8 +85,8 @@ class ExtrasInfoSubmanager(BaseInfoSubmanager): if sui is not None: try: (extra["enabled"], extra["started"]) = await sui.get_status(daemon) - except Exception as err: - get_logger(0).error("Can't get info about the service %r: %s", daemon, tools.efmt(err)) + except Exception as ex: + get_logger(0).error("Can't get info about the service %r: %s", daemon, tools.efmt(ex)) def __rewrite_app_port(self, extra: dict) -> None: port_path = extra.get("port", "") diff --git a/kvmd/apps/kvmd/info/fan.py b/kvmd/apps/kvmd/info/fan.py index 48f4f6d5..247aff7d 100644 --- a/kvmd/apps/kvmd/info/fan.py +++ b/kvmd/apps/kvmd/info/fan.py @@ -87,8 +87,8 @@ class FanInfoSubmanager(BaseInfoSubmanager): async with sysunit.SystemdUnitInfo() as sui: status = await sui.get_status(self.__daemon) return (status[0] or status[1]) - except Exception as err: - get_logger(0).error("Can't get info about the service %r: %s", self.__daemon, tools.efmt(err)) + except Exception as ex: + get_logger(0).error("Can't get info about the service %r: %s", self.__daemon, tools.efmt(ex)) return False async def __get_fan_state(self) -> (dict | None): @@ -97,8 +97,8 @@ class FanInfoSubmanager(BaseInfoSubmanager): async with session.get("http://localhost/state") as response: htclient.raise_not_200(response) return (await response.json())["result"] - except Exception as err: - get_logger(0).error("Can't read fan state: %s", err) + except Exception as ex: + get_logger(0).error("Can't read fan state: %s", ex) return None def __make_http_session(self) -> aiohttp.ClientSession: diff --git a/kvmd/apps/kvmd/info/hw.py b/kvmd/apps/kvmd/info/hw.py index 2222ace3..458bc1ec 100644 --- a/kvmd/apps/kvmd/info/hw.py +++ b/kvmd/apps/kvmd/info/hw.py @@ -114,8 +114,8 @@ class HwInfoSubmanager(BaseInfoSubmanager): try: value = (await aiotools.read_file(path)).strip(" \t\r\n\0") self.__dt_cache[name] = (value.upper() if upper else value) - except Exception as err: - get_logger(0).error("Can't read DT %s from %s: %s", name, path, err) + except Exception as ex: + get_logger(0).error("Can't read DT %s from %s: %s", name, path, ex) return None return self.__dt_cache[name] @@ -141,8 +141,8 @@ class HwInfoSubmanager(BaseInfoSubmanager): temp_path = f"{env.SYSFS_PREFIX}/sys/class/thermal/thermal_zone0/temp" try: 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) + except Exception as ex: + get_logger(0).error("Can't read CPU temp from %s: %s", temp_path, ex) return None async def __get_cpu_percent(self) -> (float | None): @@ -160,8 +160,8 @@ class HwInfoSubmanager(BaseInfoSubmanager): + system_all / total * 100 + (st.steal + st.guest) / total * 100 ) - except Exception as err: - get_logger(0).error("Can't get CPU percent: %s", err) + except Exception as ex: + get_logger(0).error("Can't get CPU percent: %s", ex) return None async def __get_mem(self) -> dict: @@ -172,8 +172,8 @@ class HwInfoSubmanager(BaseInfoSubmanager): "total": st.total, "available": st.available, } - except Exception as err: - get_logger(0).error("Can't get memory info: %s", err) + except Exception as ex: + get_logger(0).error("Can't get memory info: %s", ex) return { "percent": None, "total": None, @@ -216,6 +216,6 @@ class HwInfoSubmanager(BaseInfoSubmanager): return None try: return parser(text) - except Exception as err: - get_logger(0).error("Can't parse [ %s ] output: %r: %s", tools.cmdfmt(cmd), text, tools.efmt(err)) + except Exception as ex: + get_logger(0).error("Can't parse [ %s ] output: %r: %s", tools.cmdfmt(cmd), text, tools.efmt(ex)) return None diff --git a/kvmd/apps/kvmd/ocr.py b/kvmd/apps/kvmd/ocr.py index bd30afa6..0a632d9d 100644 --- a/kvmd/apps/kvmd/ocr.py +++ b/kvmd/apps/kvmd/ocr.py @@ -76,8 +76,8 @@ def _load_libtesseract() -> (ctypes.CDLL | None): setattr(func, "restype", restype) setattr(func, "argtypes", argtypes) return lib - except Exception as err: - warnings.warn(f"Can't load libtesseract: {err}", RuntimeWarning) + except Exception as ex: + warnings.warn(f"Can't load libtesseract: {ex}", RuntimeWarning) return None diff --git a/kvmd/apps/kvmd/server.py b/kvmd/apps/kvmd/server.py index 44f33f89..366958ce 100644 --- a/kvmd/apps/kvmd/server.py +++ b/kvmd/apps/kvmd/server.py @@ -213,7 +213,7 @@ class KvmdServer(HttpServer): # pylint: disable=too-many-arguments,too-many-ins # ===== STREAMER CONTROLLER @exposed_http("POST", "/streamer/set_params") - async def __streamer_set_params_handler(self, request: Request) -> Response: + async def __streamer_set_params_handler(self, req: Request) -> Response: current_params = self.__streamer.get_params() for (name, validator, exc_cls) in [ ("quality", valid_stream_quality, StreamerQualityNotSupported), @@ -222,7 +222,7 @@ class KvmdServer(HttpServer): # pylint: disable=too-many-arguments,too-many-ins ("h264_bitrate", valid_stream_h264_bitrate, StreamerH264NotSupported), ("h264_gop", valid_stream_h264_gop, StreamerH264NotSupported), ]: - value = request.query.get(name) + value = req.query.get(name) if value: if name not in current_params: assert exc_cls is not None, name @@ -242,9 +242,9 @@ class KvmdServer(HttpServer): # pylint: disable=too-many-arguments,too-many-ins # ===== WEBSOCKET @exposed_http("GET", "/ws") - async def __ws_handler(self, request: Request) -> WebSocketResponse: - stream = valid_bool(request.query.get("stream", True)) - async with self._ws_session(request, stream=stream) as ws: + async def __ws_handler(self, req: Request) -> WebSocketResponse: + stream = valid_bool(req.query.get("stream", True)) + async with self._ws_session(req, stream=stream) as ws: states = [ (event_type, src.get_state()) for sub in self.__subsystems @@ -275,8 +275,8 @@ class KvmdServer(HttpServer): # pylint: disable=too-many-arguments,too-many-ins aioproc.rename_process("main") super().run(**kwargs) - async def _check_request_auth(self, exposed: HttpExposed, request: Request) -> None: - await check_request_auth(self.__auth_manager, exposed, request) + async def _check_request_auth(self, exposed: HttpExposed, req: Request) -> None: + await check_request_auth(self.__auth_manager, exposed, req) async def _init_app(self) -> None: aiotools.create_deadly_task("Stream controller", self.__stream_controller()) diff --git a/kvmd/apps/kvmd/streamer.py b/kvmd/apps/kvmd/streamer.py index e5c406d9..c365e19d 100644 --- a/kvmd/apps/kvmd/streamer.py +++ b/kvmd/apps/kvmd/streamer.py @@ -386,8 +386,8 @@ 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", tools.efmt(err)) + except (aiohttp.ClientConnectionError, aiohttp.ServerConnectionError) as ex: + logger.error("Can't connect to streamer: %s", tools.efmt(ex)) except Exception: logger.exception("Invalid streamer response from /snapshot") return None @@ -473,8 +473,8 @@ class Streamer: # pylint: disable=too-many-instance-attributes logger.info("%s: %s", name, tools.cmdfmt(cmd)) try: await aioproc.log_process(cmd, logger, prefix=name) - except Exception as err: - logger.exception("Can't execute command: %s", err) + except Exception as ex: + logger.exception("Can't execute command: %s", ex) async def __start_streamer_proc(self) -> None: assert self.__streamer_proc is None diff --git a/kvmd/apps/kvmd/sysunit.py b/kvmd/apps/kvmd/sysunit.py index eea397ed..bcb41c34 100644 --- a/kvmd/apps/kvmd/sysunit.py +++ b/kvmd/apps/kvmd/sysunit.py @@ -51,8 +51,8 @@ class SystemdUnitInfo: unit_props = unit.get_interface("org.freedesktop.DBus.Properties") started = ((await unit_props.call_get("org.freedesktop.systemd1.Unit", "ActiveState")).value == "active") # type: ignore self.__requested = True - except dbus_next.errors.DBusError as err: - if err.type != "org.freedesktop.systemd1.NoSuchUnit": + except dbus_next.errors.DBusError as ex: + if ex.type != "org.freedesktop.systemd1.NoSuchUnit": raise started = False enabled = ((await self.__manager.call_get_unit_file_state(name)) in [ # type: ignore diff --git a/kvmd/apps/otg/__init__.py b/kvmd/apps/otg/__init__.py index 1da23c67..b683c5fd 100644 --- a/kvmd/apps/otg/__init__.py +++ b/kvmd/apps/otg/__init__.py @@ -346,5 +346,5 @@ def main(argv: (list[str] | None)=None) -> None: options = parser.parse_args(argv[1:]) try: options.cmd(config) - except ValidatorError as err: - raise SystemExit(str(err)) + except ValidatorError as ex: + raise SystemExit(str(ex)) diff --git a/kvmd/apps/otgmsd/__init__.py b/kvmd/apps/otgmsd/__init__.py index abe2400c..7d5bfdbc 100644 --- a/kvmd/apps/otgmsd/__init__.py +++ b/kvmd/apps/otgmsd/__init__.py @@ -47,9 +47,9 @@ def _set_param(gadget: str, instance: int, param: str, value: str) -> None: try: with open(_get_param_path(gadget, instance, param), "w") as file: file.write(value + "\n") - except OSError as err: - if err.errno == errno.EBUSY: - raise SystemExit(f"Can't change {param!r} value because device is locked: {err}") + except OSError as ex: + if ex.errno == errno.EBUSY: + raise SystemExit(f"Can't change {param!r} value because device is locked: {ex}") raise diff --git a/kvmd/apps/otgnet/__init__.py b/kvmd/apps/otgnet/__init__.py index 3519d98b..35c0bc45 100644 --- a/kvmd/apps/otgnet/__init__.py +++ b/kvmd/apps/otgnet/__init__.py @@ -133,8 +133,8 @@ class _Service: # pylint: disable=too-many-instance-attributes logger.info("CMD: %s", tools.cmdfmt(cmd)) try: return (not (await aioproc.log_process(cmd, logger)).returncode) - except Exception as err: - logger.exception("Can't execute command: %s", err) + except Exception as ex: + logger.exception("Can't execute command: %s", ex) return False # ===== diff --git a/kvmd/apps/pst/server.py b/kvmd/apps/pst/server.py index 359faf9a..79bbf7c8 100644 --- a/kvmd/apps/pst/server.py +++ b/kvmd/apps/pst/server.py @@ -60,8 +60,8 @@ class PstServer(HttpServer): # pylint: disable=too-many-arguments,too-many-inst # ===== WEBSOCKET @exposed_http("GET", "/ws") - async def __ws_handler(self, request: Request) -> WebSocketResponse: - async with self._ws_session(request) as ws: + async def __ws_handler(self, req: Request) -> WebSocketResponse: + async with self._ws_session(req) as ws: await ws.send_event("loop", {}) return (await self._ws_loop(ws)) @@ -128,9 +128,9 @@ class PstServer(HttpServer): # pylint: disable=too-many-arguments,too-many-inst def __is_write_available(self) -> bool: try: return (not (os.statvfs(self.__data_path).f_flag & os.ST_RDONLY)) - except Exception as err: + except Exception as ex: get_logger(0).info("Can't get filesystem state of PST (%s): %s", - self.__data_path, tools.efmt(err)) + self.__data_path, tools.efmt(ex)) return False async def __remount_storage(self, rw: bool) -> bool: diff --git a/kvmd/apps/pstrun/__init__.py b/kvmd/apps/pstrun/__init__.py index f7dd537d..33e1396e 100644 --- a/kvmd/apps/pstrun/__init__.py +++ b/kvmd/apps/pstrun/__init__.py @@ -46,8 +46,8 @@ def _preexec() -> None: if os.isatty(0): try: os.tcsetpgrp(0, os.getpgid(0)) - except Exception as err: - get_logger(0).info("Can't perform tcsetpgrp(0): %s", tools.efmt(err)) + except Exception as ex: + get_logger(0).info("Can't perform tcsetpgrp(0): %s", tools.efmt(ex)) async def _run_process(cmd: list[str], data_path: str) -> asyncio.subprocess.Process: # pylint: disable=no-member diff --git a/kvmd/apps/vnc/rfb/__init__.py b/kvmd/apps/vnc/rfb/__init__.py index ac4e0354..c145b4b3 100644 --- a/kvmd/apps/vnc/rfb/__init__.py +++ b/kvmd/apps/vnc/rfb/__init__.py @@ -120,10 +120,10 @@ class RfbClient(RfbClientStream): # pylint: disable=too-many-instance-attribute except asyncio.CancelledError: logger.info("%s [%s]: Cancelling subtask ...", self._remote, name) raise - except RfbConnectionError as err: - logger.info("%s [%s]: Gone: %s", self._remote, name, err) - except (RfbError, ssl.SSLError) as err: - logger.error("%s [%s]: Error: %s", self._remote, name, err) + except RfbConnectionError as ex: + logger.info("%s [%s]: Gone: %s", self._remote, name, ex) + except (RfbError, ssl.SSLError) as ex: + logger.error("%s [%s]: Error: %s", self._remote, name, ex) except Exception: logger.exception("%s [%s]: Unhandled exception", self._remote, name) diff --git a/kvmd/apps/vnc/rfb/errors.py b/kvmd/apps/vnc/rfb/errors.py index 1cf68818..caa4d085 100644 --- a/kvmd/apps/vnc/rfb/errors.py +++ b/kvmd/apps/vnc/rfb/errors.py @@ -29,5 +29,5 @@ class RfbError(Exception): class RfbConnectionError(RfbError): - def __init__(self, msg: str, err: Exception) -> None: - super().__init__(f"{msg}: {tools.efmt(err)}") + def __init__(self, msg: str, ex: Exception) -> None: + super().__init__(f"{msg}: {tools.efmt(ex)}") diff --git a/kvmd/apps/vnc/rfb/stream.py b/kvmd/apps/vnc/rfb/stream.py index 44998617..dc3ceb1b 100644 --- a/kvmd/apps/vnc/rfb/stream.py +++ b/kvmd/apps/vnc/rfb/stream.py @@ -51,22 +51,22 @@ class RfbClientStream: else: fmt = f">{fmt}" return struct.unpack(fmt, await self.__reader.readexactly(struct.calcsize(fmt)))[0] - except (ConnectionError, asyncio.IncompleteReadError) as err: - raise RfbConnectionError(f"Can't read {msg}", err) + except (ConnectionError, asyncio.IncompleteReadError) as ex: + raise RfbConnectionError(f"Can't read {msg}", ex) async def _read_struct(self, msg: str, fmt: str) -> tuple[int, ...]: assert len(fmt) > 1 try: fmt = f">{fmt}" return struct.unpack(fmt, (await self.__reader.readexactly(struct.calcsize(fmt)))) - except (ConnectionError, asyncio.IncompleteReadError) as err: - raise RfbConnectionError(f"Can't read {msg}", err) + except (ConnectionError, asyncio.IncompleteReadError) as ex: + raise RfbConnectionError(f"Can't read {msg}", ex) async def _read_text(self, msg: str, length: int) -> str: try: return (await self.__reader.readexactly(length)).decode("utf-8", errors="ignore") - except (ConnectionError, asyncio.IncompleteReadError) as err: - raise RfbConnectionError(f"Can't read {msg}", err) + except (ConnectionError, asyncio.IncompleteReadError) as ex: + raise RfbConnectionError(f"Can't read {msg}", ex) # ===== @@ -84,8 +84,8 @@ class RfbClientStream: self.__writer.write(struct.pack(f">{fmt}", *values)) if drain: await self.__writer.drain() - except ConnectionError as err: - raise RfbConnectionError(f"Can't write {msg}", err) + except ConnectionError as ex: + raise RfbConnectionError(f"Can't write {msg}", ex) async def _write_reason(self, msg: str, text: str, drain: bool=True) -> None: encoded = text.encode("utf-8", errors="ignore") @@ -94,8 +94,8 @@ class RfbClientStream: self.__writer.write(encoded) if drain: await self.__writer.drain() - except ConnectionError as err: - raise RfbConnectionError(f"Can't write {msg}", err) + except ConnectionError as ex: + raise RfbConnectionError(f"Can't write {msg}", ex) async def _write_fb_update(self, msg: str, width: int, height: int, encoding: int, drain: bool=True) -> None: await self._write_struct( @@ -123,8 +123,8 @@ class RfbClientStream: server_side=True, ssl_handshake_timeout=ssl_timeout, ) - except ConnectionError as err: - raise RfbConnectionError("Can't start TLS", err) + except ConnectionError as ex: + raise RfbConnectionError("Can't start TLS", ex) ssl_reader.set_transport(transport) # type: ignore ssl_writer = asyncio.StreamWriter( diff --git a/kvmd/apps/vnc/server.py b/kvmd/apps/vnc/server.py index 6ec3960e..f8e97050 100644 --- a/kvmd/apps/vnc/server.py +++ b/kvmd/apps/vnc/server.py @@ -210,12 +210,12 @@ class _Client(RfbClient): # pylint: disable=too-many-instance-attributes await self.__queue_frame(frame) else: await self.__queue_frame("No signal") - except StreamerError as err: - if isinstance(err, StreamerPermError): + except StreamerError as ex: + if isinstance(ex, StreamerPermError): streamer = self.__get_default_streamer() - logger.info("%s [streamer]: Permanent error: %s; switching to %s ...", self._remote, err, streamer) + logger.info("%s [streamer]: Permanent error: %s; switching to %s ...", self._remote, ex, streamer) else: - logger.info("%s [streamer]: Waiting for stream: %s", self._remote, err) + logger.info("%s [streamer]: Waiting for stream: %s", self._remote, ex) await self.__queue_frame("Waiting for stream ...") await asyncio.sleep(1) @@ -481,8 +481,8 @@ class VncServer: # pylint: disable=too-many-instance-attributes try: 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("%s [entry]: Can't check KVMD auth mode: %s", remote, tools.efmt(err)) + except (aiohttp.ClientError, asyncio.TimeoutError) as ex: + logger.error("%s [entry]: Can't check KVMD auth mode: %s", remote, tools.efmt(ex)) return await _Client( diff --git a/kvmd/apps/vnc/vncauth.py b/kvmd/apps/vnc/vncauth.py index ebda9ef4..46c1a77d 100644 --- a/kvmd/apps/vnc/vncauth.py +++ b/kvmd/apps/vnc/vncauth.py @@ -54,8 +54,8 @@ class VncAuthManager: if self.__enabled: try: return (await self.__inner_read_credentials(), True) - except VncAuthError as err: - get_logger(0).error(str(err)) + except VncAuthError as ex: + get_logger(0).error(str(ex)) except Exception: get_logger(0).exception("Unhandled exception while reading VNCAuth passwd file") return ({}, (not self.__enabled)) diff --git a/kvmd/apps/watchdog/__init__.py b/kvmd/apps/watchdog/__init__.py index 37981d0b..c2b03730 100644 --- a/kvmd/apps/watchdog/__init__.py +++ b/kvmd/apps/watchdog/__init__.py @@ -56,8 +56,8 @@ def _write_int(rtc: int, key: str, value: int) -> None: def _reset_alarm(rtc: int, timeout: int) -> None: try: now = _read_int(rtc, "since_epoch") - except OSError as err: - if err.errno != errno.EINVAL: + except OSError as ex: + if ex.errno != errno.EINVAL: raise raise RtcIsNotAvailableError("Can't read since_epoch right now") if now == 0: @@ -65,8 +65,8 @@ def _reset_alarm(rtc: int, timeout: int) -> None: try: for wake in [0, now + timeout]: _write_int(rtc, "wakealarm", wake) - except OSError as err: - if err.errno != errno.EIO: + except OSError as ex: + if ex.errno != errno.EIO: raise raise RtcIsNotAvailableError("IO error, probably the supercapacitor is not charged") @@ -80,9 +80,9 @@ def _cmd_run(config: Section) -> None: while True: try: _reset_alarm(config.rtc, config.timeout) - except RtcIsNotAvailableError as err: + except RtcIsNotAvailableError as ex: if not fail: - logger.error("RTC%d is not available now: %s; waiting ...", config.rtc, err) + logger.error("RTC%d is not available now: %s; waiting ...", config.rtc, ex) fail = True else: if fail: |