Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/lib/output.py
diff options
context:
space:
mode:
authorDaniel Girtler <blackrabbit256@gmail.com>2022-05-27 05:48:29 +1000
committerGitHub <noreply@github.com>2022-05-26 21:48:29 +0200
commit870da403e79ab50350803b45f200e0b272334989 (patch)
tree9b203a054bd10cbc73a81b4fd5fe24ef8e6f141a /archinstall/lib/output.py
parent353c05318ce80b8eec32031c9e14b8471b458548 (diff)
Rework user management (#1220)
* Rework users * Update user installation * Fix config serialization * Update * Update schemas and documentation * Update * Fix flake8 * Make users mypy compatible * Fix minor copy Co-authored-by: Daniel Girtler <girtler.daniel@gmail.com> Co-authored-by: Anton Hvornum <anton@hvornum.se>
Diffstat (limited to 'archinstall/lib/output.py')
-rw-r--r--archinstall/lib/output.py38
1 files changed, 37 insertions, 1 deletions
diff --git a/archinstall/lib/output.py b/archinstall/lib/output.py
index 07747091..29b73bc4 100644
--- a/archinstall/lib/output.py
+++ b/archinstall/lib/output.py
@@ -2,11 +2,47 @@ import logging
import os
import sys
from pathlib import Path
-from typing import Dict, Union
+from typing import Dict, Union, List, Any
from .storage import storage
+class FormattedOutput:
+
+ @classmethod
+ def values(cls, o: Any) -> Dict[str, Any]:
+ if hasattr(o, 'json'):
+ return o.json()
+ else:
+ return o.__dict__
+
+ @classmethod
+ def as_table(cls, obj: List[Any]) -> str:
+ column_width: Dict[str, int] = {}
+ for o in obj:
+ for k, v in cls.values(o).items():
+ column_width.setdefault(k, 0)
+ column_width[k] = max([column_width[k], len(str(v)), len(k)])
+
+ output = ''
+ for key, width in column_width.items():
+ key = key.replace('!', '')
+ output += key.ljust(width) + ' | '
+
+ output = output[:-3] + '\n'
+ output += '-' * len(output) + '\n'
+
+ for o in obj:
+ for k, v in cls.values(o).items():
+ if '!' in k:
+ v = '*' * len(str(v))
+ output += str(v).ljust(column_width[k]) + ' | '
+ output = output[:-3]
+ output += '\n'
+
+ return output
+
+
class Journald:
@staticmethod
def log(message :str, level :int = logging.DEBUG) -> None: