Ejemplo n.º 1
0
	def _copyMoveCommand(self, workerID, target, command, source, destination):
		from octoprint.server.api.files import _verifyFolderExists, _verifyFileExists
		if not _verifyFileExists(target, source) and not _verifyFolderExists(target, source):
			return

		if _verifyFolderExists(target, destination):
			path, name = self._file_manager.split_path(target, source)
			destination = self._file_manager.join_path(target, destination, name)

		if _verifyFileExists(target, destination) or _verifyFolderExists(target, destination):
			return

		if command == "copy":
			if self._file_manager.file_exists(target, source):
				self._file_manager.copy_file(target, source, destination)
			elif self._file_manager.folder_exists(target, source):
				self._file_manager.copy_folder(target, source, destination)
		elif command == "move":
			from octoprint.server.api.files import _isBusy
			if _isBusy(target, source):
				self._plugin_manager.send_plugin_message(self._identifier,
														dict(type="failed", workerID=workerID, lastfile=source,
															reason="Trying to delete a file that is currently in use"))
				return

			# deselect the file if it's currently selected
			from octoprint.server.api.files import _getCurrentFile
			currentOrigin, currentFilename = _getCurrentFile()
			if currentFilename is not None and source == currentFilename:
				self._printer.unselect_file()

			if self._file_manager.file_exists(target, source):
				self._file_manager.move_file(target, source, destination)
			elif self._file_manager.folder_exists(target, source):
				self._file_manager.move_folder(target, source, destination)
Ejemplo n.º 2
0
	def _copyMoveCommand(self, workerID, target, command, source, destination):
		from octoprint.server.api.files import _verifyFolderExists, _verifyFileExists
		if not _verifyFileExists(target, source) and not _verifyFolderExists(target, source):
			return

		if _verifyFolderExists(target, destination):
			path, name = self._file_manager.split_path(target, source)
			destination = self._file_manager.join_path(target, destination, name)

		if _verifyFileExists(target, destination) or _verifyFolderExists(target, destination):
			return

		if command == "copy":
			if self._file_manager.file_exists(target, source):
				self._file_manager.copy_file(target, source, destination)
			elif self._file_manager.folder_exists(target, source):
				self._file_manager.copy_folder(target, source, destination)
		elif command == "move":
			from octoprint.server.api.files import _isBusy
			if _isBusy(target, source):
				self._plugin_manager.send_plugin_message(self._identifier,
														dict(type="failed", workerID=workerID, lastfile=source,
															reason="Trying to delete a file that is currently in use"))
				return

			# deselect the file if it's currently selected
			from octoprint.server.api.files import _getCurrentFile
			currentOrigin, currentFilename = _getCurrentFile()
			if currentFilename is not None and source == currentFilename:
				self._printer.unselect_file()

			if self._file_manager.file_exists(target, source):
				self._file_manager.move_file(target, source, destination)
			elif self._file_manager.folder_exists(target, source):
				self._file_manager.move_folder(target, source, destination)
Ejemplo n.º 3
0
    def _deleteCommand(self, workerID, target, source):
        from octoprint.server.api.files import _verifyFolderExists, _verifyFileExists, _isBusy

        # prohibit deleting or moving files that are currently in use
        from octoprint.server.api.files import _getCurrentFile
        currentOrigin, currentFilename = _getCurrentFile()

        if _verifyFileExists(target, source):
            if _isBusy(target, source):
                self._plugin_manager.send_plugin_message(
                    self._identifier,
                    dict(type="failed",
                         workerID=workerID,
                         lastfile=source,
                         reason=
                         "Trying to delete a file that is currently in use"))
                return

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

            # delete it
            if target == FileDestinations.SDCARD:
                self._printer.delete_sd_file(source)
            else:
                self._file_manager.remove_file(target, source)
        elif _verifyFolderExists(target, source):
            if not target in [FileDestinations.LOCAL]:
                return make_response("Unknown target: %s" % target, 404)

            folderpath = source
            if _isBusy(target, folderpath):
                self._plugin_manager.send_plugin_message(
                    self._identifier,
                    dict(
                        type="failed",
                        workerID=workerID,
                        lastfile=folderpath,
                        reason=
                        "Trying to delete a folder that contains a file that is currently in use"
                    ))
                return

            # deselect the file if it's currently selected
            if currentFilename is not None and self._file_manager.file_in_path(
                    target, folderpath, currentFilename):
                self._printer.unselect_file()

            # delete it
            self._file_manager.remove_folder(target, folderpath)
Ejemplo n.º 4
0
	def _deleteCommand(self, workerID, target, source):
		from octoprint.server.api.files import _verifyFolderExists, _verifyFileExists, _isBusy

		# prohibit deleting or moving files that are currently in use
		from octoprint.server.api.files import _getCurrentFile
		currentOrigin, currentFilename = _getCurrentFile()

		if _verifyFileExists(target, source):
			if _isBusy(target, source):
				self._plugin_manager.send_plugin_message(self._identifier,
														dict(type="failed", workerID=workerID, lastfile=source,
															reason="Trying to delete a file that is currently in use"))
				return

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

			# delete it
			if target == FileDestinations.SDCARD:
				self._printer.delete_sd_file(source)
			else:
				self._file_manager.remove_file(target, source)
		elif _verifyFolderExists(target, source):
			if not target in [FileDestinations.LOCAL]:
				return make_response("Unknown target: %s" % target, 404)

			folderpath = source
			if _isBusy(target, folderpath):
				self._plugin_manager.send_plugin_message(self._identifier,
														dict(type="failed", workerID=workerID, lastfile=folderpath,
															reason="Trying to delete a folder that contains a file that is currently in use"))
				return

			# deselect the file if it's currently selected
			if currentFilename is not None and self._file_manager.file_in_path(target, folderpath, currentFilename):
				self._printer.unselect_file()

			# delete it
			self._file_manager.remove_folder(target, folderpath)