Example #1
0
def deleteGcodeFile(filename, target):
	if not target in [FileDestinations.LOCAL, FileDestinations.SDCARD]:
		return make_response("Unknown target: %s" % target, 404)

	if not _verifyFileExists(target, filename):
		return make_response("File not found on '%s': %s" % (target, filename), 404)

	# prohibit deleting files that are currently in use
	currentOrigin, currentFilename = _getCurrentFile()
	if currentFilename == filename and currentOrigin == target and (printer.is_printing() or printer.is_paused()):
		make_response("Trying to delete file that is currently being printed: %s" % filename, 409)

	if (target, filename) in fileManager.get_busy_files():
		make_response("Trying to delete a file that is currently in use: %s" % filename, 409)

	# deselect the file if it's currently selected
	if currentFilename is not None and filename == currentFilename:
		printer.unselect_file()

	# delete it
	if target == FileDestinations.SDCARD:
		printer.delete_sd_file(filename)
	else:
		fileManager.remove_file(target, filename)

	return NO_CONTENT
Example #2
0
def deleteGcodeFile(filename, target):
    if not target in [FileDestinations.LOCAL, FileDestinations.SDCARD]:
        return make_response("Unknown target: %s" % target, 404)

    if not _verifyFileExists(target, filename):
        return make_response("File not found on '%s': %s" % (target, filename),
                             404)

    # prohibit deleting files that are currently in use
    currentOrigin, currentFilename = _getCurrentFile()
    if currentFilename == filename and currentOrigin == target and (
            printer.is_printing() or printer.is_paused()):
        make_response(
            "Trying to delete file that is currently being printed: %s" %
            filename, 409)

    if (target, filename) in fileManager.get_busy_files():
        make_response(
            "Trying to delete a file that is currently in use: %s" % filename,
            409)

    # deselect the file if it's currently selected
    if currentFilename is not None and filename == currentFilename:
        printer.unselect_file()

    # delete it
    if target == FileDestinations.SDCARD:
        printer.delete_sd_file(filename)
    else:
        fileManager.remove_file(target, filename)

    return NO_CONTENT
Example #3
0
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
Example #4
0
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
Example #5
0
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