mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-12 17:20:30 +08:00
refactoring
This commit is contained in:
parent
8306b0e9a6
commit
675abed41a
@ -65,17 +65,17 @@ class MsdOfflineError(MsdOperationError):
|
|||||||
super().__init__("Mass-storage device is not found")
|
super().__init__("Mass-storage device is not found")
|
||||||
|
|
||||||
|
|
||||||
class MsdAlreadyConnectedToServerError(MsdOperationError):
|
class MsdAlreadyOnServerError(MsdOperationError):
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
super().__init__("Mass-storage is already connected to Server")
|
super().__init__("Mass-storage is already connected to Server")
|
||||||
|
|
||||||
|
|
||||||
class MsdAlreadyConnectedToKvmError(MsdOperationError):
|
class MsdAlreadyOnKvmError(MsdOperationError):
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
super().__init__("Mass-storage is already connected to KVM")
|
super().__init__("Mass-storage is already connected to KVM")
|
||||||
|
|
||||||
|
|
||||||
class MsdNotConnectedToKvmError(MsdOperationError):
|
class MsdNotOnKvmError(MsdOperationError):
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
super().__init__("Mass-storage is not connected to KVM")
|
super().__init__("Mass-storage is not connected to KVM")
|
||||||
|
|
||||||
@ -283,7 +283,7 @@ class MassStorageDevice: # pylint: disable=too-many-instance-attributes
|
|||||||
try:
|
try:
|
||||||
with self.__region:
|
with self.__region:
|
||||||
if self.__on_kvm:
|
if self.__on_kvm:
|
||||||
raise MsdAlreadyConnectedToKvmError()
|
raise MsdAlreadyOnKvmError()
|
||||||
notify = True
|
notify = True
|
||||||
|
|
||||||
gpio.write(self.__target_pin, False)
|
gpio.write(self.__target_pin, False)
|
||||||
@ -304,13 +304,13 @@ class MassStorageDevice: # pylint: disable=too-many-instance-attributes
|
|||||||
|
|
||||||
@_msd_working
|
@_msd_working
|
||||||
@aiotools.atomic
|
@aiotools.atomic
|
||||||
async def connect_to_pc(self) -> Dict:
|
async def connect_to_server(self) -> Dict:
|
||||||
notify = False
|
notify = False
|
||||||
state: Dict = {}
|
state: Dict = {}
|
||||||
try:
|
try:
|
||||||
with self.__region:
|
with self.__region:
|
||||||
if not self.__on_kvm:
|
if not self.__on_kvm:
|
||||||
raise MsdAlreadyConnectedToServerError()
|
raise MsdAlreadyOnServerError()
|
||||||
notify = True
|
notify = True
|
||||||
|
|
||||||
gpio.write(self.__target_pin, True)
|
gpio.write(self.__target_pin, True)
|
||||||
@ -353,7 +353,7 @@ class MassStorageDevice: # pylint: disable=too-many-instance-attributes
|
|||||||
self.__region.enter()
|
self.__region.enter()
|
||||||
try:
|
try:
|
||||||
if not self.__on_kvm:
|
if not self.__on_kvm:
|
||||||
raise MsdNotConnectedToKvmError()
|
raise MsdNotOnKvmError()
|
||||||
self.__device_file = await aiofiles.open(self._device_info.path, mode="w+b", buffering=0)
|
self.__device_file = await aiofiles.open(self._device_info.path, mode="w+b", buffering=0)
|
||||||
self.__written = 0
|
self.__written = 0
|
||||||
return self
|
return self
|
||||||
|
|||||||
@ -465,7 +465,7 @@ class Server: # pylint: disable=too-many-instance-attributes
|
|||||||
to = valid_kvm_target(request.query.get("to"))
|
to = valid_kvm_target(request.query.get("to"))
|
||||||
return _json(await ({
|
return _json(await ({
|
||||||
"kvm": self.__msd.connect_to_kvm,
|
"kvm": self.__msd.connect_to_kvm,
|
||||||
"server": self.__msd.connect_to_pc,
|
"server": self.__msd.connect_to_server,
|
||||||
}[to])())
|
}[to])())
|
||||||
|
|
||||||
@_exposed("POST", "/msd/write")
|
@_exposed("POST", "/msd/write")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user