diff options
author | Devaev Maxim <[email protected]> | 2019-06-01 03:54:40 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2019-06-01 03:54:40 +0300 |
commit | 7037bb0cfafbceb98da478a9d182aa0c43162eb2 (patch) | |
tree | bd25590203b44d0a3688fe74955ae3116790a9b3 | |
parent | 187a195011aacc66cd8652f0af81ee0300bb7381 (diff) |
using dataclasses instead of typed namedtuple
-rwxr-xr-x | genmap.py | 5 | ||||
-rw-r--r-- | kvmd/apps/ipmi/auth.py | 6 | ||||
-rw-r--r-- | kvmd/apps/kvmd/hid.py | 12 | ||||
-rw-r--r-- | kvmd/apps/kvmd/msd.py | 17 |
4 files changed, 23 insertions, 17 deletions
@@ -23,15 +23,16 @@ import sys import textwrap +import dataclasses from typing import List -from typing import NamedTuple import mako.template # ===== -class _KeyMapping(NamedTuple): [email protected](frozen=True) +class _KeyMapping: kvmd_code: int arduino_hid_key: str web_key: str diff --git a/kvmd/apps/ipmi/auth.py b/kvmd/apps/ipmi/auth.py index 4b95abf5..d4c922d7 100644 --- a/kvmd/apps/ipmi/auth.py +++ b/kvmd/apps/ipmi/auth.py @@ -20,9 +20,10 @@ # ========================================================================== # +import dataclasses + from typing import List from typing import Dict -from typing import NamedTuple # ===== @@ -31,7 +32,8 @@ class IpmiPasswdError(Exception): super().__init__("Incorrect IPMI passwd file: " + msg) -class IpmiUserCredentials(NamedTuple): [email protected](frozen=True) +class IpmiUserCredentials: ipmi_user: str ipmi_passwd: str kvmd_user: str diff --git a/kvmd/apps/kvmd/hid.py b/kvmd/apps/kvmd/hid.py index 3cdc48fc..dbfd5c58 100644 --- a/kvmd/apps/kvmd/hid.py +++ b/kvmd/apps/kvmd/hid.py @@ -50,19 +50,19 @@ class _BaseEvent: raise NotImplementedError [email protected] # pylint: disable=abstract-method [email protected](frozen=True) # pylint: disable=abstract-method class _BoolEvent(_BaseEvent): name: str state: bool [email protected] # pylint: disable=abstract-method [email protected](frozen=True) # pylint: disable=abstract-method class _IntEvent(_BaseEvent): x: int y: int [email protected](frozen=True) class _KeyEvent(_BoolEvent): def __post_init__(self) -> None: assert self.name in keymap.KEYMAP @@ -75,7 +75,7 @@ class _KeyEvent(_BoolEvent): return b"\x11" + key_bytes + state_bytes + b"\x00\x00" [email protected](frozen=True) class _MouseMoveEvent(_IntEvent): def __post_init__(self) -> None: assert -32768 <= self.x <= 32767 @@ -85,7 +85,7 @@ class _MouseMoveEvent(_IntEvent): return b"\x12" + struct.pack(">hh", self.x, self.y) [email protected](frozen=True) class _MouseButtonEvent(_BoolEvent): def __post_init__(self) -> None: assert self.name in ["left", "right"] @@ -100,7 +100,7 @@ class _MouseButtonEvent(_BoolEvent): return b"\x13" + bytes([code]) + b"\x00\x00\x00" [email protected](frozen=True) class _MouseWheelEvent(_IntEvent): def __post_init__(self) -> None: assert self.x == 0 # Горизонтальная прокрутка пока не поддерживается diff --git a/kvmd/apps/kvmd/msd.py b/kvmd/apps/kvmd/msd.py index 44156b9e..d8b6b69e 100644 --- a/kvmd/apps/kvmd/msd.py +++ b/kvmd/apps/kvmd/msd.py @@ -24,10 +24,10 @@ import os import struct import asyncio import asyncio.queues +import dataclasses import types from typing import Dict -from typing import NamedTuple from typing import Callable from typing import Type from typing import AsyncGenerator @@ -84,19 +84,22 @@ class MsdIsBusyError(MsdOperationError, aioregion.RegionIsBusyError): # ===== -class _HardwareInfo(NamedTuple): [email protected](frozen=True) +class _HardwareInfo: manufacturer: str product: str serial: str -class _ImageInfo(NamedTuple): [email protected](frozen=True) +class _ImageInfo: name: str size: int complete: bool -class _MassStorageDeviceInfo(NamedTuple): [email protected](frozen=True) +class _MassStorageDeviceInfo: path: str real: str size: int @@ -250,13 +253,13 @@ class MassStorageDevice: # pylint: disable=too-many-instance-attributes def get_state(self) -> Dict: online = (self._enabled and bool(self._device_path)) - info = (self.__saved_device_info._asdict() if self.__saved_device_info else None) + info = (dataclasses.asdict(self.__saved_device_info) if self.__saved_device_info else None) connected_to: Optional[str] = None if online: if info: - info["hw"] = (info["hw"]._asdict() if info["hw"] else None) - info["image"] = (info["image"]._asdict() if info["image"] else None) + info["hw"] = (dataclasses.asdict(info["hw"]) if info["hw"] else None) + info["image"] = (dataclasses.asdict(info["image"]) if info["image"] else None) connected_to = ("kvm" if self.__device_info else "server") return { |