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:
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: