MCPcopy Create free account
hub / github.com/AstroPrint/AstroBox / deletePrintFile

Method deletePrintFile

src/astroprint/plugin/services/files.py:219–268  ·  view source on GitHub ↗
(self, data, sendResponse)

Source from the content-addressed store, hash-verified

217 sendResponse('invalid_filename', True)
218
219 def deletePrintFile(self, data, sendResponse):
220
221 fileDestination = fileName = None
222
223 if 'location' in data:
224 fileDestination = data['location']
225
226 if 'fileName' in data:
227 fileName = data['fileName']
228
229 if not fileDestination in [FileDestinations.LOCAL, FileDestinations.SDCARD]:
230 self._logger.error("Unknown file location")
231 sendResponse('unknown_file_location',True)
232 return
233
234 if not fileName or not self._verifyFileExists(fileDestination, fileName):
235 self._logger.error("File not found")
236 sendResponse('file_not_found',True)
237 return
238
239 sd = fileDestination == FileDestinations.SDCARD
240
241 printer = printerManager()
242
243 currentJob = printer.getCurrentJob()
244 currentFilename = None
245 currentSd = None
246 if currentJob is not None and "fileName" in currentJob.keys() and "sd" in currentJob.keys():
247 currentFilename = currentJob["fileName"]
248 currentSd = currentJob["sd"]
249
250 # prohibit deleting the file that is currently being printed
251 if currentFilename == fileName and currentSd == sd and (printer.isPrinting() or printer.isPaused()):
252 sendResponse("Trying to delete file that is currently being printed: %s" % fileName,true)
253
254 # deselect the file if it's currently selected
255 if currentFilename is not None and fileName == currentFilename:
256 printer.unselectFile()
257
258 # delete it
259 if sd:
260 printer.deleteSdFile(fileName)
261 else:
262 printer.fileManager.removeFile(fileName)
263
264 eventManager().fire(Events.FILE_DELETED, {"filename": fileName})
265
266 self.publishEvent('file_deleted','deleted')
267
268 sendResponse({'success':'no error'})
269
270
271 def downloadPrintFile(self,printFileId,sendResponse):

Callers

nothing calls this directly

Calls 12

_verifyFileExistsMethod · 0.95
printerManagerFunction · 0.90
eventManagerFunction · 0.90
getCurrentJobMethod · 0.80
removeFileMethod · 0.80
fireMethod · 0.80
publishEventMethod · 0.80
errorMethod · 0.45
isPrintingMethod · 0.45
isPausedMethod · 0.45
unselectFileMethod · 0.45
deleteSdFileMethod · 0.45

Tested by

no test coverage detected