def parseAndAssignFieldValue(self, fieldLabel, fieldName, fieldValue, printJobModel, errorCollection, lineNumber): if ("" == fieldValue or "-" == fieldValue or fieldValue == None): # check if mandatory return matched = self.tempPattern.match(fieldValue) if (matched): bedTemp = float(matched.group(1)) toolTemp = float(matched.group(2)) tempModel = TemperatureModel() tempModel.sensorName = "bed" tempModel.sensorValue = bedTemp printJobModel.addTemperatureModel(tempModel) tempModel = TemperatureModel() tempModel.sensorName = "tool0" tempModel.sensorValue = toolTemp printJobModel.addTemperatureModel(tempModel) pass else: errorCollection.append( "[" + str(lineNumber) + "]" + " Wrong temperature format. Allowed: 'bed:60.0 tool0:200.0'") pass
def deletePrintJob(self, databaseId): databaseIdAsInt = StringUtils.transformToIntOrNone(databaseId) if (databaseIdAsInt == None): self._logger.error( "Could not delete PrintJob, because not a valid databaseId '" + str(databaseId) + "' maybe not a number") return None with self._database.atomic() as transaction: # Opens new transaction. try: # first delete relations n = FilamentModel.delete().where( FilamentModel.printJob == databaseIdAsInt).execute() n = TemperatureModel.delete().where( TemperatureModel.printJob == databaseIdAsInt).execute() n = CostModel.delete().where( CostModel.printJob == databaseIdAsInt).execute() PrintJobModel.delete_by_id(databaseIdAsInt) except Exception as e: # Because this block of code is wrapped with "atomic", a # new transaction will begin automatically after the call # to rollback(). transaction.rollback() self._logger.exception( "Could not delete printJob from database:" + str(e)) self.sendErrorMessageToClient( "PJH-DatabaseManager", "Could not delete the printjob ('" + str(databaseId) + "') from the database. See OctoPrint.log for details!") pass
def _addTemperatureToPrintModel(self, printJobModel, bedTemp, toolTemp): tempModel = TemperatureModel() tempModel.sensorName = "bed" tempModel.sensorValue = bedTemp printJobModel.addTemperatureModel(tempModel) tempModel = TemperatureModel() tempModel.sensorName = "tool0" tempModel.sensorValue = toolTemp printJobModel.addTemperatureModel(tempModel)
def _addTemperatureToPrintModel(self, printJobModel, bedTemp, toolId, toolTemp): tempModel = TemperatureModel() tempModel.sensorName = "bed" # tempModel.sensorValue = bedTemp if bedTemp != None else"-" tempModel.sensorValue = bedTemp if bedTemp != None else "-" printJobModel.addTemperatureModel(tempModel) tempModel = TemperatureModel() tempModel.sensorName = toolId #"tool0" tempModel.sensorValue = toolTemp if toolTemp != None else "-" printJobModel.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: 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 deletePrintJob(self, databaseId): with self._database.atomic() as transaction: # Opens new transaction. try: # first delete relations n = FilamentModel.delete().where(FilamentModel.printJob == databaseId).execute() n = TemperatureModel.delete().where(TemperatureModel.printJob == databaseId).execute() PrintJobModel.delete_by_id(databaseId) except Exception as e: # Because this block of code is wrapped with "atomic", a # new transaction will begin automatically after the call # to rollback(). transaction.rollback() self._logger.exception("Could not delete printJob from database:" + str(e)) self.sendErrorMessageToClient("PJH-DatabaseManager", "Could not delete the printjob ('"+ str(databaseId) +"') from the database. See OctoPrint.log for details!") pass