mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-12 09:10:30 +08:00
removed pyudev
This commit is contained in:
parent
a6aaa21287
commit
2c9781b8ac
1
PKGBUILD
1
PKGBUILD
@ -25,7 +25,6 @@ depends=(
|
|||||||
python-aiohttp
|
python-aiohttp
|
||||||
python-aiofiles
|
python-aiofiles
|
||||||
python-passlib
|
python-passlib
|
||||||
python-pyudev
|
|
||||||
python-raspberry-gpio
|
python-raspberry-gpio
|
||||||
python-pyserial
|
python-pyserial
|
||||||
python-setproctitle
|
python-setproctitle
|
||||||
|
|||||||
@ -21,6 +21,8 @@
|
|||||||
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import stat
|
||||||
|
import fcntl
|
||||||
import struct
|
import struct
|
||||||
import asyncio
|
import asyncio
|
||||||
import asyncio.queues
|
import asyncio.queues
|
||||||
@ -34,8 +36,6 @@ from typing import AsyncGenerator
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
import pyudev
|
|
||||||
|
|
||||||
import aiofiles
|
import aiofiles
|
||||||
import aiofiles.base
|
import aiofiles.base
|
||||||
|
|
||||||
@ -85,13 +85,6 @@ class MsdIsBusyError(MsdOperationError, aioregion.RegionIsBusyError):
|
|||||||
|
|
||||||
|
|
||||||
# =====
|
# =====
|
||||||
@dataclasses.dataclass(frozen=True)
|
|
||||||
class _HardwareInfo:
|
|
||||||
manufacturer: str
|
|
||||||
product: str
|
|
||||||
serial: str
|
|
||||||
|
|
||||||
|
|
||||||
@dataclasses.dataclass(frozen=True)
|
@dataclasses.dataclass(frozen=True)
|
||||||
class _ImageInfo:
|
class _ImageInfo:
|
||||||
name: str
|
name: str
|
||||||
@ -104,7 +97,6 @@ class _MassStorageDeviceInfo:
|
|||||||
path: str
|
path: str
|
||||||
real: str
|
real: str
|
||||||
size: int
|
size: int
|
||||||
hw: Optional[_HardwareInfo]
|
|
||||||
image: Optional[_ImageInfo]
|
image: Optional[_ImageInfo]
|
||||||
|
|
||||||
|
|
||||||
@ -154,23 +146,14 @@ def _parse_image_info_bytes(data: bytes) -> Optional[_ImageInfo]:
|
|||||||
|
|
||||||
|
|
||||||
def _explore_device(device_path: str) -> _MassStorageDeviceInfo:
|
def _explore_device(device_path: str) -> _MassStorageDeviceInfo:
|
||||||
# udevadm info -a -p $(udevadm info -q path -n /dev/sda)
|
if not stat.S_ISBLK(os.stat(device_path).st_mode):
|
||||||
device = pyudev.Devices.from_device_file(pyudev.Context(), device_path)
|
raise RuntimeError("Not a block device: %s" % (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
|
|
||||||
|
|
||||||
with open(device_path, "rb") as device_file:
|
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)
|
device_file.seek(size - _IMAGE_INFO_SIZE)
|
||||||
image_info = _parse_image_info_bytes(device_file.read())
|
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),
|
real=os.path.realpath(device_path),
|
||||||
size=size,
|
size=size,
|
||||||
image=image_info,
|
image=image_info,
|
||||||
hw=hw_info,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -193,7 +175,6 @@ def _msd_working(method: Callable) -> Callable:
|
|||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
# =====
|
|
||||||
class MassStorageDevice: # pylint: disable=too-many-instance-attributes
|
class MassStorageDevice: # pylint: disable=too-many-instance-attributes
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
|||||||
@ -3,7 +3,6 @@ fake_rpi
|
|||||||
aiohttp
|
aiohttp
|
||||||
aiofiles
|
aiofiles
|
||||||
passlib
|
passlib
|
||||||
pyudev
|
|
||||||
pyyaml
|
pyyaml
|
||||||
pyserial
|
pyserial
|
||||||
setproctitle
|
setproctitle
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user