diff --git a/octoprint/cura/__init__.py b/octoprint/cura/__init__.py index 82c43758..256ffa50 100644 --- a/octoprint/cura/__init__.py +++ b/octoprint/cura/__init__.py @@ -52,7 +52,7 @@ class CuraEngine(object): logging.info("Subprocess args: %s" % str(call_args)) process = subprocess.call(call_args) call_back(*call_back_args) - logging.info("Slicing call back complete") + logging.info("Slicing call back complete:%s" % str(call_back)) args = [self.cura_path, '-s', config, '-o', gcode, file_path] logging.info('CuraEngine args:%s' % str(args)) diff --git a/octoprint/filemanager/destinations.py b/octoprint/filemanager/destinations.py new file mode 100644 index 00000000..b4af5183 --- /dev/null +++ b/octoprint/filemanager/destinations.py @@ -0,0 +1,4 @@ +class FileDestinations(object): + + SDCARD = "sdcard" + LOCAL = "local" diff --git a/octoprint/gcodefiles.py b/octoprint/gcodefiles.py index 158039fc..a1847737 100644 --- a/octoprint/gcodefiles.py +++ b/octoprint/gcodefiles.py @@ -117,14 +117,19 @@ class GcodeManager: #~~ file handling - def addFile(self, file): + def addFile(self, file, destination): from octoprint.util import isSTLFileName from octoprint.util import isGcodeFileName + from octoprint.filemanager.destinations import FileDestinations - if not file: + if not file or not destination: return None + local = True if destination == FileDestinations.LOCAL else False + absolutePath = self.getAbsolutePath(file.filename, mustExist=False) + + logging.info("Adding file:%s" % absolutePath) if absolutePath is None: return None @@ -133,19 +138,22 @@ class GcodeManager: filename = file.filename if isGcodeFileName(filename): + logging.info("File is Gcode File") return self.processGcode(absolutePath) curaEnabled = self._settings.get(["curaEngine", "enabled"]) + logging.info("Cura Enabled %s" % str(curaEnabled)) - if isSTLFileName(filename) and curaEnabled: + if isSTLFileName(filename) and curaEnabled and local: + logging.info("File is STL - Needs to be sliced") gcodePath = util.genGcodeFileName(absolutePath) logging.info("FILENAME: %s" % filename) callBackArgs = [gcodePath] callBack = self.processGcode - return self.processSTL( - filename, absolutePath, callBack, callBackArgs) + self.processSTL(absolutePath, callBack, callBackArgs) + return filename def getFutureFileName(self, file): if not file: @@ -157,21 +165,19 @@ class GcodeManager: return self._getBasicFilename(absolutePath) - - def processSTL(self, filename, absolutePath, callBack, callBackArgs): + def processSTL(self, absolutePath, callBack, callBackArgs): from octoprint.cura import CuraFactory curaEngine = CuraFactory.create_slicer() - gcodePath = util.genGcodeFileName(absolutePath) - config = self._settings.get(["curaEngine", "config"]) curaEngine.process_file( - config, gcodePath, absolutePath, callBack, callBackArgs) - + config, gcodePath, absolutePath, callBack, callBackArgs) def processGcode(self, absolutePath): + if absolutePath is None: + return None filename = self._getBasicFilename(absolutePath) @@ -185,19 +191,6 @@ class GcodeManager: return filename - if absolutePath is None: - return None - - basename = self._getBasicFilename(absolutePath) - if basename in self._metadata.keys(): - # delete existing metadata entry, since the file is going to get overwritten - del self._metadata[basename] - self._metadataDirty = True - self._saveMetadata() - file.save(absolutePath) - self._metadataAnalyzer.addFileToQueue(basename) - return basename - def getFutureFilename(self, file): if not file: return None @@ -211,10 +204,16 @@ class GcodeManager: def removeFile(self, filename): filename = self._getBasicFilename(filename) absolutePath = self.getAbsolutePath(filename) + stlPath = util.genStlFileName(absolutePath) + if absolutePath is None: return + if stlPath: + os.remove(stlPath) + os.remove(absolutePath) + if filename in self._metadata.keys(): del self._metadata[filename] self._metadataDirty = True diff --git a/octoprint/printer.py b/octoprint/printer.py index ae080ea3..9a394bbe 100644 --- a/octoprint/printer.py +++ b/octoprint/printer.py @@ -7,6 +7,7 @@ import datetime import threading import copy import os +import logging #import logging, logging.config @@ -463,27 +464,26 @@ class Printer(): from octoprint.util import isGcodeFileName from octoprint.util import isSTLFileName + logging.info("Adding SD Card file:%s" % filename) if not self._comm or self._comm.isBusy(): + logging.error("No connection to printer or printer is busy") return if isGcodeFileName(filename): + logging.info("Sending Gcode to SD card") self.streamSdFile(filename, absolutePath) if isSTLFileName(filename): + logging.info("Slicing stl and then sending to SD card") gcodePath = util.genGcodeFileName(absolutePath) - callBackArgs = [filename, absolutePath] + gcodeFileName = util.genGcodeFileName(filename) + callBackArgs = [gcodeFileName, gcodePath] callBack = self.streamSdFile - gcodeManager = GcodeManager() - gcodeManager.processSTL( - filename, absolutePath, callBack, callBackArgs) + self._gcodeManager.processSTL( + absolutePath, callBack, callBackArgs) - def streamSdFile(filename, absolutePath): - self._sdStreamer = SdFileStreamer(self._comm, filename, absolutePath, self._onSdFileStreamProgress, self._onSdFileStreamFinish) - self._sdStreamer.start() - logging.info("Stream file to SD started") - - def addSdFile(self, filename, path): + def streamSdFile(self, filename, path): if not self._comm or self._comm.isBusy(): return self._comm.startFileTransfer(path, filename[:8].lower() + ".gco") diff --git a/octoprint/server.py b/octoprint/server.py index f02c87ce..c1c5140e 100644 --- a/octoprint/server.py +++ b/octoprint/server.py @@ -19,6 +19,8 @@ import octoprint.timelapse import octoprint.gcodefiles as gcodefiles import octoprint.util as util import octoprint.users as users +from octoprint.filemanager.destinations import FileDestinations + import octoprint.events as events @@ -311,12 +313,16 @@ def readGcodeFile(filename): @login_required def uploadGcodeFile(): if "gcode_file" in request.files.keys(): + logging.info("Uploading Gcode File") file = request.files["gcode_file"] sd = "target" in request.values.keys() and request.values["target"] == "sd"; + logging.info("SD:%s" % str(sd)) + currentFilename = None currentSd = None currentJob = printer.getCurrentJob() + logging.info("Current Job:%s" % str(currentJob)) if currentJob is not None and "filename" in currentJob.keys() and "sd" in currentJob.keys(): currentFilename = currentJob["filename"] currentSd = currentJob["sd"] @@ -329,13 +335,16 @@ def uploadGcodeFile(): # trying to overwrite currently selected file, but it is being printed return make_response("Trying to overwrite file that is currently being printed: %s" % currentFilename, 403) - filename = gcodeManager.addFile(file) + destination = FileDestinations.SDCARD if sd else FileDestinations.LOCAL + + filename = gcodeManager.addFile(file, destination) if filename is None: return make_response("Could not upload the file %s" % file.filename, 500) absFilename = gcodeManager.getAbsolutePath(filename) if sd: + logging.info("Add to SD file") printer.addSdFile(filename, absFilename) if currentFilename == filename and currentSd == sd: diff --git a/octoprint/util/__init__.py b/octoprint/util/__init__.py index ce6a9172..5bd7578b 100644 --- a/octoprint/util/__init__.py +++ b/octoprint/util/__init__.py @@ -82,7 +82,16 @@ def genGcodeFileName(filename): return filename.replace('.stl', '.gcode') +def genStlFileName(filename): + if not filename: + return None + + if "." not in filename: + return filename + ".stl" + + return filename.replace('.gcode', '.stl') + def isDevVersion(): gitPath = os.path.abspath(os.path.join(os.path.split(os.path.abspath(__file__))[0], "../../.git")) return os.path.exists(gitPath) diff --git a/octoprint/util/comm.py b/octoprint/util/comm.py index 32f66c76..1460cab5 100644 --- a/octoprint/util/comm.py +++ b/octoprint/util/comm.py @@ -332,10 +332,13 @@ class MachineCom(object): eventManager().fire("Error", self.getErrorString()) def startFileTransfer(self, filename, remoteFilename): + logging.info("Starting File Transfer:%s" % filename) if not self.isOperational() or self.isBusy(): + logging.info("Printer is not operation or busy") return self._currentFile = StreamingGcodeFileInformation(filename) + logging.info("Starting to send currentfile:%s" % str(self._currentFile)) self._currentFile.start() self.sendCommand("M28 %s" % remoteFilename) @@ -405,6 +408,7 @@ class MachineCom(object): def endSdFileTransfer(self, filename): if not self.isOperational() or self.isBusy(): + logging.info("endSdFile busy") return self.sendCommand("M29 %s" % filename.lower()) @@ -595,6 +599,8 @@ class MachineCom(object): self._callback.mcPrintjobDone() self._changeState(self.STATE_OPERATIONAL) eventManager().fire("PrintDone") + elif 'Done saving file' in line: + self.refreshSdFiles() ##~~ Message handling elif line.strip() != '' and line.strip() != 'ok' and not line.startswith("wait") and not line.startswith('Resend:') and line != 'echo:Unknown command:""\n' and self.isOperational(): @@ -674,8 +680,8 @@ class MachineCom(object): startSeen = True elif "ok" in line and startSeen: self._changeState(self.STATE_OPERATIONAL) - if self._sdAvailable: - self.refreshSdFiles() + if not self._sdAvailable: + self.initSdCard() eventManager().fire("Connected", "%s at %s baud" % (self._port, self._baudrate)) elif time.time() > timeout: self.close()