Exemple #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
Exemple #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
Exemple #3
0
		def slicing_done(target, gcode_name, select_after_slicing, print_after_slicing, model_to_remove_after_slicing = None):
			if select_after_slicing or print_after_slicing:
				sd = False
				if target == FileDestinations.SDCARD:
					filenameToSelect = gcode_name
					sd = True
				else:
					filenameToSelect = fileManager.path_on_disk(target, gcode_name)
				printer.select_file(filenameToSelect, sd, print_after_slicing)

			# Custom option to remove auto-generated STL from workbench after slicing
			if model_to_remove_after_slicing is not None:
				fileManager.remove_file(target, model_to_remove_after_slicing)
Exemple #4
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
Exemple #5
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
Exemple #6
0
        def slicing_done(target,
                         gcode_name,
                         select_after_slicing,
                         print_after_slicing,
                         model_to_remove_after_slicing=None):
            if select_after_slicing or print_after_slicing:
                sd = False
                if target == FileDestinations.SDCARD:
                    filenameToSelect = gcode_name
                    sd = True
                else:
                    filenameToSelect = fileManager.path_on_disk(
                        target, gcode_name)
                printer.select_file(filenameToSelect, sd, print_after_slicing)

            # Custom option to remove auto-generated STL from workbench after slicing
            if model_to_remove_after_slicing is not None:
                fileManager.remove_file(target, model_to_remove_after_slicing)
Exemple #7
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