aboutsummaryrefslogtreecommitdiff
path: root/src/ee/_utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/ee/_utils.py')
-rw-r--r--src/ee/_utils.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/ee/_utils.py b/src/ee/_utils.py
index 08e75fa..5960161 100644
--- a/src/ee/_utils.py
+++ b/src/ee/_utils.py
@@ -77,3 +77,24 @@ class EmptyHttpCache(object):
def maybe_cache(path: Optional[Path], **kwargs) -> HttpCache:
return HttpCache(path, **kwargs) if path is not None else EmptyHttpCache()
+
+
+def gen_rst_table(header: List[str], data: List[List[str]]):
+ column_widths = []
+ for i in range(len(header)):
+ w = len(header[i])
+ for row in data:
+ w = max(w, len(row[i]))
+ column_widths.append(w)
+
+ import io
+ buf = io.StringIO()
+ sep = "+-" + "-+-".join(["-" * w for i, w in enumerate(column_widths)]) + "-+"
+ print(sep, file=buf)
+ print("| " + " | ".join([header[i].ljust(w) for i, w in enumerate(column_widths)]) + " |", file=buf)
+ print(sep.replace("-", "="), file=buf)
+ for row in data:
+ print("| " + " | ".join([row[i].ljust(w) for i, w in enumerate(column_widths)]) + " |", file=buf)
+ print(sep, file=buf)
+
+ return buf.getvalue()