From 7e24733383d80b31d062aaab492938f4325d1401 Mon Sep 17 00:00:00 2001 From: David Lehman Date: Wed, 15 Jul 2009 12:08:11 -0500 Subject: Change DeviceTree.devices from a dict to a list. --- storage/__init__.py | 25 +++++++++++-------------- storage/devicetree.py | 35 ++++++++++++++++++++++++++--------- storage/partitioning.py | 2 +- 3 files changed, 38 insertions(+), 24 deletions(-) (limited to 'storage') diff --git a/storage/__init__.py b/storage/__init__.py index 8d4636778..66e390d2e 100644 --- a/storage/__init__.py +++ b/storage/__init__.py @@ -297,7 +297,7 @@ class Storage(object): @property def devices(self): """ A list of all the devices in the device tree. """ - devices = self.devicetree.devices.values() + devices = self.devicetree.devices devices.sort(key=lambda d: d.path) return devices @@ -312,10 +312,9 @@ class Storage(object): system's disks. """ disks = [] - devices = self.devicetree.devices - for d in devices: - if isinstance(devices[d], DiskDevice) and devices[d].mediaPresent: - disks.append(devices[d]) + for device in self.devicetree.devices: + if isinstance(device, DiskDevice) and device.mediaPresent: + disks.append(device) disks.sort(key=lambda d: d.name) return disks @@ -363,7 +362,7 @@ class Storage(object): does not necessarily reflect the actual on-disk state of the system's disks. """ - devices = self.devicetree.devices.values() + devices = self.devicetree.devices pvs = [d for d in devices if d.format.type == "lvmpv"] pvs.sort(key=lambda d: d.name) return pvs @@ -402,7 +401,7 @@ class Storage(object): does not necessarily reflect the actual on-disk state of the system's disks. """ - devices = self.devicetree.devices.values() + devices = self.devicetree.devices members = [d for d in devices if d.format.type == "mdmember"] members.sort(key=lambda d: d.name) return members @@ -438,14 +437,14 @@ class Storage(object): does not necessarily reflect the actual on-disk state of the system's disks. """ - devices = self.devicetree.devices.values() + devices = self.devicetree.devices swaps = [d for d in devices if d.format.type == "swap"] swaps.sort(key=lambda d: d.name) return swaps @property def protectedDevices(self): - devices = self.devicetree.devices.values() + devices = self.devicetree.devices protected = [d for d in devices if d.protected] protected.sort(key=lambda d: d.name) return protected @@ -1200,7 +1199,7 @@ class CryptTab(object): def populate(self): """ Populate the instance based on the device tree's contents. """ - for device in self.devicetree.devices.values(): + for device in self.devicetree.devices: # XXX should we put them all in there or just the ones that # are part of a device containing swap or a filesystem? # @@ -1321,9 +1320,7 @@ class FSSet(object): @property def devices(self): - devices = self.devicetree.devices.values() - devices.sort(key=lambda d: d.path) - return devices + return sorted(self.devicetree.devices, key=lambda d: d.path) @property def mountpoints(self): @@ -1487,7 +1484,7 @@ class FSSet(object): if not device: continue - if device not in self.devicetree.devices.values(): + if device not in self.devicetree.devices: self.devicetree._addDevice(device) def fsFreeSpace(self, chroot='/'): diff --git a/storage/devicetree.py b/storage/devicetree.py index 0bd3f5d99..5a4a10514 100644 --- a/storage/devicetree.py +++ b/storage/devicetree.py @@ -684,7 +684,7 @@ class DeviceTree(object): log.debug("action: %s" % action) log.debug("resetting parted disks...") - for device in self.devices.itervalues(): + for device in self.devices: if isinstance(device, DiskDevice): device.resetPartedDisk() @@ -864,7 +864,7 @@ class DeviceTree(object): if part.partType and part.isLogical and part.disk == dep.disk: logicals.append(part) - for device in self.devices.values(): + for device in self.devices: if device.dependsOn(dep): dependents.append(device) else: @@ -928,7 +928,7 @@ class DeviceTree(object): sysfs_path = udev_device_get_sysfs_path(info) device = None - for dmdev in self.devices.values(): + for dmdev in self.devices: if not isinstance(dmdev, DMDevice): continue @@ -1830,6 +1830,24 @@ class DeviceTree(object): log.debug("found %s" % found) return found + def getDeviceByPath(self, path): + log.debug("looking for device '%s'..." % path) + if not path: + return None + + found = None + for device in self._devices: + if device.path == path: + found = device + break + elif (device.type == "lvmlv" or device.type == "lvmvg") and \ + device.path == path.replace("--","-"): + found = device + break + + log.debug("found %s" % found) + return found + def getDevicesByType(self, device_type): # TODO: expand this to catch device format types return [d for d in self._devices if d.type == device_type] @@ -1839,14 +1857,13 @@ class DeviceTree(object): @property def devices(self): - """ Dict with device path keys and Device values. """ - devices = {} - + """ List of device instances """ + devices = [] for device in self._devices: - if device.path in devices: + if device.path in [d.path for d in devices]: raise DeviceTreeError("duplicate paths in device tree") - devices[device.path] = device + devices.append(device) return devices @@ -1924,7 +1941,7 @@ class DeviceTree(object): log.error("failed to resolve device %s" % devspec) elif devspec.startswith("/dev/"): # device path - device = self.devices.get(devspec) + device = self.getDeviceByPath(devspec) if device is None: if blkidTab: # try to use the blkid.tab to correlate the device diff --git a/storage/partitioning.py b/storage/partitioning.py index 101ff192d..7e7a5cf6d 100644 --- a/storage/partitioning.py +++ b/storage/partitioning.py @@ -162,7 +162,7 @@ def doAutoPartition(anaconda): log.debug("clearPartDisks: %s" % anaconda.id.storage.clearPartDisks) log.debug("autoPartitionRequests: %s" % anaconda.id.storage.autoPartitionRequests) log.debug("storage.disks: %s" % anaconda.id.storage.disks) - log.debug("all names: %s" % [d.name for d in anaconda.id.storage.devicetree.devices.values()]) + log.debug("all names: %s" % [d.name for d in anaconda.id.storage.devices]) if anaconda.dir == DISPATCH_BACK: anaconda.id.storage.reset() return -- cgit