summaryrefslogtreecommitdiffstats
path: root/bin/hostinfo
diff options
context:
space:
mode:
Diffstat (limited to 'bin/hostinfo')
-rwxr-xr-xbin/hostinfo12
1 files changed, 5 insertions, 7 deletions
diff --git a/bin/hostinfo b/bin/hostinfo
index 2270208..ced856a 100755
--- a/bin/hostinfo
+++ b/bin/hostinfo
@@ -13,6 +13,7 @@ if os.path.exists(os.path.join(LIB, 'hostinfo')):
sys.path = [LIB] + sys.path
from hostinfo import printer
+from hostinfo import utils
def _get_data(path):
stream = file(path, 'r')
@@ -29,10 +30,10 @@ def match_key(data, keys):
rest = keys[1:]
if key == 'addresses' and 'addresses' in data:
- return match_key({a['interface']: a for a in data}, rest)
+ return match_key(utils.group_by(data['addresses'], 'interface'), rest)
if key == 'ports' and 'ports' in data:
- return match_key({p['process']: p for p in data}, rest)
+ return match_key(utils.group_by(data['ports'], 'process', 'UNKNOWN'), rest)
if isinstance(data, dict):
if key in data:
@@ -117,14 +118,11 @@ def print_keys(path):
print "%s%s" % (prefix, key)
if key == 'addresses':
- for k in set([a['interface'] for a in data[key]]):
+ for k in utils.group_by(data[key], 'interface').keys():
print "%s%s.%s" % (prefix, key, k)
elif key == 'ports':
- names = [p['process'] for p in data[key] if 'process' in p]
- for k in set(names):
+ for k in utils.group_by(data[key], 'process', 'UNKNOWN').keys():
print "%s%s.%s" % (prefix, key, k)
- if len([p for p in data[key] if 'process' not in p]) > 0:
- print "%s%s.%s" % (prefix, key, 'UNKNOWN')
elif isinstance(data[key], dict):
_print_keys(data[key], "%s%s." % (prefix, key))
elif isinstance(data[key], list):