From 9c9b98dde4d5bae6b3ef4d3b2cca1f134826c578 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Sun, 25 May 2014 20:18:41 +0200 Subject: [PATCH] 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 --- src/octoprint/server/api/files.py | 20 ++++++++++---------- src/octoprint/server/util.py | 21 ++++++++++++++------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/octoprint/server/api/files.py b/src/octoprint/server/api/files.py index a46123a7..b615c173 100644 --- a/src/octoprint/server/api/files.py +++ b/src/octoprint/server/api/files.py @@ -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) diff --git a/src/octoprint/server/util.py b/src/octoprint/server/util.py index 9c198163..eff51a62 100644 --- a/src/octoprint/server/util.py +++ b/src/octoprint/server/util.py @@ -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)