Revision: 96729d270fc0
Author:   Robot Framework Developers <[email protected]>
Date:     Tue Jan  3 05:53:35 2012
Log:      txtwriter: align last column in pipe separated format
http://code.google.com/p/robotframework/source/detail?r=96729d270fc0

Modified:
 /src/robot/writer/formatters.py
 /src/robot/writer/tableformatters.py

=======================================
--- /src/robot/writer/formatters.py     Tue Jan  3 05:09:21 2012
+++ /src/robot/writer/formatters.py     Tue Jan  3 05:53:35 2012
@@ -76,6 +76,7 @@
 class TxtFormatter(_TestDataFileFormatter):
     _FIRST_ROW_LENGTH = 18
     _SETTING_NAME_WIDTH = 14
+    _align_last_column = False

     def __init__(self, cols=8):
         self._cols = cols
@@ -95,12 +96,12 @@
     def header_row(self, table):
         header = ['*** %s ***' % table.header[0]] + table.header[1:]
         if self._should_align_columns(table):
- return ColumnAligner(self._FIRST_ROW_LENGTH, table).align_row(header) + return ColumnAligner(self._FIRST_ROW_LENGTH, table, self._align_last_column).align_row(header)
         return header

     def _indented_table_formatter(self, table):
         if self._should_align_columns(table):
-            return ColumnAligner(self._FIRST_ROW_LENGTH, table)
+ return ColumnAligner(self._FIRST_ROW_LENGTH, table, self._align_last_column)
         return RowSplittingFormatter(self._cols)

     def _should_align_columns(self, table):
@@ -124,6 +125,7 @@


 class PipeFormatter(TxtFormatter):
+    _align_last_column = True

     def _escape(self, row):
         row = self._format_empty_cells(row)
=======================================
--- /src/robot/writer/tableformatters.py        Tue Jan  3 04:46:29 2012
+++ /src/robot/writer/tableformatters.py        Tue Jan  3 05:53:35 2012
@@ -66,22 +66,31 @@


 class _Aligner(_Formatter):
+
+    def __init__(self, widths, align_last_column=False):
+        self._widths = widths
+        self._align_last_column = align_last_column
+
     def align_rows(self, rows):
         return [self.align_row(r) for r in rows]

     def align_row(self, row):
-        for index, col in enumerate(row[:-1]):
+        for index, col in enumerate(row[:self._last_aligned_column(row)]):
             if len(self._widths) <= index:
                 continue
             row[index] = row[index].ljust(self._widths[index])
         return row


+    def _last_aligned_column(self, row):
+        return len(row) if self._align_last_column else -1
+
+
 class SettingTableAligner(_Aligner):

     def __init__(self, cols, first_column_width):
         self._row_splitter = RowSplitter(cols)
-        self._widths = [first_column_width]
+        _Aligner.__init__(self, [first_column_width])

     def format_simple_table(self, table):
         return self.align_rows(self._rows_from_simple_table(table))
@@ -92,12 +101,13 @@

 class ColumnAligner(_Aligner):

-    def __init__(self, max_name_length, table):
+    def __init__(self, max_name_length, table, align_last_column):
         self._max_name_length = max_name_length
-        self._widths = self._count_justifications(table)
+        _Aligner.__init__(self, self._count_justifications(table),
+                          align_last_column)

     def _count_justifications(self, table):
-        result = [18] + [len(header) for header in table.header]
+ result = [self._max_name_length] + [len(header) for header in table.header]
         for element in [list(kw) for kw in list(table)]:
             for step in element:
                 for index, col in enumerate(step.as_list()):

Reply via email to