diff options
author | Lars Wirzenius <liw@liw.fi> | 2011-08-02 17:36:00 +0100 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2011-08-02 17:36:00 +0100 |
commit | 0014611f7f756588a27e55947a1286c3b8c2a127 (patch) | |
tree | 6041a47b57c83e570f80505ce3849a2d175a6122 | |
parent | cdce731982f390ef5d28d7161c481d2913de6375 (diff) | |
download | seivot-0014611f7f756588a27e55947a1286c3b8c2a127.tar.gz |
Make some columns be left-aligned.
-rwxr-xr-x | seivots-summary | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/seivots-summary b/seivots-summary index c1a82cd..71e88c6 100755 --- a/seivots-summary +++ b/seivots-summary @@ -33,8 +33,8 @@ class Table(object): self.columns = [] self.rows = [] - def add_column(self, heading1, heading2, format): - self.columns.append((heading1, heading2, format)) + def add_column(self, heading1, heading2, format, left): + self.columns.append((heading1, heading2, format, left)) def add_row(self, data): assert len(data) == len(self.columns) @@ -45,8 +45,8 @@ class Table(object): f.write('%s\n%s\n\n' % (self.caption, '-' * len(self.caption))) cells = [] - cells.append([h1 for h1, h2, format in self.columns]) - cells.append([h2 for h1, h2, format in self.columns]) + cells.append([h1 for h1, h2, format, left in self.columns]) + cells.append([h2 for h1, h2, format, left in self.columns]) for row in self.rows: cells.append([self.format_cell(row[i], self.columns[i][2]) for i in range(len(self.columns))]) @@ -55,9 +55,17 @@ class Table(object): f.write('%s\n' % self.format_headings(widths, 0)) f.write('%s\n' % self.format_headings(widths, 1)) + f.write('\n') for row in self.rows: f.write('%s\n' % self.format_row(row, widths)) + def align_cell(self, width, text, column): + h1, h2, fmt, left = self.columns[column] + if not left: + return '%-*s' % (width, text) + else: + return'%*s' % (width, text) + def format_cell(self, data, format): return format % data @@ -69,12 +77,12 @@ class Table(object): return widths def format_headings(self, widths, which): - headings = ['%*s' % (widths[i], self.columns[i][which]) + headings = [self.align_cell(widths[i], self.columns[i][which], i) for i in range(len(widths))] return self.sep.join(headings) def format_row(self, row, widths): - cells = ['%*s' % (widths[i], self.columns[i][2] % row[i]) + cells = [self.align_cell(widths[i], self.columns[i][2] % row[i], i) for i in range(len(widths))] return self.sep.join(cells) @@ -118,6 +126,8 @@ class SeivotsSummary(cliapp.Application): 'description': ('desc', '', '%s', self.get_description), } + leftist = ('branch', 'description') + prefix = ('obnam-revno', 'larch-revno') which = { 'backup': @@ -139,7 +149,7 @@ class SeivotsSummary(cliapp.Application): table = Table() for colname in colnames: h1, h2, fmt, func = cols[colname] - table.add_column(h1, h2, fmt) + table.add_column(h1, h2, fmt, colname in leftist) for seivot in group: row = [] |