| 114 | return self.gen_rst_table(fields, rows, **kwargs) |
| 115 | |
| 116 | def gen_rst_table(self, field_names, rows, tab_size=4): |
| 117 | assert(not rows or len(field_names) == len(rows[0])) |
| 118 | rows.append(field_names) |
| 119 | fld_len = len(field_names) |
| 120 | cls_len = [max(len(c[i]) for c in rows) for i in range(fld_len)] |
| 121 | del rows[-1] |
| 122 | cformat = ' '.join('{:<%d}' % i for i in cls_len) |
| 123 | border = cformat.format(*['='*i for i in cls_len]) |
| 124 | |
| 125 | rows = [cformat.format(*row) for row in rows] |
| 126 | # header |
| 127 | rows = [border, cformat.format(*field_names), border] + rows |
| 128 | # footer |
| 129 | rows += [border] |
| 130 | # add left margin |
| 131 | rows = [(' ' * tab_size) + r for r in rows] |
| 132 | return '\n'.join(rows) |
| 133 | |
| 134 | def wrapper_section(title, content, tab_size=4): |
| 135 | tab = ' '*tab_size |