summaryrefslogtreecommitdiffstats
path: root/glances/globals.py
diff options
context:
space:
mode:
Diffstat (limited to 'glances/globals.py')
-rw-r--r--glances/globals.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/glances/globals.py b/glances/globals.py
index e4e42ec8..a88af241 100644
--- a/glances/globals.py
+++ b/glances/globals.py
@@ -426,3 +426,13 @@ def weak_lru_cache(maxsize=128, typed=False):
return inner
return wrapper
+
+
+def namedtuple_to_dict(data):
+ """Convert a namedtuple to a dict, using the _asdict() method embeded in PsUtil stats."""
+ return {k: (v._asdict() if hasattr(v, '_asdict') else v) for k, v in data.items()}
+
+
+def list_of_namedtuple_to_list_of_dict(data):
+ """Convert a list of namedtuples to a dict, using the _asdict() method embeded in PsUtil stats."""
+ return [namedtuple_to_dict(d) for d in data]