|
25 | 25 | """ |
26 | 26 | Routines for printing columnar output. See colify() for more information. |
27 | 27 | """ |
| 28 | +from __future__ import division |
| 29 | + |
28 | 30 | import os |
29 | 31 | import sys |
30 | | -from StringIO import StringIO |
| 32 | +from six import StringIO |
31 | 33 |
|
32 | 34 | from llnl.util.tty import terminal_size |
33 | 35 | from llnl.util.tty.color import clen, cextra |
@@ -64,18 +66,18 @@ def config_variable_cols(elts, console_width, padding, cols=0): |
64 | 66 | # Get a bound on the most columns we could possibly have. |
65 | 67 | # 'clen' ignores length of ansi color sequences. |
66 | 68 | lengths = [clen(e) for e in elts] |
67 | | - max_cols = max(1, console_width / (min(lengths) + padding)) |
| 69 | + max_cols = max(1, console_width // (min(lengths) + padding)) |
68 | 70 | max_cols = min(len(elts), max_cols) |
69 | 71 |
|
70 | 72 | # Range of column counts to try. If forced, use the supplied value. |
71 | | - col_range = [cols] if cols else xrange(1, max_cols + 1) |
| 73 | + col_range = [cols] if cols else range(1, max_cols + 1) |
72 | 74 |
|
73 | 75 | # Determine the most columns possible for the console width. |
74 | 76 | configs = [ColumnConfig(c) for c in col_range] |
75 | 77 | for i, length in enumerate(lengths): |
76 | 78 | for conf in configs: |
77 | 79 | if conf.valid: |
78 | | - col = i / ((len(elts) + conf.cols - 1) / conf.cols) |
| 80 | + col = i // ((len(elts) + conf.cols - 1) // conf.cols) |
79 | 81 | p = padding if col < (conf.cols - 1) else 0 |
80 | 82 |
|
81 | 83 | if conf.widths[col] < (length + p): |
@@ -107,7 +109,7 @@ def config_uniform_cols(elts, console_width, padding, cols=0): |
107 | 109 | # 'clen' ignores length of ansi color sequences. |
108 | 110 | max_len = max(clen(e) for e in elts) + padding |
109 | 111 | if cols == 0: |
110 | | - cols = max(1, console_width / max_len) |
| 112 | + cols = max(1, console_width // max_len) |
111 | 113 | cols = min(len(elts), cols) |
112 | 114 |
|
113 | 115 | config = ColumnConfig(cols) |
@@ -193,12 +195,12 @@ def colify(elts, **options): |
193 | 195 | raise ValueError("method must be one of: " + allowed_methods) |
194 | 196 |
|
195 | 197 | cols = config.cols |
196 | | - rows = (len(elts) + cols - 1) / cols |
| 198 | + rows = (len(elts) + cols - 1) // cols |
197 | 199 | rows_last_col = len(elts) % rows |
198 | 200 |
|
199 | | - for row in xrange(rows): |
| 201 | + for row in range(rows): |
200 | 202 | output.write(" " * indent) |
201 | | - for col in xrange(cols): |
| 203 | + for col in range(cols): |
202 | 204 | elt = col * rows + row |
203 | 205 | width = config.widths[col] + cextra(elts[elt]) |
204 | 206 | if col < cols - 1: |
@@ -233,7 +235,7 @@ def colify_table(table, **options): |
233 | 235 | columns = len(table[0]) |
234 | 236 |
|
235 | 237 | def transpose(): |
236 | | - for i in xrange(columns): |
| 238 | + for i in range(columns): |
237 | 239 | for row in table: |
238 | 240 | yield row[i] |
239 | 241 |
|
|
0 commit comments