diff options
author | Jonah BrĂ¼chert <jbb@kaidan.im> | 2024-04-16 18:38:52 +0200 |
---|---|---|
committer | Jonah BrĂ¼chert <jbb@kaidan.im> | 2024-04-16 18:41:56 +0200 |
commit | 9f6e876e14a074c386660c582c7f78e1503877aa (patch) | |
tree | affbde24ebd185674909fd6f727a20d87155b8ec /hostinfo/printer.py | |
parent | 18425d3ee02f75f5275b394205abcb5a4ce995bf (diff) | |
download | tools-9f6e876e14a074c386660c582c7f78e1503877aa.tar.gz tools-9f6e876e14a074c386660c582c7f78e1503877aa.tar.bz2 tools-9f6e876e14a074c386660c582c7f78e1503877aa.zip |
Diffstat (limited to 'hostinfo/printer.py')
-rw-r--r-- | hostinfo/printer.py | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/hostinfo/printer.py b/hostinfo/printer.py index 16c0249..4054df2 100644 --- a/hostinfo/printer.py +++ b/hostinfo/printer.py @@ -4,7 +4,7 @@ from hostinfo import prefix from hostinfo import utils -from typing import Iterable, Optional +from typing import Iterable, Optional, Any, Union def _get_full_key(prev_key, key): @@ -14,13 +14,13 @@ def _get_full_key(prev_key, key): def _sort_with_list(iterable: Iterable, sort: list[str]): - def helper(value): + def helper(value) -> str: if sort is None: return value (key, _) = value if key in sort: - return sort.index(key) + return str(sort.index(key)) return "%d %s" % (len(sort), key) return sorted(iterable, key=helper) @@ -60,15 +60,13 @@ class Printer: return True return False - def _print(self, valuestr: str, printer: prefix.Printer, + def _print(self, value: Union[str, dict[str, Any], list[str]], + printer: prefix.Printer, filter_key: Optional[str] = None, sort=None, force=False): - try: - value = valuestr.strip().splitlines() - except AttributeError: - pass - - if isinstance(value, dict): + if isinstance(value, str): + self._print_list(value.strip().splitlines(), printer, filter_key) + elif isinstance(value, dict): self._print_dict(value, printer, filter_key, sort, force) elif isinstance(value, list): self._print_list(value, printer, filter_key) |