def _createPrintJobModel(self, payload): self._currentPrintJobModel = PrintJobModel() self._currentPrintJobModel.printStartDateTime = datetime.datetime.now() self._currentPrintJobModel.fileOrigin = payload["origin"] self._currentPrintJobModel.fileName = payload["name"] self._currentPrintJobModel.filePathName = payload["path"] # self._file_manager.path_on_disk() if "owner" in payload: self._currentPrintJobModel.userName = payload["owner"] else: self._currentPrintJobModel.userName = "******" self._currentPrintJobModel.fileSize = payload["size"] tempFound = False toolId = self._settings.get( [SettingsKeys.SETTINGS_KEY_DEFAULT_TOOL_ID]) tempTool = -1 tempBed = 0 shouldReadTemperatureFromPreHeat = self._settings.get_boolean( [SettingsKeys.SETTINGS_KEY_TAKE_TEMPERATURE_FROM_PREHEAT]) if (shouldReadTemperatureFromPreHeat == True): self._logger.info("Try reading Temperature from PreHeat-Plugin...") if (self._preHeatPluginImplementation != None): path_on_disk = octoprint.server.fileManager.path_on_disk( self._currentPrintJobModel.fileOrigin, self._currentPrintJobModel.filePathName) preHeatTemperature = self._preHeatPluginImplementation.read_temperatures_from_file( path_on_disk) if preHeatTemperature != None: if "bed" in preHeatTemperature: tempBed = preHeatTemperature["bed"] tempFound = True if toolId in preHeatTemperature: tempTool = preHeatTemperature[toolId] #"tool0" tempFound = True else: self._logger.warn( "... PreHeat-Temperatures does not include default Extruder-Tool '" + toolId + "'") pass else: self._logger.warn("... PreHeat Plugin not installed/enabled") if (tempFound == True): self._logger.info("... Temperature found '" + str(tempBed) + "' ' Tool '" + toolId + "' '" + str(tempTool) + "'") self._addTemperatureToPrintModel(self._currentPrintJobModel, tempBed, toolId, tempTool) else: # readTemperatureFromPrinter # because temperature is 0 at the beginning, we need to wait a couple of seconds (maybe 3) self._readAndAssignCurrentTemperatureDelayed( self._currentPrintJobModel)
def _createPrintJobModel(self, payload): self._currentPrintJobModel = PrintJobModel() self._currentPrintJobModel.printStartDateTime = datetime.datetime.now() self._currentPrintJobModel.fileOrigin = payload["origin"] self._currentPrintJobModel.fileName = payload["name"] self._currentPrintJobModel.filePathName = payload["path"] # self._file_manager.path_on_disk() if "owner" in payload: self._currentPrintJobModel.userName = payload["owner"] else: self._currentPrintJobModel.userName = "******" self._currentPrintJobModel.fileSize = payload["size"] tempFound = False tempTool = 0 tempBed = 0 if self._preHeatPluginImplementation != None: path_on_disk = octoprint.server.fileManager.path_on_disk( self._currentPrintJobModel.fileOrigin, self._currentPrintJobModel.filePathName) preHeatTemperature = self._preHeatPluginImplementation.read_temperatures_from_file( path_on_disk) if preHeatTemperature != None: if "bed" in preHeatTemperature: tempBed = preHeatTemperature["bed"] tempFound = True if "tool0" in preHeatTemperature: tempTool = preHeatTemperature["tool0"] tempFound = True pass else: currentTemps = self._printer.get_current_temperatures() if (len(currentTemps) > 0): tempBed = currentTemps[0]["bed"]["target"] tempTool = currentTemps[0]["tool0"]["target"] tempFound = True if (tempFound == True): tempModel = TemperatureModel() tempModel.sensorName = "bed" tempModel.sensorValue = tempBed self._currentPrintJobModel.addTemperatureModel(tempModel) tempModel = TemperatureModel() tempModel.sensorName = "tool0" tempModel.sensorValue = tempTool self._currentPrintJobModel.addTemperatureModel(tempModel)
def _createPrintJobModel(self, payload): self._currentPrintJobModel = PrintJobModel() self._currentPrintJobModel.printStartDateTime = datetime.datetime.now() self._currentPrintJobModel.fileOrigin = payload["origin"] self._currentPrintJobModel.fileName = payload["name"] self._currentPrintJobModel.filePathName = payload["path"] # self._file_manager.path_on_disk() if "owner" in payload: self._currentPrintJobModel.userName = payload["owner"] else: self._currentPrintJobModel.userName = "******" self._currentPrintJobModel.fileSize = payload["size"] tempFound = False tempTool = 0 tempBed = 0 if self._preHeatPluginImplementation != None: path_on_disk = octoprint.server.fileManager.path_on_disk( self._currentPrintJobModel.fileOrigin, self._currentPrintJobModel.filePathName) preHeatTemperature = self._preHeatPluginImplementation.read_temperatures_from_file( path_on_disk) if preHeatTemperature != None: if "bed" in preHeatTemperature: tempBed = preHeatTemperature["bed"] tempFound = True if "tool0" in preHeatTemperature: tempTool = preHeatTemperature["tool0"] tempFound = True pass else: # because temperature is 0 at the beginning, we need to wait a couple of seconds (maybe 3) self._readAndAssignCurrentTemperatureDelayed( self._currentPrintJobModel) if (tempFound == True): self._addTemperatureToPrintModel(self._currentPrintJobModel, tempBed, tempTool)
def parseCSV(csvFile4Import, errorCollection, logger): result = list() # List with printJobModels lineNumber = 0 try: with open(csvFile4Import) as csv_file: csv_reader = csv.reader(csv_file, delimiter=',') lineNumber = 0 for row in csv_reader: lineNumber += 1 if lineNumber == 1: # createColumnOrderFromHeader(row) # mandatoryFieldCount = 0 mandatoryFieldAvaiable = list() columnIndex = 0 for column in row: column = column.strip() if column in ALL_COLUMNS: columnOrderInFile[columnIndex] = ALL_COLUMNS[ column] if column in mandatoryFieldNames: mandatoryFieldAvaiable.append(column) # mandatoryFieldCount += 1 columnIndex += 1 if len(mandatoryFieldAvaiable) != len(mandatoryFieldNames): # if mandatoryFieldCount != len(mandatoryFieldNames): # identify missing files # mandatoryFieldMissing = mandatoryFieldNames - mandatoryFieldAvaiable mandatoryFieldMissing = list( set(mandatoryFieldNames) - set(mandatoryFieldAvaiable)) errorCollection.append( "Mandatory column is missing! <br/><b>'" + "".join(mandatoryFieldMissing) + "'</b><br/>") break else: printJobModel = PrintJobModel() # parse line with header defined order columnIndex = 0 for columnValue in row: if columnIndex in columnOrderInFile: csvColumn = columnOrderInFile[columnIndex] if not csvColumn == None: columnValue = columnValue.strip() csvColumn.parseAndAssignFieldValue( columnValue, printJobModel, errorCollection, lineNumber) pass columnIndex += 1 if (len(errorCollection) != 0): logger.warn("ERROR(s) occurred!!!!!") else: result.append(printJobModel) pass except Exception as e: errorMessage = "Error during processing file '" + csvFile4Import + "' error '" + str( e) + "' line '" + str(lineNumber) + "'" errorCollection.append(errorMessage) logger.error(errorMessage) finally: logger.info("Removing uploded csv temp-file") try: os.remove(csvFile4Import) except Exception: pass print("Processed " + str(lineNumber)) return result
def parseCSV(csvFile4Import, updateParsingStatus, errorCollection, logger, deleteAfterParsing=True): result = list() # List with printJobModels lineNumber = 0 try: with open(csvFile4Import) as csv_file: csv_reader = csv.reader(csv_file, delimiter=',') lineNumber = 0 for row in csv_reader: lineNumber += 1 # import time # time.sleep(1) updateParsingStatus(str(lineNumber)) if lineNumber == 1: # createColumnOrderFromHeader(row) # mandatoryFieldCount = 0 mandatoryFieldAvaiable = list() columnIndex = 0 for column in row: column = column.strip() if column in ALL_COLUMNS: columnOrderInFile[columnIndex] = ALL_COLUMNS[column] if column in mandatoryFieldNames: mandatoryFieldAvaiable.append(column) # mandatoryFieldCount += 1 columnIndex += 1 if len(mandatoryFieldAvaiable) != len(mandatoryFieldNames): # if mandatoryFieldCount != len(mandatoryFieldNames): # identify missing files # mandatoryFieldMissing = mandatoryFieldNames - mandatoryFieldAvaiable mandatoryFieldMissing = list( set(mandatoryFieldNames) - set(mandatoryFieldAvaiable) ) errorCollection.append("Mandatory column is missing! <br/><b>'" + "".join(mandatoryFieldMissing) + "'</b><br/>") break else: printJobModel = PrintJobModel() # parse line with header defined order columnIndex = 0 for columnValue in row: if columnIndex in columnOrderInFile: csvColumn = columnOrderInFile[columnIndex] if not csvColumn == None: columnValue = columnValue.strip() # check if mandatory value is missing if (len(columnValue) == 0): columnName = csvColumn.columnLabel if columnName in mandatoryFieldNames: errorCollection.append("["+str(lineNumber)+"] Mandatory value for column '" + columnName + "' is missing!") pass else: csvColumn.parseAndAssignFieldValue(columnValue, printJobModel, errorCollection, lineNumber) pass columnIndex += 1 if (len(errorCollection) != 0): logger.error("Reading error line '" + str(lineNumber) + "' in Column '" + column + "' ") else: result.append(printJobModel) pass except Exception as e: errorMessage = "CSV Parsing error. Line:'" + str(lineNumber) + "' Error:'" + str(e) + "' File:'" + csvFile4Import + "'" errorCollection.append(errorMessage) logger.error(errorMessage) finally: if (deleteAfterParsing): logger.info("Removing uploded csv temp-file") try: os.remove(csvFile4Import) except Exception: pass return result
def createWithDefaults(self): newPrintJobModel = PrintJobModel() totalFilament = FilamentModel() totalFilament.toolId = "total" newPrintJobModel.addFilamentModel(totalFilament) return newPrintJobModel