refactoring

This commit is contained in:
Devaev Maxim 2019-06-11 11:07:56 +03:00
parent 8306b0e9a6
commit 675abed41a
2 changed files with 8 additions and 8 deletions

View File

@ -65,17 +65,17 @@ class MsdOfflineError(MsdOperationError):
super().__init__("Mass-storage device is not found")
class MsdAlreadyConnectedToServerError(MsdOperationError):
class MsdAlreadyOnServerError(MsdOperationError):
def __init__(self) -> None:
super().__init__("Mass-storage is already connected to Server")
class MsdAlreadyConnectedToKvmError(MsdOperationError):
class MsdAlreadyOnKvmError(MsdOperationError):
def __init__(self) -> None:
super().__init__("Mass-storage is already connected to KVM")
class MsdNotConnectedToKvmError(MsdOperationError):
class MsdNotOnKvmError(MsdOperationError):
def __init__(self) -> None:
super().__init__("Mass-storage is not connected to KVM")
@ -283,7 +283,7 @@ class MassStorageDevice: # pylint: disable=too-many-instance-attributes
try:
with self.__region:
if self.__on_kvm:
raise MsdAlreadyConnectedToKvmError()
raise MsdAlreadyOnKvmError()
notify = True
gpio.write(self.__target_pin, False)
@ -304,13 +304,13 @@ class MassStorageDevice: # pylint: disable=too-many-instance-attributes
@_msd_working
@aiotools.atomic
async def connect_to_pc(self) -> Dict:
async def connect_to_server(self) -> Dict:
notify = False
state: Dict = {}
try:
with self.__region:
if not self.__on_kvm:
raise MsdAlreadyConnectedToServerError()
raise MsdAlreadyOnServerError()
notify = True
gpio.write(self.__target_pin, True)
@ -353,7 +353,7 @@ class MassStorageDevice: # pylint: disable=too-many-instance-attributes
self.__region.enter()
try:
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.__written = 0
return self

View File

@ -465,7 +465,7 @@ class Server: # pylint: disable=too-many-instance-attributes
to = valid_kvm_target(request.query.get("to"))
return _json(await ({
"kvm": self.__msd.connect_to_kvm,
"server": self.__msd.connect_to_pc,
"server": self.__msd.connect_to_server,
}[to])())
@_exposed("POST", "/msd/write")