[PATCH 10/10] Move free space info gathering into Storage.

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

 



---
 pyanaconda/storage/__init__.py      |   46 +++++++++++++++++++++++++++++++++++
 pyanaconda/ui/gui/spokes/storage.py |   34 ++++---------------------
 2 files changed, 52 insertions(+), 28 deletions(-)

diff --git a/pyanaconda/storage/__init__.py b/pyanaconda/storage/__init__.py
index 33f242c..0c5ace3 100644
--- a/pyanaconda/storage/__init__.py
+++ b/pyanaconda/storage/__init__.py
@@ -696,6 +696,52 @@ class Storage(object):
         """ The OS image used by live installs. """
         return None
 
+    def getFreeSpace(self, disks=None, clearPartType=None):
+        """ Return a dict with free space info for each disk.
+
+            The dict values are 2-tuples: (disk_free, fs_free). fs_free is
+            space available by shrinking filesystems. disk_free is space not
+            allocated to any partition.
+
+            disks and clearPartType allow specifying a set of disks other than
+            self.disks and a clearPartType value other than
+            self.config.clearPartType.
+        """
+        from partitioning import shouldClear
+        if disks is None:
+            disks = self.disks
+
+        if clearPartType is None:
+            clearPartType = self.config.clearPartType
+
+        free = {}
+        for disk in [d for d in disks if d.partitioned]:
+            should_clear = shouldClear(disk, clearPartType, [disk.name])
+            if should_clear:
+                free[disk.name] = (disk.size, 0)
+                continue
+
+            disk_free = 0
+            fs_free = 0
+            if disk.partitioned:
+                disk_free = disk.format.free
+                for partition in [p for p in self.partitions if p.disk == disk]:
+                    # only check actual filesystems since lvm &c require a bunch of
+                    # operations to translate free filesystem space into free disk
+                    # space
+                    should_clear = shouldClear(partition, clearPartType,
+                                               [d.name])
+                    if should_clear:
+                        disk_free += partition.size
+                    elif hasattr(partition.format, "free"):
+                        fs_free += partition.format.free
+            elif hasattr(disk.format, "free"):
+                fs_free = disk.format.free
+
+            free[disk.name] = (disk_free, fs_free)
+
+        return free
+
     def exceptionDisks(self):
         """ Return a list of removable devices to save exceptions to.
 
diff --git a/pyanaconda/ui/gui/spokes/storage.py b/pyanaconda/ui/gui/spokes/storage.py
index 1df29a9..7e532a5 100644
--- a/pyanaconda/ui/gui/spokes/storage.py
+++ b/pyanaconda/ui/gui/spokes/storage.py
@@ -96,27 +96,6 @@ def getDisks(devicetree, fake=False):
 
     return disks
 
-def get_free_space_info(disks, devicetree, clearPartType, clearPartDisks):
-    disk_free = 0
-    fs_free = 0
-    for disk in disks:
-        if not disk.partitioned:
-            continue
-
-        disk_free += disk.format.free
-
-        for partition in devicetree.getChildren(disk):
-            # only check actual filesystems since lvm &c require a bunch of
-            # operations to translate free filesystem space into free disk space
-            if shouldClear(partition, clearPartType, clearPartDisks):
-                disk_free += partition.size
-            elif hasattr(partition.format, "free"):
-                fs_free += partition.format.free
-
-    print("disks %s have %d free, plus %s in filesystems"
-          % ([d.name for d in disks], disk_free, fs_free))
-    return (disk_free, fs_free)
-
 def size_str(mb):
     if isinstance(mb, Size):
         spec = str(mb)
@@ -483,6 +462,7 @@ class StorageSpoke(NormalSpoke):
         free = 0
 
         overviews = self.local_disks_box.get_children()
+        free_space = self.storage.getFreeSpace(clearPartType=self.clearPartType)
         for overview in overviews:
             name = overview.get_property("popup-info").partition("|")[0].strip()
             selected = overview.get_chosen()
@@ -494,9 +474,7 @@ class StorageSpoke(NormalSpoke):
                         break
 
                 capacity += disk.size
-                free += get_free_space_info([disk], self.storage.devicetree,
-                                            self.clearPartType,
-                                            self.selected_disks)[0]
+                free += free_space[disk.name][0]
                 count += 1
 
         summary = (P_(("%d disk selected; %s capacity; %s free ..."),
@@ -553,10 +531,10 @@ class StorageSpoke(NormalSpoke):
     def on_continue_clicked(self, button):
         # show the installation options dialog
         disks = [d for d in self.disks if d.name in self.selected_disks]
-        (disk_free, fs_free) = get_free_space_info(disks,
-                                                   self.storage.devicetree,
-                                                   self.clearPartType,
-                                                   self.selected_disks)
+        free_space = self.storage.getFreeSpace(disks=disks,
+                                               clearPartType=self.clearPartType)
+        disk_free = sum([f[0] for f in free_space.itervalues()])
+        fs_free = sum([f[1] for f in free_space.itervalues()])
         required_space = self.payload.spaceRequired
         if disk_free >= required_space:
             dialog = InstallOptions1Dialog(self.data)
-- 
1.7.7.6

_______________________________________________
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