file_manager: use print_stats to determine if an operation is safe
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
d19737f4c5
commit
9c76875896
|
@ -143,21 +143,23 @@ class FileManager:
|
||||||
async def _handle_operation_check(self, requested_path):
|
async def _handle_operation_check(self, requested_path):
|
||||||
# Get virtual_sdcard status
|
# Get virtual_sdcard status
|
||||||
request = self.server.make_request(
|
request = self.server.make_request(
|
||||||
"objects/status", 'GET', {'virtual_sdcard': []})
|
"objects/status", 'GET', {'print_stats': []})
|
||||||
result = await request.wait()
|
result = await request.wait()
|
||||||
if isinstance(result, self.server.error):
|
if isinstance(result, self.server.error):
|
||||||
raise result
|
raise result
|
||||||
vsd = result.get('virtual_sdcard', {})
|
pstats = result.get('print_stats', {})
|
||||||
loaded_file = vsd.get('filename', "")
|
loaded_file = pstats.get('filename', "")
|
||||||
|
state = pstats.get('state', "")
|
||||||
gc_path = self.file_paths.get('gcodes', "")
|
gc_path = self.file_paths.get('gcodes', "")
|
||||||
full_path = os.path.join(gc_path, loaded_file)
|
full_path = os.path.join(gc_path, loaded_file)
|
||||||
if os.path.isdir(requested_path):
|
if loaded_file and state != "complete":
|
||||||
# Check to see of the loaded file is in the reques
|
if os.path.isdir(requested_path):
|
||||||
if full_path.startswith(requested_path):
|
# Check to see of the loaded file is in the request
|
||||||
|
if full_path.startswith(requested_path):
|
||||||
|
raise self.server.error("File currently in use", 403)
|
||||||
|
elif full_path == requested_path:
|
||||||
raise self.server.error("File currently in use", 403)
|
raise self.server.error("File currently in use", 403)
|
||||||
elif full_path == requested_path:
|
ongoing = state in ["printing", "paused"]
|
||||||
raise self.server.error("File currently in use", 403)
|
|
||||||
ongoing = vsd.get('total_duration', 0.) > 0.
|
|
||||||
return ongoing
|
return ongoing
|
||||||
|
|
||||||
def _convert_path(self, url_path):
|
def _convert_path(self, url_path):
|
||||||
|
|
Loading…
Reference in New Issue