summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonah BrĂ¼chert <jbb@kaidan.im>2024-04-16 18:38:52 +0200
committerJonah BrĂ¼chert <jbb@kaidan.im>2024-04-16 18:41:56 +0200
commit9f6e876e14a074c386660c582c7f78e1503877aa (patch)
treeaffbde24ebd185674909fd6f727a20d87155b8ec
parent18425d3ee02f75f5275b394205abcb5a4ce995bf (diff)
downloadtools-master.tar.gz
tools-master.tar.bz2
tools-master.zip
More python 3 adaptionHEADmaster
-rwxr-xr-xbin/hostinfo4
-rw-r--r--hostinfo/printer.py18
2 files changed, 10 insertions, 12 deletions
diff --git a/bin/hostinfo b/bin/hostinfo
index b85ccc8..639102c 100755
--- a/bin/hostinfo
+++ b/bin/hostinfo
@@ -20,8 +20,8 @@ from hostinfo import utils
def _get_data(path):
- stream = file(path, 'r')
- return yaml.load(stream)
+ stream = open(path, 'r')
+ return yaml.safe_load(stream)
def _match_key(data, keys):
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)