[blivet:master 02/17] Be less eager about processing all lines in /proc/meminfo.

mulhern amulhern at redhat.com
Tue Jan 6 20:38:04 UTC 2015


Don't read all the lines in the file and stop on first match of MemTotal.

Previous code assumed that there would be at least one match and that
doesn't seem to have failed ever, so my code assumes the same.

Signed-off-by: mulhern <amulhern at redhat.com>
---
 blivet/util.py | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/blivet/util.py b/blivet/util.py
index e3670a9..15b1daf 100644
--- a/blivet/util.py
+++ b/blivet/util.py
@@ -145,10 +145,9 @@ def total_memory():
     # import locally to avoid a cycle with size importing util
     from .size import Size
 
-    lines = open("/proc/meminfo").readlines()
-    for line in lines:
-        if line.startswith("MemTotal:"):
-            mem = Size("%s KiB" % line.split()[1])
+    with open("/proc/meminfo") as lines:
+        line = next(l for l in lines if l.startswith("MemTotal:"))
+        mem = Size("%s KiB" % line.split()[1])
 
     # Because /proc/meminfo only gives us the MemTotal (total physical RAM
     # minus the kernel binary code), we need to round this up. Assuming
-- 
1.9.3



More information about the anaconda-patches mailing list