separate busy and uploading flag

This commit is contained in:
Devaev Maxim 2019-06-11 03:37:55 +03:00
parent 8d83a8b898
commit bf34f7b3fa
2 changed files with 35 additions and 32 deletions

View File

@ -254,10 +254,11 @@ class MassStorageDevice: # pylint: disable=too-many-instance-attributes
return {
"enabled": self._enabled,
"online": online,
"connected_to": (("kvm" if self.__on_kvm else "server") if online else None),
"busy": self.__region.is_busy(),
"uploading": bool(self.__device_file),
"written": self.__written,
"info": (dataclasses.asdict(self._device_info) if online else None),
"connected_to": (("kvm" if self.__on_kvm else "server") if online else None),
}
async def poll_state(self) -> AsyncGenerator[Dict, None]:
@ -289,12 +290,9 @@ class MassStorageDevice: # pylint: disable=too-many-instance-attributes
gpio.write(self.__target_pin, True)
raise
self.__on_kvm = True
state = self.get_state()
await self.__state_queue.put(state)
get_logger().info("Mass-storage device switched to KVM: %s", self._device_info)
return state
return (await self.__queue_current_state())
@_msd_working
@aiotools.atomic
@ -305,33 +303,33 @@ class MassStorageDevice: # pylint: disable=too-many-instance-attributes
gpio.write(self.__target_pin, True)
self.__on_kvm = False
state = self.get_state()
await self.__state_queue.put(state)
get_logger().info("Mass-storage device switched to Server")
return state
return (await self.__queue_current_state())
@aiotools.tasked
@aiotools.atomic
async def reset(self) -> None:
with self.__region:
if not self._enabled:
raise MsdDisabledError()
notify = False
try:
with self.__region:
if not self._enabled:
raise MsdDisabledError()
get_logger(0).info("Mass-storage device reset")
notify = True
get_logger(0).info("Mass-storage device reset")
gpio.write(self.__reset_pin, True)
await asyncio.sleep(self.__reset_delay)
gpio.write(self.__target_pin, False)
self.__on_kvm = True
await asyncio.sleep(self.__reset_delay)
gpio.write(self.__reset_pin, False)
gpio.write(self.__reset_pin, True)
await asyncio.sleep(self.__reset_delay)
gpio.write(self.__target_pin, False)
self.__on_kvm = True
await asyncio.sleep(self.__reset_delay)
gpio.write(self.__reset_pin, False)
try:
await self.__load_device_info()
finally:
await self.__state_queue.put(self.get_state())
finally:
if notify:
await self.__queue_current_state()
@_msd_working
@aiotools.atomic
@ -348,7 +346,7 @@ class MassStorageDevice: # pylint: disable=too-many-instance-attributes
self.__region.exit()
raise
finally:
await self.__state_queue.put(self.get_state())
await self.__queue_current_state()
@aiotools.atomic
async def write_image_info(self, name: str, complete: bool) -> None:
@ -379,8 +377,13 @@ class MassStorageDevice: # pylint: disable=too-many-instance-attributes
await self.__close_device_file()
await self.__load_device_info()
finally:
await self.__state_queue.put(self.get_state())
self.__region.exit()
await self.__queue_current_state()
async def __queue_current_state(self) -> Dict:
state = self.get_state()
await self.__state_queue.put(state)
return state
async def __write_to_device_file(self, data: bytes) -> None:
assert self.__device_file

View File

@ -128,7 +128,7 @@ function Msd() {
$("msd-another-another-user-uploads").style.display = "none";
$("msd-led").className = "led-green";
$("msd-status").innerHTML = $("msd-led").title = "Connected to Server";
} else if (__state.busy) {
} else if (__state.uploading) {
if (!__upload_http) {
$("msd-another-another-user-uploads").style.display = "block";
}
@ -147,17 +147,17 @@ function Msd() {
$("msd-offline").style.display = (__state.online ? "none" : "block");
$("msd-current-image-broken").style.display = (
__state.online && __state.info.image &&
!__state.info.image.complete && !__state.busy ? "block" : "none"
!__state.info.image.complete && !__state.uploading ? "block" : "none"
);
$("msd-current-image-name").innerHTML = (__state.online && __state.info.image ? __state.info.image.name : "None");
$("msd-current-image-size").innerHTML = (__state.online && __state.info.image ? __formatSize(__state.info.image.size) : "None");
$("msd-storage-size").innerHTML = (__state.online ? __formatSize(__state.info.size) : "Unavailable");
wm.switchDisabled($("msd-switch-to-kvm-button"), (!__state.online || __state.connected_to === "kvm" || __state.busy));
wm.switchDisabled($("msd-switch-to-server-button"), (!__state.online || __state.connected_to === "server" || __state.busy));
wm.switchDisabled($("msd-select-new-image-button"), (!__state.online || __state.connected_to !== "kvm" || __state.busy || __upload_http));
wm.switchDisabled($("msd-upload-new-image-button"), (!__state.online || __state.connected_to !== "kvm" || __state.busy || !__image_file));
wm.switchDisabled($("msd-switch-to-kvm-button"), (!__state.online || __state.connected_to === "kvm" || __state.uploading));
wm.switchDisabled($("msd-switch-to-server-button"), (!__state.online || __state.connected_to === "server" || __state.uploading));
wm.switchDisabled($("msd-select-new-image-button"), (!__state.online || __state.connected_to !== "kvm" || __state.uploading || __upload_http));
wm.switchDisabled($("msd-upload-new-image-button"), (!__state.online || __state.connected_to !== "kvm" || __state.uploading || !__image_file));
wm.switchDisabled($("msd-abort-uploading-button"), (!__state.online || !__upload_http));
wm.switchDisabled($("msd-reset-button"), (!__state.enabled || __state.busy));