From 93cb77d0a50252e53371bdaf63d03916f8bad5d8 Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Fri, 13 May 2016 04:30:56 +0200 Subject: [PATCH] [mod] try to improve lisibility a bit --- src/yunohost/monitor.py | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/yunohost/monitor.py b/src/yunohost/monitor.py index af67d1409..1ff69b9b2 100644 --- a/src/yunohost/monitor.py +++ b/src/yunohost/monitor.py @@ -717,22 +717,26 @@ def _append_to_stats(stats, monitor, statics=[]): statics = [statics] # Appending function - def _append(s, m, st): - for k, v in m.items(): - if k in st: - s[k] = v - elif isinstance(v, dict): - if k not in s: - s[k] = {} - s[k] = _append(s[k], v, st) + def _append(_stats, _monitor, _statics): + for key, value in _monitor.items(): + if key in _statics: + _stats[key] = value + + elif isinstance(value, dict): + if key not in _stats: + _stats[key] = {} + _stats[key] = _append(_stats[key], value, _statics) + else: - if k not in s: - s[k] = [] - if isinstance(v, list): - s[k].extend(v) + if key not in _stats: + _stats[key] = [] + + if isinstance(value, list): + _stats[key].extend(value) else: - s[k].append(v) - return s + _stats[key].append(value) + + return _stats stats = _append(stats, monitor, statics) return stats