diff options
author | Devaev Maxim <[email protected]> | 2019-06-12 07:55:44 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2019-06-12 07:55:44 +0300 |
commit | 2c9781b8ac34955dba3a015338ec2d1b5e0884d7 (patch) | |
tree | 2f903029922edf61cd2f398ea35f0f6a4ed87b93 | |
parent | a6aaa212872590d425945d8b3bf11ba4cbfc1fde (diff) |
removed pyudev
-rw-r--r-- | PKGBUILD | 1 | ||||
-rw-r--r-- | kvmd/apps/kvmd/msd.py | 35 | ||||
-rw-r--r-- | testenv/requirements.txt | 1 |
3 files changed, 8 insertions, 29 deletions
@@ -25,7 +25,6 @@ depends=( python-aiohttp python-aiofiles python-passlib - python-pyudev python-raspberry-gpio python-pyserial python-setproctitle diff --git a/kvmd/apps/kvmd/msd.py b/kvmd/apps/kvmd/msd.py index 70b871ee..166a9cac 100644 --- a/kvmd/apps/kvmd/msd.py +++ b/kvmd/apps/kvmd/msd.py @@ -21,6 +21,8 @@ import os +import stat +import fcntl import struct import asyncio import asyncio.queues @@ -34,8 +36,6 @@ from typing import AsyncGenerator from typing import Optional from typing import Any -import pyudev - import aiofiles import aiofiles.base @@ -86,13 +86,6 @@ class MsdIsBusyError(MsdOperationError, aioregion.RegionIsBusyError): # ===== @dataclasses.dataclass(frozen=True) -class _HardwareInfo: - manufacturer: str - product: str - serial: str - - [email protected](frozen=True) class _ImageInfo: name: str size: int @@ -104,7 +97,6 @@ class _MassStorageDeviceInfo: path: str real: str size: int - hw: Optional[_HardwareInfo] image: Optional[_ImageInfo] @@ -154,23 +146,14 @@ def _parse_image_info_bytes(data: bytes) -> Optional[_ImageInfo]: def _explore_device(device_path: str) -> _MassStorageDeviceInfo: - # udevadm info -a -p $(udevadm info -q path -n /dev/sda) - device = pyudev.Devices.from_device_file(pyudev.Context(), device_path) - - if device.subsystem != "block": - raise RuntimeError("Not a block device") - - hw_info: Optional[_HardwareInfo] = None - usb_device = device.find_parent("usb", "usb_device") - if usb_device: - hw_info = _HardwareInfo(**{ - attr: usb_device.attributes.asstring(attr).strip() - for attr in ["manufacturer", "product", "serial"] - }) - - size = device.attributes.asint("size") * 512 + if not stat.S_ISBLK(os.stat(device_path).st_mode): + raise RuntimeError("Not a block device: %s" % (device_path)) with open(device_path, "rb") as device_file: + buf = b"\0" * 8 + buf = fcntl.ioctl(device_file.fileno(), 0x80081272, buf) # BLKGETSIZE64 + size = struct.unpack("L", buf)[0] + assert size > 0, (size, buf) device_file.seek(size - _IMAGE_INFO_SIZE) image_info = _parse_image_info_bytes(device_file.read()) @@ -179,7 +162,6 @@ def _explore_device(device_path: str) -> _MassStorageDeviceInfo: real=os.path.realpath(device_path), size=size, image=image_info, - hw=hw_info, ) @@ -193,7 +175,6 @@ def _msd_working(method: Callable) -> Callable: return wrapper -# ===== class MassStorageDevice: # pylint: disable=too-many-instance-attributes def __init__( self, diff --git a/testenv/requirements.txt b/testenv/requirements.txt index fbbfdbc8..5ba03e57 100644 --- a/testenv/requirements.txt +++ b/testenv/requirements.txt @@ -3,7 +3,6 @@ fake_rpi aiohttp aiofiles passlib -pyudev pyyaml pyserial setproctitle |