[PATCH 32/47] Iterate over partitions using disk.partitions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Rather than calling disk.nextPartition() over and over, we can
get a hash table of all partitions on a disk via disk.partitions.
Iterate over the values() of this hash (the keys correspond to
the partition number).
---
 autopart.py             |   12 ++++++------
 bootloader.py           |    4 ++--
 fsset.py                |    2 +-
 iw/partition_gui.py     |   17 +++++------------
 partedUtils.py          |    8 ++++----
 partitions.py           |   11 +++--------
 textw/partition_text.py |    7 +------
 7 files changed, 22 insertions(+), 39 deletions(-)

diff --git a/autopart.py b/autopart.py
index a445f34..17a9748 100644
--- a/autopart.py
+++ b/autopart.py
@@ -114,7 +114,7 @@ def bootAlphaCheckRequirements(part):
 
     # The first free space should start at the begining of the drive
     # and span for a megabyte or more.
-    for free in disk.partitions.values():
+    for free in disk.partitions:
         if free.type & parted.PARTITION_FREESPACE:
             break
     if (not free or free.geometry.start != 1L or free.getSize(unit="MB") < 1):
@@ -149,7 +149,7 @@ def findFreespace(diskset):
     for drive in diskset.disks.keys():
         disk = diskset.disks[drive]
         free[drive] = []
-        for part in disk.partitions.values():
+        for part in disk.partitions:
             if part.type & parted.PARTITION_FREESPACE:
                 free[drive].append(part)
     return free
@@ -453,7 +453,7 @@ def fitSized(diskset, requests, primOnly = 0, newParts = None):
                     # now need to update freespace since adding extended
                     # took some space
                     found = 0
-                    for part in disk.partitions.values():
+                    for part in disk.partitions:
                         if part.type & parted.PARTITION_FREESPACE:
                             if part.geometry.start > freeStartSec and part.geometry.end <= freeEndSec:
                                 found = 1
@@ -883,7 +883,7 @@ def setPreexistParts(diskset, requests):
             lvmLog.info("pre-existing partition on non-native disk %s, ignoring" %(request.drive,))
             continue
         disk = diskset.disks[request.drive]
-        for part in disk.partitions.values():
+        for part in disk.partitions:
             if part.geometry.start == request.start and part.geometry.end == request.end:
                 if partedUtils.isEfiSystemPartition(part) and \
                         request.fstype.name == "vfat":
@@ -925,7 +925,7 @@ def setPreexistParts(diskset, requests):
 
 def deletePart(diskset, delete):
     disk = diskset.disks[delete.drive]
-    for part in disk.partitions.values():
+    for part in disk.partitions:
         if part.geometry.start == delete.start and part.geometry.end == delete.end:
             disk.deletePartition(part)
             return
@@ -1134,7 +1134,7 @@ def doClearPartAction(anaconda, partitions, diskset):
            drive in diskset.skippedDisks:
             continue
         disk = diskset.disks[drive]
-        for part in disk.partitions.values():
+        for part in disk.partitions:
             if (not part.active or (part.type == parted.PARTITION_EXTENDED) or
                (part.disk.type == "mac" and part.number == 1 and part.name == "Apple")):
                 continue
diff --git a/bootloader.py b/bootloader.py
index 39102fe..58d20b3 100644
--- a/bootloader.py
+++ b/bootloader.py
@@ -65,7 +65,7 @@ def bootloaderSetupChoices(anaconda):
         bootPart = None
         for drive in drives:
             disk = anaconda.id.diskset.disks[drive]
-            for part in disk.partitions.values():
+            for part in disk.partitions:
                 if part.active and partedUtils.isEfiSystemPartition(part):
                     bootPart = part.getDeviceNodeName()
                     break
@@ -84,7 +84,7 @@ def bootloaderSetupChoices(anaconda):
         bootPart = None
         for drive in drives:
             disk = anaconda.id.diskset.disks[drive]
-            for part in disk.partitions.values():
+            for part in disk.partitions:
                 if part.active and part.getFlag(parted.PARTITION_PREP):
                     bootPart = part.getDeviceNodeName()
                     break
diff --git a/fsset.py b/fsset.py
index 0af78d7..862ef24 100644
--- a/fsset.py
+++ b/fsset.py
@@ -1666,7 +1666,7 @@ MAILADDR root
             if partedUtils.hasGptLabel(diskset, drive):
                 continue
             disk = diskset.disks[drive]
-            for part in disk.partitions.values():
+            for part in disk.partitions:
                 if not part.active:
                     continue
 
diff --git a/iw/partition_gui.py b/iw/partition_gui.py
index 5517f57..c39bbb7 100644
--- a/iw/partition_gui.py
+++ b/iw/partition_gui.py
@@ -828,15 +828,12 @@ class PartitionWindow(InstallWindow):
             sectorsPerCyl = heads * sectors
 
             extendedParent = None
-            part = disk.next_partition()
-            while part:
+            for part in disk.partitions:
                 if part.type & parted.PARTITION_METADATA:
-                    part = disk.next_partition(part)
                     continue
                 # ignore the tiny < 1 MB partitions (#119479)
                 if part.getSize(unit="MB") <= 1.0:
                     if not part.is_active() or not part.getFlag(parted.PARTITION_BOOT):
-                        part = disk.next_partition(part)                    
                         continue
 
                 stripe.add(part)
@@ -858,7 +855,7 @@ class PartitionWindow(InstallWindow):
                 else:
                     iter = self.tree.append(parent)
                     self.tree[iter]['IsLeaf'] = True
-                    
+
                 if request and request.mountpoint:
                     self.tree[iter]['Mount Point'] = request.mountpoint
                 else:
@@ -871,7 +868,6 @@ class PartitionWindow(InstallWindow):
 			    self.tree[iter]['Mount Point'] = vgreq.volumeGroupName
 			else:
 			    self.tree.appendToHiddenPartitionsList(part)
-			    part = disk.next_partition(part)
 			    self.tree.remove(iter)
 			    continue
 		    else:
@@ -884,7 +880,7 @@ class PartitionWindow(InstallWindow):
 		
                 if request and request.fstype:
                     self.tree[iter]['IsFormattable'] = request.fstype.isFormattable()
-                
+
                 if part.type & parted.PARTITION_FREESPACE:
                     ptype = _("Free space")
                 elif part.type == parted.PARTITION_EXTENDED:
@@ -901,7 +897,6 @@ class PartitionWindow(InstallWindow):
 			    self.tree[iter]['Mount Point'] = mddevice
 			else:
 			    self.tree.appendToHiddenPartitionsList(part)
-			    part = disk.next_partition(part)
 			    self.tree.remove(iter)
 			    continue
 		    else:
@@ -924,7 +919,7 @@ class PartitionWindow(InstallWindow):
                 else:
                     if request and request.fstype != None:
                         ptype = self.getShortFSTypeName(request.fstype.getName())
-                        
+
                         if ptype == "foreign":
                             ptype = map_foreign_to_fsname(part)
                     else:
@@ -949,8 +944,6 @@ class PartitionWindow(InstallWindow):
                     sizestr = "%Ld" % (size)
                 self.tree[iter]['Size (MB)'] = sizestr
                 self.tree[iter]['PyObject'] = part
-                
-                part = disk.next_partition(part)
 
         canvas = self.diskStripeGraph.getCanvas()
         apply(canvas.set_scroll_region, canvas.root().get_bounds())
@@ -959,7 +952,7 @@ class PartitionWindow(InstallWindow):
     def treeActivateCb(self, view, path, col):
         if self.tree.getCurrentPartition():
             self.editCb()
-        
+
     def treeSelectCb(self, selection, *args):
         model, iter = selection.get_selected()
         if not iter:
diff --git a/partedUtils.py b/partedUtils.py
index 54abfa8..40c31ae 100644
--- a/partedUtils.py
+++ b/partedUtils.py
@@ -106,7 +106,7 @@ def map_foreign_to_fsname(part):
 
 def filter_partitions(disk, func):
     rc = []
-    for part in disk.partitions.values():
+    for part in disk.partitions:
         if func(part):
             rc.append(part)
     return rc
@@ -681,7 +681,7 @@ class DiskSet:
 
         for drive in drives:
             disk = self.disks[drive]
-            for part in disk.partitions.values():
+            for part in disk.partitions:
                 node = part.getDeviceNodeName()
                 crypto = self.anaconda.id.partitions.encryptedDevices.get(node)
                 if (part.active
@@ -1105,7 +1105,7 @@ class DiskSet:
 
         for drive in drives:
             disk = self.disks[drive]
-            for part in disk.partitions.values():
+            for part in disk.partitions:
                 if part.type in (parted.PARTITION_NORMAL,
                                  parted.PARTITION_LOGICAL):
                     device = part.getDeviceNodeName()
@@ -1128,7 +1128,7 @@ class DiskSet:
                         disk.device.length,
                         disk.maxPrimaryPartitionCount))
 
-            for part in disk.partitions.values():
+            for part in disk.partitions:
                 rc = rc + ("Device    Type         Filesystem   Start      "
                            "End        Length        Flags\n")
                 rc = rc + ("------    ----         ----------   -----      "
diff --git a/partitions.py b/partitions.py
index 650a3da..dd482e0 100644
--- a/partitions.py
+++ b/partitions.py
@@ -304,23 +304,18 @@ class Partitions:
                 continue
 
             disk = diskset.disks[drive]
-            part = disk.next_partition()
-            while part:
+            for part in disk.partitions:
                 if part.type & parted.PARTITION_METADATA:
-                    part = disk.next_partition(part)
                     continue
 
                 device = part.getDeviceNodeName()
                 fs = isys.readFSType("/dev/%s" % (device,))
                 if fs and fs.endswith("raid"):
-                    part = disk.next_partition(part)
                     continue
 
                 if cryptodev.isLuks("/dev/%s" % device):
                     self.getCryptoDev(device)
 
-                part = disk.next_partition(part)
-
         diskset.startMPath()
         diskset.startDmRaid()
         diskset.startMdRaid()
@@ -372,7 +367,7 @@ class Partitions:
         drives.sort()
         for drive in drives:
             disk = diskset.disks[drive]
-            for part in disk.partitions.values():
+            for part in disk.partitions:
                 if part.type & parted.PARTITION_METADATA:
                     continue
 
@@ -658,7 +653,7 @@ class Partitions:
 
         rc = []
         disk = diskset.disks[device]
-        for part in disk.partitions.values():
+        for part in disk.partitions:
             dev = part.getDeviceNodeName()
             request = self.getRequestByDeviceName(dev)
 
diff --git a/textw/partition_text.py b/textw/partition_text.py
index 997989e..f86a61e 100644
--- a/textw/partition_text.py
+++ b/textw/partition_text.py
@@ -138,16 +138,13 @@ class PartitionWindow:
             self.lb.append([devify(drive),"","","","",""], None)
 
             extendedParent = None
-            part = disk.next_partition()
-            while part:
+            for part in disk.partitions:
                 if part.type & parted.PARTITION_METADATA:
 #                    print("partition %s has type %d" %(part.getDeviceNodeName(), part.type))
-                    part = disk.next_partition(part)
                     continue
                 # ignore the tiny < 1 MB partitions (#119479)
                 if part.getSize(unit="MB") <= 1.0:
                     if not part.is_active() or not part.get_flag(parted.PARTITION_BOOT):
-                        part = disk.next_partition(part)                    
                         continue
 
                 device = part.getDeviceNodeName()
@@ -204,7 +201,6 @@ class PartitionWindow:
                                     "%s" %(ptype),
                                     ""], part,
                                    [LEFT, RIGHT, RIGHT, RIGHT, LEFT, LEFT])
-                                    
                 else:
                     dev = devify(part.getDeviceNodeName())
                     # save some space per #90838
@@ -219,7 +215,6 @@ class PartitionWindow:
                                     "%s" %(ptype),
                                     "%s" %(mount)], part,
                                    [LEFT, RIGHT, RIGHT, RIGHT, LEFT, LEFT])
-                part = disk.next_partition(part)
 
     def refresh(self):
         # XXX need some way to stay at the same place in the list after
-- 
1.6.1.3

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux