[blivet][master/rhel7-branch][PATCH 1/3] Remove DeviceTree.getDevicesByInstance. (#1155984)

Samantha N. Bueno sbueno+anaconda at redhat.com
Thu Jun 4 16:04:23 UTC 2015


The only thing you get for using this method is the extra overhead of
us logging the return value. Your code doesn't get any smaller or simpler.

Patch originally by Dave Lehman <dlehman at redhat.com>

Resolves: rhbz#1155984
---
 blivet/__init__.py   |  7 +++----
 blivet/devicetree.py | 18 ++----------------
 2 files changed, 5 insertions(+), 20 deletions(-)

diff --git a/blivet/__init__.py b/blivet/__init__.py
index 3b28ad9..83a65bc 100644
--- a/blivet/__init__.py
+++ b/blivet/__init__.py
@@ -586,9 +586,8 @@ class Blivet(object):
             does not necessarily reflect the actual on-disk state of the
             system's disks.
         """
-        partitions = self.devicetree.getDevicesByInstance(PartitionDevice)
-        partitions.sort(key=lambda d: d.name)
-        return partitions
+        partitions = (d for d in self.devices if isinstance(d, PartitionDevice))
+        return sorted(partitions, key=lambda d: d.name)
 
     @property
     def vgs(self):
@@ -2787,7 +2786,7 @@ class FSSet(object):
         else:
             devices += self.swapDevices
 
-        netdevs = self.devicetree.getDevicesByInstance(NetworkStorageDevice)
+        netdevs = [d for d in self.devices if isinstance(d, NetworkStorageDevice)]
         for device in devices:
             # why the hell do we put swap in the fstab, anyway?
             if not device.format.mountable and device.format.type != "swap":
diff --git a/blivet/devicetree.py b/blivet/devicetree.py
index 9f1aa9e..b6f94a4 100644
--- a/blivet/devicetree.py
+++ b/blivet/devicetree.py
@@ -317,7 +317,8 @@ class DeviceTree(object):
 
         # now we have to update the parted partitions of all devices so they
         # match the parted disks we just updated
-        for partition in self.getDevicesByInstance(PartitionDevice):
+        partitions = (d for d in self.devices if isinstance(d, PartitionDevice))
+        for partition in partitions:
             pdisk = partition.disk.format.partedDisk
             partition.partedPartition = pdisk.getPartitionByPath(partition.path)
 
@@ -2382,21 +2383,6 @@ class DeviceTree(object):
         log_method_return(self, [r.name for r in result])
         return result
 
-    def getDevicesByInstance(self, device_class, incomplete=False, hidden=False):
-        """ Return a list of devices with a matching device class.
-
-            :param class device_class: the device class to match
-            :param bool incomplete: include incomplete devices in search
-            :param bool hidden: include hidden devices in search
-            :returns: all matching device found
-            :rtype: list of :class:`~.devices.Device`
-        """
-        log_method_call(self, device_class=device_class, incomplete=incomplete, hidden=hidden)
-        devices = self._filterDevices(incomplete=incomplete, hidden=hidden)
-        result = [d for d in devices if isinstance(d, device_class)]
-        log_method_return(self, [r.name for r in result])
-        return result
-
     def getDeviceByID(self, id_num, incomplete=False, hidden=False):
         """ Return a device with specified device id.
 
-- 
1.9.3



More information about the anaconda-patches mailing list