[blivet] Allow user code creating free space snapshot
Vratislav Podzimek
vpodzime at redhat.com
Thu Aug 28 15:55:18 UTC 2014
Sometimes the user code (e.g. Anaconda) needs to snapshot available free space
so that it can lately read it and calculate with it.
This requires __deepcopy__ functionality for the Size class instances.
Related: rhbz#1132436
Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
---
blivet/__init__.py | 13 +++++++++++++
blivet/size.py | 3 +++
2 files changed, 16 insertions(+)
diff --git a/blivet/__init__.py b/blivet/__init__.py
index 9b1d33f..9bf6d0d 100644
--- a/blivet/__init__.py
+++ b/blivet/__init__.py
@@ -345,6 +345,7 @@ class Blivet(object):
self.fsset = FSSet(self.devicetree)
self.roots = []
self.services = set()
+ self._free_space_snapshot = None
def doIt(self):
self.devicetree.processActions()
@@ -2166,6 +2167,18 @@ class Blivet(object):
parent = getattr(self.ksdata, list_attr)
parent.dataList().append(data)
+ @property
+ def freeSpaceSnapshot(self):
+ # if no snapshot is available, do it now and return it
+ self._free_space_snapshot = self._free_space_snapshot or self.getFreeSpace()
+
+ return self._free_space_snapshot
+
+ def createFreeSpaceSnapshot(self):
+ self._free_space_snapshot = self.getFreeSpace()
+
+ return self._free_space_snapshot
+
def mountExistingSystem(fsset, rootDevice,
allowDirty=None, dirtyCB=None,
readOnly=None):
diff --git a/blivet/size.py b/blivet/size.py
index b21b3b9..1f64f7c 100644
--- a/blivet/size.py
+++ b/blivet/size.py
@@ -239,6 +239,9 @@ class Size(Decimal):
def __div__(self, other, context=None):
return Size(bytes=Decimal.__div__(self, other, context=context))
+ def __deepcopy__(self, memo):
+ return Size(self.convertTo(spec="b"))
+
def _trimEnd(self, val):
""" Internal method to trim trailing zeros. """
val = re.sub(r'(\.\d*?)0+$', '\\1', val)
--
1.9.3
More information about the anaconda-patches
mailing list