Esempio n. 1
0
    def __writeTable(self, categoryObj, numSteps=5):
        indS = " " * self.__INDENT_DEFINITION
        myCategory = DataCategoryFormatted(
            categoryObj, preferDoubleQuotes=self.__preferDoubleQuotes)
        # Write the declaration of the loop_
        #
        lineList = []
        lineList.append(indS + '#\n')
        if self.__doDefinitionIndent:
            lineList.append(self.__indentSpace)
        lineList.append("loop_")
        for attributeName in myCategory.getAttributeList():
            lineList.append('\n')
            if self.__doDefinitionIndent:
                lineList.append(self.__indentSpace)
            itemName = "_%s.%s" % (myCategory.getName(), attributeName)
            lineList.append(itemName)
        self.__write("".join(lineList))

        #
        formatTypeList, dataTypeList = myCategory.getFormatTypeList(
            steps=numSteps)
        spacing = " " * self.__SPACING
        #
        for iRow in range(myCategory.getRowCount()):
            lineList = []
            lineList.append('\n')
            if self.__doDefinitionIndent:
                lineList.append(self.__indentSpace + "  ")

            for iAt in range(myCategory.getAttributeCount()):
                formatType = formatTypeList[iAt]

                if (formatType == 'FT_UNQUOTED_STRING'
                        or formatType == 'FT_NULL_VALUE'):
                    val = myCategory.getValueFormattedByIndex(iAt, iRow)
                    lineList.append(val)

                elif formatType == 'FT_NUMBER':
                    val = myCategory.getValueFormattedByIndex(iAt, iRow)
                    lineList.append(val)

                elif formatType == 'FT_QUOTED_STRING':
                    val = myCategory.getValueFormattedByIndex(iAt, iRow)
                    lineList.append(val)

                elif formatType == "FT_MULTI_LINE_STRING":
                    val = myCategory.getValueFormattedByIndex(iAt, iRow)
                    lineList.append(val)

                lineList.append(spacing)

            self.__write("".join(lineList))
        self.__write("\n")
        if self.__useStopTokens:
            self.__write("stop_\n")
Esempio n. 2
0
    def __writeTableFormat(self, categoryObj):
        # indS = " " * self.__INDENT_DEFINITION
        myCategory = DataCategoryFormatted(
            categoryObj, preferDoubleQuotes=self.__preferDoubleQuotes)
        # Write the declaration of the loop_
        #
        lineList = []
        # lineList.append(indS + '#\n')
        lineList.append("\n")
        if self.__doDefinitionIndent:
            lineList.append(self.__indentSpace)
        lineList.append("loop_")
        for attributeName in myCategory.getAttributeList():
            lineList.append("\n")
            if self.__doDefinitionIndent:
                lineList.append(self.__indentSpace)
            itemName = "_%s.%s" % (myCategory.getName(), attributeName)
            lineList.append(itemName)
        self.__write("".join(lineList))

        #
        # Write the data in tabular format -
        #
        # print myCategory.getName()
        # print myCategory.getAttributeList()

        #    For speed make the following evaluation on a portion of the table
        if self.__rowPartition is not None:
            numSteps = max(1, myCategory.getRowCount() // self.__rowPartition)
        else:
            numSteps = 1

        formatTypeList, _ = myCategory.getFormatTypeList(steps=numSteps)
        maxLengthList = myCategory.getAttributeValueMaxLengthList(
            steps=numSteps)
        spacing = " " * self.__spacing
        #

        # print formatTypeList
        # print dataTypeList
        # print maxLengthList
        #
        for iRow in range(myCategory.getRowCount()):
            lineList = []
            lineList.append("\n")
            if self.__doDefinitionIndent:
                lineList.append(self.__indentSpace + "  ")

            for iAt in range(myCategory.getAttributeCount()):
                formatType = formatTypeList[iAt]
                maxLength = maxLengthList[iAt]

                if formatType == "FT_UNQUOTED_STRING" or formatType == "FT_NULL_VALUE":
                    val = myCategory.getValueFormattedByIndex(iAt, iRow)
                    lineList.append(val.ljust(maxLength))

                elif formatType == "FT_NUMBER":
                    val = myCategory.getValueFormattedByIndex(iAt, iRow)
                    lineList.append(val.rjust(maxLength))

                elif formatType == "FT_QUOTED_STRING":
                    val = myCategory.getValueFormattedByIndex(iAt, iRow)
                    # don't pad the last item in row condition
                    if iAt == myCategory.getAttributeCount() - 1:
                        lineList.append(val.ljust(len(val)))
                    else:
                        lineList.append(val.ljust(maxLength + 2))

                elif formatType == "FT_MULTI_LINE_STRING":
                    val = myCategory.getValueFormattedByIndex(iAt, iRow)
                    lineList.append(val)

                lineList.append(spacing)

            self.__write("".join(lineList))
        self.__write("\n")
        if self.__useStopTokens:
            self.__write("stop_\n")