aboutsummaryrefslogtreecommitdiffstats
path: root/python/refcat/cli.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/refcat/cli.py')
-rw-r--r--python/refcat/cli.py29
1 files changed, 28 insertions, 1 deletions
diff --git a/python/refcat/cli.py b/python/refcat/cli.py
index a490553..6bb3073 100644
--- a/python/refcat/cli.py
+++ b/python/refcat/cli.py
@@ -18,6 +18,7 @@ To install completion run:
$ source <(refcat.pyz completion)
"""
+import io
import logging
import os
import subprocess
@@ -32,9 +33,9 @@ from luigi.task_register import TaskClassNotFoundException
from refcat import __version__
from refcat.deps import dump_deps, dump_deps_dot
+from refcat.report import *
from refcat.settings import LOGGING_CONF_FILE, settings
from refcat.tasks import *
-from refcat.techreport import *
from refcat.utils import columnize
# These are utility classes of luigi.
@@ -58,6 +59,32 @@ suppress_task_names = [
]
+def columnize(lines, term_width=80, indent=0, pad=2):
+ n_lines = len(lines)
+ if n_lines == 0:
+ return
+
+ col_width = max(len(line) for line in lines)
+ n_cols = int((term_width + pad - indent) / (col_width + pad))
+ n_cols = min(n_lines, max(1, n_cols))
+
+ col_len = int(n_lines / n_cols) + (0 if n_lines % n_cols == 0 else 1)
+ if (n_cols - 1) * col_len >= n_lines:
+ n_cols -= 1
+
+ cols = [lines[i * col_len:i * col_len + col_len] for i in range(n_cols)]
+
+ rows = list(zip(*cols))
+ rows_missed = zip(*[col[len(rows):] for col in cols[:-1]])
+ rows.extend(rows_missed)
+
+ sio = io.StringIO()
+ for row in rows:
+ sio.write(" " * indent + (" " * pad).join(line.ljust(col_width) for line in row) + "\n")
+
+ return sio.getvalue()
+
+
def effective_task_names():
"""
Runnable, relevant task names.