CONSTRUCTOR.
75 ):
76
77 self.data = data
78 self.headline=headline
79 self.headline_color=headline_color
80 self.header_color = header_color
81
82 if len(self.data) < 3:
84 log.info(
'To fulfill the table design, it must have header row, separator row and a final separator row.')
85 raise ValueError()
86 if not isinstance(self.data[0][0], int):
87 log.warning(
'The first column of first row is not as "int".')
88 log.info(
'To fulfill the table design, each row must start with a row type integer constant.')
89 if self.data[0][0] != HEADER:
90 log.warning(
'First data row is not the table header.')
91 log.info(
'To fulfil the table design, the table header must be sorted to the first index position.')
92
93 row_lengths: list[int] = []
94 for i in range(len(self.data)):
95 row = self.data[i]
96 if self.data[i][0] not in ROW_TYPES:
97 log.warning(
'Found not implemented value "{}" in row type column.'.format(self.data[i][0]))
98 log.info(
'The first value in each row must be in "{}" = "[tbl.HEADER, tbl.SEPARATOR, tbl.DATA]".'.format(ROW_TYPES))
99 raise NotImplementedError()
100 if self.data[i][0] is SEPARATOR:
101 self.data[i] = (
102 [self.data[i][0]]
103 +
104 [None for _ in range(len(self.data[0]) - 1)]
105 )
106 row_lengths.append(len(self.data[i]))
107 if (row[0] != SEPARATOR) and (row_lengths[-1] < 2):
109 log.info(
'Each data and header row must have a row type column and min. 1 data cell column.')
110 raise ValueError()
111 for j in range(len(row)):
112 if j == 0: continue
113 cell = str(data[i][j])
114
115
116 if cell is not None:
117 if not cell.startswith(' '):
118 cell = ' ' + str(cell)
119 if not cell.endswith(' '):
120 cell += ' '
121 data[i][j] = cell
122
123
124
125 if not all(item == row_lengths[0] for item in row_lengths):
127 'Length of each row is not identical (see {}).'.format(row_lengths))
128 log.info(
'Check/repair the deviating rows.')
129 raise ValueError()
130
warning((str, tuple) msg)
Log warning message colored to console only.
info((str, tuple) msg)
Log info message colored to console only.