Looks like an improvement to me. On Thu, 2009-03-05 at 22:06 +0100, Joel Granados Moreno wrote: > --- > storage/devices.py | 23 +++++++++++++-------- > storage/devicetree.py | 50 ++++++++++++++++++++++++------------------------ > storage/errors.py | 3 ++ > 3 files changed, 42 insertions(+), 34 deletions(-) > > diff --git a/storage/devices.py b/storage/devices.py > index 84cfe1b..946f357 100644 > --- a/storage/devices.py > +++ b/storage/devices.py > @@ -101,6 +101,7 @@ from devicelibs import lvm > #import block > from devicelibs import dm > import parted > +import platform > > from errors import * > from iutil import log_method_call, notify_kernel, numeric_type > @@ -568,8 +569,8 @@ class DiskDevice(StorageDevice): > _type = "disk" > > def __init__(self, device, format=None, > - size=None, major=None, minor=None, > - sysfsPath='', parents=None, init = False, labeltype = None): > + size=None, major=None, minor=None, sysfsPath='', \ > + parents=None, initcb=None, kwargsinitcb=None): > """ Create a DiskDevice instance. > > Arguments: > @@ -586,8 +587,8 @@ class DiskDevice(StorageDevice): > parents -- a list of required Device instances > removable -- whether or not this is a removable device > > - init -- initialize label on this drive > - labeltype -- type of the label to use during initialization > + initcb -- the call back to be used when initiating disk. > + kwargs -- arguments for the intcb. If no args then = {} > > > DiskDevices always exist. > @@ -603,12 +604,16 @@ class DiskDevice(StorageDevice): > if not self.partedDevice: > raise DeviceError("cannot find parted device instance") > log.debug("creating parted Disk: %s" % self.path) > - if init: > - self.partedDisk = parted.freshDisk(device=self.partedDevice, ty = labeltype) > - else: > + try: > self.partedDisk = parted.Disk(device=self.partedDevice) > - if not self.partedDisk: > - raise DeviceError("failed to create parted Disk") > + except: > + # if we have a cb function use it. else an error. > + if initcb is not None and kwargsinitcb is not None and \ > + initcb(**kwargsinitcb): > + self.partedDisk = parted.freshDisk(device=self.partedDevice, \ > + ty = platform.getPlatform(None).diskType) > + else: > + raise DeviceUserDeniedFormatError("User prefered to not format.") > > self.probe() > > diff --git a/storage/devicetree.py b/storage/devicetree.py > index 3494d5a..374ef46 100644 > --- a/storage/devicetree.py > +++ b/storage/devicetree.py > @@ -27,8 +27,6 @@ from devices import * > from deviceaction import * > import formats > from udev import * > -import parted > -import platform > > import gettext > _ = lambda x: gettext.ldgettext("anaconda", x) > @@ -116,7 +114,26 @@ def getLUKSPassphrase(intf, device, globalPassphrase): > > return (passphrase, isglobal) > > - > +# Don't really know where to put this. > +def questionInitializeDisk(intf=None, name=None): > + retVal = False # The less destructive default > + if not intf or not name: > + pass > + else: > + rc = intf.messageWindow(_("Warning"), > + _("Error processing drive %s.\n" > + "Maybe it needs to be reinitialized." > + "YOU WILL LOSE ALL DATA ON THIS DRIVE!") % (name,), > + type="custom", > + custom_buttons = [ _("_Ignore drive"), > + _("_Re-initialize drive") ], > + custom_icon="question") > + if rc == 0: > + pass > + else: > + retVal = True > + return retVal > + > class DeviceTree(object): > """ A quasi-tree that represents the devices in the system. > > @@ -749,29 +766,12 @@ class DeviceTree(object): > device = DiskDevice(name, > major=udev_device_get_major(info), > minor=udev_device_get_minor(info), > - sysfsPath=sysfs_path) > + sysfsPath=sysfs_path, > + initcb=questionInitializeDisk, > + kwargsinitcb={"intf":self.intf, "name":name}) > self._addDevice(device) > - except parted.IOException: #drive not initialized? > - if not self.intf: > - self.ignoredDisks.append(name) > - else: > - rc = self.intf.messageWindow(_("Warning"), > - _("Error processing drive %s.\n" > - "Maybe it needs to be reinitialized." > - "YOU WILL LOSE ALL DATA ON THIS DRIVE!") % (name,), > - type="custom", > - custom_buttons = [ _("_Ignore drive"), > - _("_Re-initialize drive") ], > - custom_icon="question") > - if rc == 0: > - self.ignoredDisks.append(name) > - else: > - device = DiskDevice(name, > - major=udev_device_get_major(info), > - minor=udev_device_get_minor(info), > - sysfsPath=sysfs_path, init = True, > - labeltype = platform.getPlatform(None).diskType) > - self._addDevice(device) > + except DeviceUserDeniedFormatError: #drive not initialized? > + self.ignoredDisks.append(name) > elif udev_device_is_partition(info): > log.debug("%s is a partition" % name) > device = self.getDeviceByName(name) > diff --git a/storage/errors.py b/storage/errors.py > index 692e0ac..8fb57b1 100644 > --- a/storage/errors.py > +++ b/storage/errors.py > @@ -21,6 +21,9 @@ class DeviceTeardownError(DeviceError): > class DeviceResizeError(DeviceError): > pass > > +class DeviceUserDeniedFormatError(DeviceError): > + pass > + > # DeviceFormat > class DeviceFormatError(Exception): > pass _______________________________________________ Anaconda-devel-list mailing list Anaconda-devel-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/anaconda-devel-list