diff --git a/bumblebee_status/modules/core/memory.py b/bumblebee_status/modules/core/memory.py index 82de769..9b4a3ab 100644 --- a/bumblebee_status/modules/core/memory.py +++ b/bumblebee_status/modules/core/memory.py @@ -41,18 +41,8 @@ class Module(core.module.Module): return self._format.format(**self._mem) def update(self): - data = {} - with open("/proc/meminfo", "r") as f: - for line in f: - tmp = re.split(r"[:\s]+", line) - value = int(tmp[1]) - if tmp[2] == "kB": - value = value * 1024 - if tmp[2] == "mB": - value = value * 1024 * 1024 - if tmp[2] == "gB": - value = value * 1024 * 1024 * 1024 - data[tmp[0]] = value + data = self.__parse_meminfo() + if "MemAvailable" in data: used = data["MemTotal"] - data["MemAvailable"] else: @@ -78,5 +68,26 @@ class Module(core.module.Module): return "warning" return None + def __parse_meminfo(self): + data = {} + with open("/proc/meminfo", "r") as f: + # https://bugs.python.org/issue32933 + while True: + line = f.readline() + + if line == '': + break + + tmp = re.split(r"[:\s]+", line) + value = int(tmp[1]) + if tmp[2] == "kB": + value = value * 1024 + if tmp[2] == "mB": + value = value * 1024 * 1024 + if tmp[2] == "gB": + value = value * 1024 * 1024 * 1024 + data[tmp[0]] = value + + return data # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/tests/modules/core/test_memory.py b/tests/modules/core/test_memory.py index b133c52..9f52032 100644 --- a/tests/modules/core/test_memory.py +++ b/tests/modules/core/test_memory.py @@ -30,7 +30,6 @@ def meminfo_mock( ('Slab', slab) ] - for i, (key, value) in enumerate(states): data.append('{}: {} kB'.format(key, value))