From 44fa8e5ca2f540699af68dfea04d322501067ac4 Mon Sep 17 00:00:00 2001
From: David Lehman <dlehman@redhat.com>
Date: Tue, 22 Jan 2013 13:21:44 -0600
Subject: [PATCH 11/11] Move pyanaconda.packaging.get_mount_* into
 blivet.util.

---
 pyanaconda/packaging/__init__.py   |   46 +----------------------------------
 pyanaconda/packaging/yumpayload.py |   17 +++++++------
 pyanaconda/ui/gui/spokes/source.py |    4 ++-
 3 files changed, 14 insertions(+), 53 deletions(-)

diff --git a/pyanaconda/packaging/__init__.py b/pyanaconda/packaging/__init__.py
index 1cc9e7f..1da8908 100644
--- a/pyanaconda/packaging/__init__.py
+++ b/pyanaconda/packaging/__init__.py
@@ -98,48 +98,6 @@ class DependencyError(PayloadError):
 class PayloadInstallError(PayloadError):
     pass
 
-def get_mount_paths(dev):
-    mounts = open("/proc/mounts").readlines()
-    mount_paths = []
-    for mount in mounts:
-        try:
-            (device, path, rest) = mount.split(None, 2)
-        except ValueError:
-            continue
-
-        if dev == device:
-            mount_paths.append(path)
-
-    if mount_paths:
-        log.debug("%s is mounted on %s" % (dev, ', '.join(mount_paths)))
-    return mount_paths
-
-def get_mount_device(mountpoint):
-    import re
-    mounts = open("/proc/mounts").readlines()
-    mount_device = None
-    for mount in mounts:
-        try:
-            (device, path, rest) = mount.split(None, 2)
-        except ValueError:
-            continue
-
-        if path == mountpoint:
-            mount_device = device
-            break
-
-    if mount_device and re.match(r'/dev/loop\d+$', mount_device):
-        from blivet.devicelibs import loop
-        loop_name = os.path.basename(mount_device)
-        mount_device = loop.get_backing_file(loop_name)
-        log.debug("found backing file %s for loop device %s" % (mount_device,
-                                                                loop_name))
-
-    if mount_device:
-        log.debug("%s is mounted on %s" % (mount_device, mountpoint))
-
-    return mount_device
-
 class Payload(object):
     """ Payload is an abstract class for OS install delivery methods. """
     def __init__(self, data):
@@ -476,7 +434,7 @@ class Payload(object):
         realMountpoint = os.path.realpath(mountpoint)
 
         if os.path.ismount(realMountpoint):
-            mdev = get_mount_device(realMountpoint)
+            mdev = blivet.util.get_mount_device(realMountpoint)
             if mdev:
                 log.warning("%s is already mounted on %s" % (mdev, mountpoint))
 
@@ -501,7 +459,7 @@ class Payload(object):
         """ Prepare an NFS directory for use as a package source. """
         log.info("mounting %s:%s:%s on %s" % (server, path, options, mountpoint))
         if os.path.ismount(mountpoint):
-            dev = get_mount_device(mountpoint)
+            dev = blivet.util.get_mount_device(mountpoint)
             _server, colon, _path = dev.partition(":")
             if colon == ":" and server == _server and path == _path:
                 log.debug("%s:%s already mounted on %s" % (server, path,
diff --git a/pyanaconda/packaging/yumpayload.py b/pyanaconda/packaging/yumpayload.py
index 83461b1..9fe60ad 100644
--- a/pyanaconda/packaging/yumpayload.py
+++ b/pyanaconda/packaging/yumpayload.py
@@ -134,14 +134,14 @@ class YumPayload(PackagePayload):
         # nfsiso: umount INSTALL_TREE, umount ISO_DIR
         if os.path.ismount(INSTALL_TREE) and not flags.testing:
             if self.install_device and \
-               get_mount_device(INSTALL_TREE) == self.install_device.path:
+               blivet.util.get_mount_device(INSTALL_TREE) == self.install_device.path:
                 self.install_device.teardown(recursive=True)
             else:
                 blivet.util.umount(INSTALL_TREE)
 
         if os.path.ismount(ISO_DIR) and not flags.testing:
             if self.install_device and \
-               get_mount_device(ISO_DIR) == self.install_device.path:
+               blivet.util.get_mount_device(ISO_DIR) == self.install_device.path:
                 self.install_device.teardown(recursive=True)
             # The below code will fail when nfsiso is the stage2 source
             # But if we don't do this we may not be able to switch from
@@ -509,10 +509,10 @@ reposdir=%s
             return None
         # This could either be mounted to INSTALL_TREE or on
         # DRACUT_ISODIR if dracut did the mount.
-        dev = get_mount_device(INSTALL_TREE)
+        dev = blivet.util.get_mount_device(INSTALL_TREE)
         if dev:
             return dev[len(ISO_DIR)+1:]
-        dev = get_mount_device(DRACUT_ISODIR)
+        dev = blivet.util.get_mount_device(DRACUT_ISODIR)
         if dev:
             return dev[len(DRACUT_ISODIR)+1:]
         return None
@@ -553,7 +553,8 @@ reposdir=%s
                     method.dir = method.dir[1:]
         # Check to see if the device is already mounted, in which case
         # we don't need to mount it again
-        elif method.method == "cdrom" and get_mount_paths(device.path):
+        elif method.method == "cdrom" and \
+             blivet.util.get_mount_paths(device.path):
                 return
         else:
             device.format.setup(mountpoint=INSTALL_TREE)
@@ -580,8 +581,8 @@ reposdir=%s
         mirrorlist = None
 
         # See if we already have stuff mounted due to dracut
-        isodev = get_mount_device(DRACUT_ISODIR)
-        device = get_mount_device(DRACUT_REPODIR)
+        isodev = blivet.util.get_mount_device(DRACUT_ISODIR)
+        device = blivet.util.get_mount_device(DRACUT_REPODIR)
 
         if method.method == "harddrive":
             if method.biospart:
@@ -662,7 +663,7 @@ reposdir=%s
             sslverify = not (method.noverifyssl or flags.noverifyssl)
         elif method.method == "cdrom" or (checkmount and not method.method):
             # Did dracut leave the DVD or NFS mounted for us?
-            device = get_mount_device(DRACUT_REPODIR)
+            device = blivet.util.get_mount_device(DRACUT_REPODIR)
             # Only look at the dracut mount if we don't already have a cdrom
             if device and not self.install_device:
                 self.install_device = storage.devicetree.getDeviceByPath(device)
diff --git a/pyanaconda/ui/gui/spokes/source.py b/pyanaconda/ui/gui/spokes/source.py
index 7faf0bc..ed6cc1d 100644
--- a/pyanaconda/ui/gui/spokes/source.py
+++ b/pyanaconda/ui/gui/spokes/source.py
@@ -42,9 +42,11 @@ from pyanaconda.ui.gui.utils import enlightbox, gtk_thread_wait
 from pyanaconda.iutil import ProxyString, ProxyStringError
 from pyanaconda.ui.gui.utils import gtk_call_once
 from pyanaconda.threads import threadMgr, AnacondaThread
-from pyanaconda.packaging import PayloadError, get_mount_paths, MetadataError
+from pyanaconda.packaging import PayloadError, MetadataError
 from pyanaconda.constants import DRACUT_ISODIR, ISO_DIR
 
+from blivet.util import get_mount_paths
+
 __all__ = ["SourceSpoke"]
 
 BASEREPO_SETUP_MESSAGE = N_("Setting up installation source...")
-- 
1.7.6.5

