Properly detect current file, forgot to adjust detection stuff in upload API after renaming things in the job tracking.
Thanks to Bryan Mayland for spotting this. Closes #476
This commit is contained in:
parent
faa0521428
commit
9c9b98dde4
2 changed files with 24 additions and 17 deletions
|
|
@ -106,11 +106,13 @@ def uploadGcodeFile(target):
|
|||
|
||||
# determine current job
|
||||
currentFilename = None
|
||||
currentSd = None
|
||||
currentOrigin = None
|
||||
currentJob = printer.getCurrentJob()
|
||||
if currentJob is not None and "filename" in currentJob.keys() and "sd" in currentJob.keys():
|
||||
currentFilename = currentJob["filename"]
|
||||
currentSd = currentJob["sd"]
|
||||
if currentJob is not None and "file" in currentJob.keys():
|
||||
currentJobFile = currentJob["file"]
|
||||
if "name" in currentJobFile.keys() and "origin" in currentJobFile.keys():
|
||||
currentFilename = currentJobFile["name"]
|
||||
currentOrigin = currentJobFile["origin"]
|
||||
|
||||
# determine future filename of file to be uploaded, abort if it can't be uploaded
|
||||
futureFilename = gcodeManager.getFutureFilename(file)
|
||||
|
|
@ -118,7 +120,7 @@ def uploadGcodeFile(target):
|
|||
return make_response("Can not upload file %s, wrong format?" % file.filename, 415)
|
||||
|
||||
# prohibit overwriting currently selected file while it's being printed
|
||||
if futureFilename == currentFilename and sd == currentSd and printer.isPrinting() or printer.isPaused():
|
||||
if futureFilename == currentFilename and target == currentOrigin and printer.isPrinting() or printer.isPaused():
|
||||
return make_response("Trying to overwrite file that is currently being printed: %s" % currentFilename, 409)
|
||||
|
||||
filename = None
|
||||
|
|
@ -145,12 +147,10 @@ def uploadGcodeFile(target):
|
|||
Selects the just uploaded file if either selectAfterUpload or printAfterSelect are True, or if the
|
||||
exact file is already selected, such reloading it.
|
||||
"""
|
||||
sd = destination == FileDestinations.SDCARD
|
||||
if selectAfterUpload or printAfterSelect or (currentFilename == filename and currentSd == sd):
|
||||
printer.selectFile(nameToSelect, sd, printAfterSelect)
|
||||
if selectAfterUpload or printAfterSelect or (currentFilename == filename and currentOrigin == destination):
|
||||
printer.selectFile(nameToSelect, destination == FileDestinations.SDCARD, printAfterSelect)
|
||||
|
||||
destination = FileDestinations.SDCARD if sd else FileDestinations.LOCAL
|
||||
filename, done = gcodeManager.addFile(file, destination, fileProcessingFinished)
|
||||
filename, done = gcodeManager.addFile(file, target, fileProcessingFinished)
|
||||
if filename is None:
|
||||
return make_response("Could not upload the file %s" % file.filename, 500)
|
||||
|
||||
|
|
|
|||
|
|
@ -518,6 +518,9 @@ class GcodeWatchdogHandler(PatternMatchingEventHandler):
|
|||
|
||||
def __init__(self, gcodeManager, printer):
|
||||
PatternMatchingEventHandler.__init__(self)
|
||||
|
||||
self._logger = logging.getLogger(__name__)
|
||||
|
||||
self._gcodeManager = gcodeManager
|
||||
self._printer = printer
|
||||
|
||||
|
|
@ -535,20 +538,24 @@ class GcodeWatchdogHandler(PatternMatchingEventHandler):
|
|||
|
||||
# determine current job
|
||||
currentFilename = None
|
||||
currentSd = None
|
||||
currentOrigin = None
|
||||
currentJob = self._printer.getCurrentJob()
|
||||
if currentJob is not None and "filename" in currentJob.keys() and "sd" in currentJob.keys():
|
||||
currentFilename = currentJob["filename"]
|
||||
currentSd = currentJob["sd"]
|
||||
if currentJob is not None and "file" in currentJob.keys():
|
||||
currentJobFile = currentJob["file"]
|
||||
if "name" in currentJobFile.keys() and "origin" in currentJobFile.keys():
|
||||
currentFilename = currentJobFile["name"]
|
||||
currentOrigin = currentJobFile["origin"]
|
||||
|
||||
# determine future filename of file to be uploaded, abort if it can't be uploaded
|
||||
futureFilename = self._gcodeManager.getFutureFilename(fileWrapper)
|
||||
if futureFilename is None or (not settings().getBoolean(["cura", "enabled"]) and not gcodefiles.isGcodeFileName(futureFilename)):
|
||||
return # Invalid file
|
||||
self._logger.warn("Could not add %s: Invalid file" % fileWrapper.filename)
|
||||
return
|
||||
|
||||
# prohibit overwriting currently selected file while it's being printed
|
||||
if futureFilename == currentFilename and not currentSd and self._printer.isPrinting() or self._printer.isPaused():
|
||||
return # Trying to overwrite file that is currently being printed
|
||||
if futureFilename == currentFilename and not currentOrigin == FileDestinations.SDCARD and self._printer.isPrinting() or self._printer.isPaused():
|
||||
self._logger.warn("Could not add %s: Trying to overwrite file that is currently being printed" % fileWrapper.filename)
|
||||
return
|
||||
|
||||
self._gcodeManager.addFile(fileWrapper, FileDestinations.LOCAL)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue