[PATCH 35/47] Iterate over partitions to see free space.

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

 



Use the getFirstPartition() and nextPartition() method to
iterate over partitions so we can see the free space as
represented by libparted.
---
 autopart.py             |   22 ++++++++++------------
 iw/partition_gui.py     |    8 +++++++-
 partitions.py           |    6 +++++-
 textw/partition_text.py |    7 ++++++-
 4 files changed, 28 insertions(+), 15 deletions(-)

diff --git a/autopart.py b/autopart.py
index 17a9748..6b5f887 100644
--- a/autopart.py
+++ b/autopart.py
@@ -114,9 +114,11 @@ 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:
+    free = disk.getFirstPartition()
+    while free:
         if free.type & parted.PARTITION_FREESPACE:
             break
+        free = free.nextPartition()
     if (not free or free.geometry.start != 1L or free.getSize(unit="MB") < 1):
         return BOOTALPHA_NO_RESERVED_SPACE
 
@@ -148,10 +150,7 @@ def findFreespace(diskset):
     free = {}
     for drive in diskset.disks.keys():
         disk = diskset.disks[drive]
-        free[drive] = []
-        for part in disk.partitions:
-            if part.type & parted.PARTITION_FREESPACE:
-                free[drive].append(part)
+        free[drive] = disk.getFreeSpacePartitions()
     return free
 
 
@@ -453,13 +452,12 @@ 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:
-                        if part.type & parted.PARTITION_FREESPACE:
-                            if part.geometry.start > freeStartSec and part.geometry.end <= freeEndSec:
-                                found = 1
-                                freeStartSec = part.geometry.start
-                                freeEndSec = part.geometry.end
-                                break
+                    for part in disk.getFreeSpacePartitions():
+                        if part.geometry.start > freeStartSec and part.geometry.end <= freeEndSec:
+                            found = 1
+                            freeStartSec = part.geometry.start
+                            freeEndSec = part.geometry.end
+                            break
 
                     if not found:
                         raise PartitioningError, "Could not find free space after making new extended partition"
diff --git a/iw/partition_gui.py b/iw/partition_gui.py
index abb2845..79555be 100644
--- a/iw/partition_gui.py
+++ b/iw/partition_gui.py
@@ -828,12 +828,15 @@ class PartitionWindow(InstallWindow):
             sectorsPerCyl = heads * sectors
 
             extendedParent = None
-            for part in disk.partitions:
+            part = disk.getFirstPartition()
+            while part:
                 if part.type & parted.PARTITION_METADATA:
+                    part = part.nextPartition()
                     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 = part.nextPartition()
                         continue
 
                 stripe.add(part)
@@ -898,6 +901,7 @@ class PartitionWindow(InstallWindow):
 			else:
 			    self.tree.appendToHiddenPartitionsList(part)
 			    self.tree.remove(iter)
+			    part = part.nextPartition()
 			    continue
 		    else:
 			self.tree[iter]['Mount Point'] = ""
@@ -945,6 +949,8 @@ class PartitionWindow(InstallWindow):
                 self.tree[iter]['Size (MB)'] = sizestr
                 self.tree[iter]['PyObject'] = part
 
+                part = part.nextPartition()
+
         canvas = self.diskStripeGraph.getCanvas()
         apply(canvas.set_scroll_region, canvas.root().get_bounds())
         self.treeView.expand_all()
diff --git a/partitions.py b/partitions.py
index dd482e0..53c1480 100644
--- a/partitions.py
+++ b/partitions.py
@@ -367,8 +367,10 @@ class Partitions:
         drives.sort()
         for drive in drives:
             disk = diskset.disks[drive]
-            for part in disk.partitions:
+            part = disk.getFirstPartition()
+            while part:
                 if part.type & parted.PARTITION_METADATA:
+                    part = part.nextPartition()
                     continue
 
                 format = None
@@ -435,6 +437,8 @@ class Partitions:
                             spec.fslabel = labels[mappedDev]
                 self.addRequest(spec)
 
+                part = part.nextPartition()
+
         # now we need to read in all pre-existing RAID stuff
         diskset.startMPath()
         diskset.startDmRaid()
diff --git a/textw/partition_text.py b/textw/partition_text.py
index f86a61e..c67399e 100644
--- a/textw/partition_text.py
+++ b/textw/partition_text.py
@@ -138,13 +138,16 @@ class PartitionWindow:
             self.lb.append([devify(drive),"","","","",""], None)
 
             extendedParent = None
-            for part in disk.partitions:
+            part = disk.getFirstPartition()
+            while part:
                 if part.type & parted.PARTITION_METADATA:
 #                    print("partition %s has type %d" %(part.getDeviceNodeName(), part.type))
+                    part = part.nextPartition()
                     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 = part.nextPartition()
                         continue
 
                 device = part.getDeviceNodeName()
@@ -216,6 +219,8 @@ class PartitionWindow:
                                     "%s" %(mount)], part,
                                    [LEFT, RIGHT, RIGHT, RIGHT, LEFT, LEFT])
 
+                part = part.nextPartition()
+
     def refresh(self):
         # XXX need some way to stay at the same place in the list after
         # repopulating
-- 
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