Ejemplo n.º 1
0
def isPrintJobReprintable(fileManager, fileOrigin, filePathName, fileName):
    resultPrintJobPrintable = {}

    isRePrintable = False
    fullFileLocation = ""
    filePath = filePathName if StringUtils.isNotEmpty(
        filePathName) else fileName

    if (fileOrigin == None):
        # could be during csv import, assumption it is local
        fileOrigin = FileDestinations.LOCAL

    if (fileOrigin == FileDestinations.LOCAL):
        # local filesystem
        fullFileLocation = fileManager.path_on_disk(fileOrigin, filePath)
        isRePrintable = _isFileReadable(fullFileLocation)
        pass
    else:
        # sd-card
        # - no readable check (positiv thinking)
        isRePrintable = True
        fullFileLocation = fileOrigin + ":/" + filePath

    resultPrintJobPrintable["isRePrintable"] = isRePrintable
    resultPrintJobPrintable["fullFileLocation"] = fullFileLocation
    return resultPrintJobPrintable
Ejemplo n.º 2
0
    def formatValue(self, printJob, fieldName):

        costModel = printJob.getCosts()
        if (costModel == None):
            return "-"

        if (hasattr(costModel, fieldName) == False):
            return "-"

        valueToFormat = getattr(costModel, fieldName)

        if ("filamentCost" == fieldName or "electricityCost" == fieldName
                or "printerCost" == fieldName or "otherCost" == fieldName):
            if (valueToFormat != None and valueToFormat != ""
                    and valueToFormat != "-"):
                valueToFormat = StringUtils.formatFloatSave(
                    StringUtils.FLOAT_DEFAULT_FORMAT, valueToFormat, "-")
                if ("otherCost" == fieldName):
                    otherCostLabel = ""
                    if (StringUtils.isNotEmpty(costModel.otherCostLabel)):
                        otherCostLabel = costModel.otherCostLabel
                    valueToFormat = otherCostLabel + ":" + valueToFormat

        if valueToFormat is None or "" == valueToFormat:
            return "-"

        return valueToFormat
	def _toIntFromJSONOrNone(self, key, json):
		value = self._getValueFromJSONOrNone(key, json)
		if (value != None):
			if (StringUtils.isNotEmpty(value)):
				try:
					value = int(value)
				except Exception as e:
					errorMessage = str(e)
					self._logger.error("could not transform value '"+str(value)+"' for key '"+key+"' to int:" + errorMessage)
					value = None
			else:
				value = None
		return value
Ejemplo n.º 4
0
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:
                    # pre check, do we have values in the line?
                    isEmptyLine = True
                    for columnValue in row:
                        if (StringUtils.isNotEmpty(columnValue)):
                            isEmptyLine = False
                            break
                    if (isEmptyLine == True):
                        # errorCollection.append("CSV Line: "+str(lineNumber)+" without values! <br/>")
                        # just skip this line
                        continue
                    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