def _isBusy(target, path): currentOrigin, currentPath = _getCurrentFile() if currentPath is not None and currentOrigin == target and fileManager.file_in_path( FileDestinations.LOCAL, path, currentPath) and (printer.is_printing() or printer.is_paused()): return True return any(target == x[0] and fileManager.file_in_path(FileDestinations.LOCAL, path, x[1]) for x in fileManager.get_busy_files())
def deleteGcodeFile(filename, target): if not _verifyFileExists(target, filename) and not _verifyFolderExists( target, filename): return make_response( "File/Folder not found on '%s': %s" % (target, filename), 404) if _verifyFileExists(target, filename): if not target in [FileDestinations.LOCAL, FileDestinations.SDCARD]: return make_response("Unknown target: %s" % target, 400) if _isBusy(target, filename): return make_response( "Trying to delete a file that is currently in use: %s" % filename, 409) # deselect the file if it's currently selected currentOrigin, currentPath = _getCurrentFile() if currentPath is not None and currentOrigin == target and filename == currentPath: printer.unselect_file() # delete it if target == FileDestinations.SDCARD: printer.delete_sd_file(filename, tags={"source:api", "api:files.sd"}) else: fileManager.remove_file(target, filename) try: fileManager.remove_file(target, filename.replace(".gcode", ".png")) except: pass elif _verifyFolderExists(target, filename): if not target in [FileDestinations.LOCAL]: return make_response("Unknown target: %s" % target, 400) if _isBusy(target, filename): return make_response( "Trying to delete a folder that contains a file that is currently in use: %s" % filename, 409) # deselect the file if it's currently selected currentOrigin, currentPath = _getCurrentFile() if currentPath is not None and currentOrigin == target and fileManager.file_in_path( target, filename, currentPath): printer.unselect_file() # delete it fileManager.remove_folder(target, filename, recursive=True) return NO_CONTENT
def deleteGcodeFile(filename, target): if not _validate(target, filename): abort(404) if not _verifyFileExists(target, filename) and not _verifyFolderExists( target, filename): abort(404) if target not in [FileDestinations.LOCAL, FileDestinations.SDCARD]: abort(404) if _verifyFileExists(target, filename): if _isBusy(target, filename): abort( 409, description="Trying to delete a file that is currently in use") # deselect the file if it's currently selected currentOrigin, currentPath = _getCurrentFile() if (currentPath is not None and currentOrigin == target and filename == currentPath): printer.unselect_file() # delete it if target == FileDestinations.SDCARD: printer.delete_sd_file(filename, tags={"source:api", "api:files.sd"}) else: fileManager.remove_file(target, filename) elif _verifyFolderExists(target, filename): if _isBusy(target, filename): abort( 409, description= "Trying to delete a folder that contains a file that is currently in use", ) # deselect the file if it's currently selected currentOrigin, currentPath = _getCurrentFile() if (currentPath is not None and currentOrigin == target and fileManager.file_in_path(target, filename, currentPath)): printer.unselect_file() # delete it fileManager.remove_folder(target, filename, recursive=True) return NO_CONTENT
def deleteGcodeFile(filename, target): if not _verifyFileExists(target, filename) and not _verifyFolderExists(target, filename): return make_response("File/Folder not found on '%s': %s" % (target, filename), 404) if _verifyFileExists(target, filename): if not target in [FileDestinations.LOCAL, FileDestinations.SDCARD]: return make_response("Unknown target: %s" % target, 400) if _isBusy(target, filename): return make_response("Trying to delete a file that is currently in use: %s" % filename, 409) # deselect the file if it's currently selected currentOrigin, currentPath = _getCurrentFile() if currentPath is not None and currentOrigin == target and filename == currentPath: printer.unselect_file() # delete it if target == FileDestinations.SDCARD: printer.delete_sd_file(filename) else: fileManager.remove_file(target, filename) elif _verifyFolderExists(target, filename): if not target in [FileDestinations.LOCAL]: return make_response("Unknown target: %s" % target, 400) if _isBusy(target, filename): return make_response("Trying to delete a folder that contains a file that is currently in use: %s" % filename, 409) # deselect the file if it's currently selected currentOrigin, currentPath = _getCurrentFile() if currentPath is not None and currentOrigin == target and fileManager.file_in_path(target, filename, currentPath): printer.unselect_file() # delete it fileManager.remove_folder(target, filename, recursive=True) return NO_CONTENT
def _isBusy(target, path): currentOrigin, currentPath = _getCurrentFile() if currentPath is not None and currentOrigin == target and fileManager.file_in_path(FileDestinations.LOCAL, path, currentPath) and (printer.is_printing() or printer.is_paused()): return True return any(target == x[0] and fileManager.file_in_path(FileDestinations.LOCAL, path, x[1]) for x in fileManager.get_busy_files())