[master 4/6] Use context manager when opening /proc/mounts.

mulkieran installerbot-noreply at redhat.com
Wed May 6 15:03:54 UTC 2015


From: mulhern <amulhern at redhat.com>

Signed-off-by: mulhern <amulhern at redhat.com>
---
 blivet/mounts.py | 30 ++++++++++++++++--------------
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/blivet/mounts.py b/blivet/mounts.py
index af45c7e..d1a4eb6 100644
--- a/blivet/mounts.py
+++ b/blivet/mounts.py
@@ -89,21 +89,23 @@ def _getActiveMounts(self):
             Refreshes self.mountpoints with current mountpoint information
         """
         self.mountpoints = defaultdict(list)
-        for line in open("/proc/mounts").readlines():
-            try:
-                (devspec, mountpoint, fstype, _rest) = line.split(None, 3)
-            except ValueError:
-                log.error("failed to parse /proc/mounts line: %s", line)
-                continue
-
-            if fstype == "btrfs":
-                subvolspec = self._getSubvolSpec(devspec, mountpoint)
-                if subvolspec is not None:
-                    self.mountpoints[(devspec, subvolspec)].append(mountpoint)
+
+        with open("/proc/mounts") as mounts:
+            for line in mounts:
+                try:
+                    (devspec, mountpoint, fstype, _rest) = line.split(None, 3)
+                except ValueError:
+                    log.error("failed to parse /proc/mounts line: %s", line)
+                    continue
+
+                if fstype == "btrfs":
+                    subvolspec = self._getSubvolSpec(devspec, mountpoint)
+                    if subvolspec is not None:
+                        self.mountpoints[(devspec, subvolspec)].append(mountpoint)
+                    else:
+                        log.error("failed to obtain subvolspec for btrfs device %s", devspec)
                 else:
-                    log.error("failed to obtain subvolspec for btrfs device %s", devspec)
-            else:
-                self.mountpoints[(devspec, None)].append(mountpoint)
+                    self.mountpoints[(devspec, None)].append(mountpoint)
 
     def _cacheCheck(self):
         """ Computes the MD5 hash on /proc/mounts and updates the cache on change


-- 
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/704e1d5260d4ba9ee48e532799457402b7c9ab9f


More information about the anaconda-patches mailing list