Signed-off-by: Vratislav Podzimek <vpodzime(a)redhat.com>
---
blivet/__init__.py | 9 ++++++
blivet/deviceaction.py | 85 +++++++++++++++++++++++++-------------------------
2 files changed, 52 insertions(+), 42 deletions(-)
diff --git a/blivet/__init__.py b/blivet/__init__.py
index 109f7b8..13cb523 100644
--- a/blivet/__init__.py
+++ b/blivet/__init__.py
@@ -316,6 +316,15 @@ class Blivet(object):
that should be called (see below for more info)
:type callbacks: dict (str -> function)
+ For now the following callbacks are supported (keywords and arguments
+ the called function gets):
+
+ { "CreateFormatPre": (msg),
+ "CreateFormatPost": (msg),
+ "ResizeFormatPre": (msg),
+ "ResizeFormatPost": (msg),
+ }
+
"""
self.devicetree.processActions(callbacks=callbacks)
diff --git a/blivet/deviceaction.py b/blivet/deviceaction.py
index d139436..7a162cd 100644
--- a/blivet/deviceaction.py
+++ b/blivet/deviceaction.py
@@ -37,17 +37,6 @@ _ = lambda x: gettext.ldgettext("blivet", x)
import logging
log = logging.getLogger("blivet")
-from contextlib import contextmanager
-
-@contextmanager
-def progress_report_stub(message):
- yield
-
-try:
- from pyanaconda.progress import progress_report
-except ImportError:
- progress_report = progress_report_stub
-
# The values are just hints as to the ordering.
# Eg: fsmod and devmod ordering depends on the mod (shrink -v- grow)
ACTION_TYPE_NONE = 0
@@ -452,33 +441,39 @@ class ActionCreateFormat(DeviceAction):
self.origFormat = getFormat(None)
def execute(self, callbacks=None):
- msg = _("Creating %(type)s on %(device)s") % {"type":
self.device.format.type, "device": self.device.path}
- with progress_report(msg):
- self.device.setup()
-
- if isinstance(self.device, PartitionDevice):
- for flag in partitionFlag.keys():
- # Keep the LBA flag on pre-existing partitions
- if flag in [ PARTITION_LBA, self.format.partedFlag ]:
- continue
- self.device.unsetFlag(flag)
-
- if self.format.partedFlag is not None:
- self.device.setFlag(self.format.partedFlag)
-
- if self.format.partedSystem is not None:
- self.device.partedPartition.system = self.format.partedSystem
-
- self.device.disk.format.commitToDisk()
-
- self.device.format.create(device=self.device.path,
- options=self.device.formatArgs)
- # Get the UUID now that the format is created
- udev_settle()
- self.device.updateSysfsPath()
- info = udev_get_block_device(self.device.sysfsPath)
- self.device.format.uuid = udev_device_get_uuid(info)
- self.device.deviceLinks = udev_device_get_symlinks(info)
+ if callbacks and "CreateFormatPre" in callbacks:
+ msg = _("Creating %(type)s on %(device)s") % {"type":
self.device.format.type, "device": self.device.path}
+ callbacks["CreateFormatPre"](msg)
+
+ self.device.setup()
+
+ if isinstance(self.device, PartitionDevice):
+ for flag in partitionFlag.keys():
+ # Keep the LBA flag on pre-existing partitions
+ if flag in [ PARTITION_LBA, self.format.partedFlag ]:
+ continue
+ self.device.unsetFlag(flag)
+
+ if self.format.partedFlag is not None:
+ self.device.setFlag(self.format.partedFlag)
+
+ if self.format.partedSystem is not None:
+ self.device.partedPartition.system = self.format.partedSystem
+
+ self.device.disk.format.commitToDisk()
+
+ self.device.format.create(device=self.device.path,
+ options=self.device.formatArgs)
+ # Get the UUID now that the format is created
+ udev_settle()
+ self.device.updateSysfsPath()
+ info = udev_get_block_device(self.device.sysfsPath)
+ self.device.format.uuid = udev_device_get_uuid(info)
+ self.device.deviceLinks = udev_device_get_symlinks(info)
+
+ if callbacks and "CreateFormatPost" in callbacks:
+ msg = _("Created %(type)s on %(device)s") % {"type":
self.device.format.type, "device": self.device.path}
+ callbacks["CreateFormatPost"](msg)
def cancel(self):
self.device.format = self.origFormat
@@ -593,10 +588,16 @@ class ActionResizeFormat(DeviceAction):
self.device.format.targetSize = newsize
def execute(self, callbacks=None):
- msg = _("Resizing filesystem on %(device)s") % {"device":
self.device.path}
- with progress_report(msg):
- self.device.setup(orig=True)
- self.device.format.doResize()
+ if callbacks and "ResizeFormatPre" in callbacks:
+ msg = _("Resizing filesystem on %(device)s") % {"device":
self.device.path}
+ callbacks["ResizeFormatPre"](msg)
+
+ self.device.setup(orig=True)
+ self.device.format.doResize()
+
+ if callbacks and "ResizeFormatPost" in callbacks:
+ msg = _("Resized filesystem on %(device)s") % {"device":
self.device.path}
+ callbacks["ResizeFormatPost"](msg)
def cancel(self):
self.device.format.targetSize = self.origSize
--
1.7.11.7