FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Debian > Debian User

 
 
LinkBack Thread Tools
 
Old 03-05-2009, 08:06 PM
Joel Granados Moreno
 
Default Implement the format disk question as a callback.

---
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.
"
+ "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.
"
- "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
--
1.6.0.6

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 
Old 03-05-2009, 08:10 PM
David Lehman
 
Default Implement the format disk question as a callback.

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.
"
> + "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.
"
> - "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@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 
Old 03-05-2009, 08:17 PM
Chris Lumens
 
Default Implement the format disk question as a callback.

> storage/devices.py | 23 +++++++++++++--------
> storage/devicetree.py | 50 ++++++++++++++++++++++++------------------------
> storage/errors.py | 3 ++
> 3 files changed, 42 insertions(+), 34 deletions(-)

Yes, I definitely think this patch is an improvement. Comments to
follow inline...

> @@ -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.

I'd get rid of the kwargsinitcb parameter here and treat initcb as a lambda.
Also, there's no need for a slash in the arguments list.

> @@ -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()
>

Then here, you just call initcb() instead of messing with kwargsinitcb
as well.

> @@ -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.
"
> - "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)

And finally, your initcb parameter looks like this:

initcb=lambda intf,name: questionInitializeDisk(intf, name)

Just a thought, anyway. That's the kind of way I'd handle this but then
I do enjoy a little excessive use of lambdas. I guess the main problem
I had was that you don't really need to pass the arguments around
through several different functions. That to me clutters things up a
bit more. But I do like how you've moved the checking into the
DiskDevice class.

- Chris

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 
Old 03-06-2009, 09:16 AM
Radek Vykydal
 
Default Implement the format disk question as a callback.

Chris Lumens wrote:

And finally, your initcb parameter looks like this:

initcb=lambda intf,name: questionInitializeDisk(intf, name)



this is nice technique, I'll remember it, didn't you mean:

initcb=lambda: questionInitializeDisk(intf, name)

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 
Old 03-06-2009, 09:47 AM
Martin Sivak
 
Default Implement the format disk question as a callback.

Only one problem with this patch..

using except to catch all exceptioons is wrong a we were trying to get rid of those not so long ago in anaconda.
Otherwise, I agree with the callback.

Martin

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 
Old 03-06-2009, 12:46 PM
Joel Granados
 
Default Implement the format disk question as a callback.

On Thu, Mar 05, 2009 at 04:17:47PM -0500, Chris Lumens wrote:
> > storage/devices.py | 23 +++++++++++++--------
> > storage/devicetree.py | 50 ++++++++++++++++++++++++------------------------
> > storage/errors.py | 3 ++
> > 3 files changed, 42 insertions(+), 34 deletions(-)
>
> Yes, I definitely think this patch is an improvement. Comments to
> follow inline...
>
> > @@ -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.
>
> I'd get rid of the kwargsinitcb parameter here and treat initcb as a lambda.

Good idea..

> Also, there's no need for a slash in the arguments list.

I just like to put it everywhere I jump a line.

>
> > @@ -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()
> >
>
> Then here, you just call initcb() instead of messing with kwargsinitcb
> as well.
>
> > @@ -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.
"
> > - "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)
>
> And finally, your initcb parameter looks like this:
>
> initcb=lambda intf,name: questionInitializeDisk(intf, name)

But to hard code the values I would need to do it as Radek suggested.

>
> Just a thought, anyway. That's the kind of way I'd handle this but then
> I do enjoy a little excessive use of lambdas. I guess the main problem
> I had was that you don't really need to pass the arguments around
> through several different functions. That to me clutters things up a
> bit more. But I do like how you've moved the checking into the
> DiskDevice class.
>
> - Chris
>
> _______________________________________________
> Anaconda-devel-list mailing list
> Anaconda-devel-list@redhat.com
> https://www.redhat.com/mailman/listinfo/anaconda-devel-list

--
Joel Andres Granados
Brno, Czech Republic, Red Hat.

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 
Old 03-06-2009, 12:46 PM
Joel Granados
 
Default Implement the format disk question as a callback.

On Fri, Mar 06, 2009 at 05:47:58AM -0500, Martin Sivak wrote:
> Only one problem with this patch..
>
> using except to catch all exceptioons is wrong a we were trying to get rid of those not so long ago in anaconda.
> Otherwise, I agree with the callback.

will change.

>
> Martin
>
> _______________________________________________
> Anaconda-devel-list mailing list
> Anaconda-devel-list@redhat.com
> https://www.redhat.com/mailman/listinfo/anaconda-devel-list

--
Joel Andres Granados
Brno, Czech Republic, Red Hat.

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 
Old 03-06-2009, 02:00 PM
Chris Lumens
 
Default Implement the format disk question as a callback.

>> And finally, your initcb parameter looks like this:
>>
>> initcb=lambda intf,name: questionInitializeDisk(intf, name)
>>
>
> this is nice technique, I'll remember it, didn't you mean:
>
> initcb=lambda: questionInitializeDisk(intf, name)

Eh, I suppose that'll work. I guess it was just my aversion to free
variables or something.

- Chris

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 
Old 03-06-2009, 02:01 PM
Chris Lumens
 
Default Implement the format disk question as a callback.

> Only one problem with this patch..
>
> using except to catch all exceptioons is wrong a we were trying to get rid of those not so long ago in anaconda.
> Otherwise, I agree with the callback.

Agreed. Luckily I added _ped.DiskLabelException to pyparted yesterday
and David did a rebuild, so we should be able to just catch that one.

- Chris

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 
Old 03-06-2009, 02:53 PM
Joel Granados Moreno
 
Default Implement the format disk question as a callback.

---
storage/devices.py | 27 +++++++------
storage/devicetree.py | 101 +++++++++++++++++++++++++++----------------------
storage/errors.py | 3 +
3 files changed, 74 insertions(+), 57 deletions(-)

diff --git a/storage/devices.py b/storage/devices.py
index dd5a4f1..24153fc 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
@@ -636,8 +637,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):
""" Create a DiskDevice instance.

Arguments:
@@ -654,8 +655,7 @@ 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.


DiskDevices always exist.
@@ -671,12 +671,15 @@ 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 parted.IOException:
+ # if we have a cb function use it. else an error.
+ if initcb is not None and initcb():
+ self.partedDisk = parted.freshDisk(device=self.partedDevice,
+ ty = platform.getPlatform(None).diskType)
+ else:
+ raise DeviceUserDeniedFormatError("User prefered to not format.")

self.probe()

@@ -2159,7 +2162,7 @@ class DMRaidArrayDevice(DiskDevice):
devDir = "/dev/mapper"

def __init__(self, name, raidSet=None, level=None, format=None, size=None,
- major=None, minor=None, parents=None, sysfsPath='):
+ major=None, minor=None, parents=None, sysfsPath=', initcb=None):
""" Create a DMRaidArrayDevice instance.

Arguments:
@@ -2180,8 +2183,8 @@ class DMRaidArrayDevice(DiskDevice):
if not parent.format or parent.format.type != "dmraidmember":
raise ValueError("parent devices must contain dmraidmember format")
DiskDevice.__init__(self, name, format=format, size=size,
- major=major, minor=minor,
- parents=parents, sysfsPath=sysfsPath)
+ major=major, minor=minor, parents=parents,
+ sysfsPath=sysfsPath, initcb=initcb)

self.formatClass = get_device_format_class("dmraidmember")
if not self.formatClass:
diff --git a/storage/devicetree.py b/storage/devicetree.py
index 41e43f9..af265a7 100644
--- a/storage/devicetree.py
+++ b/storage/devicetree.py
@@ -28,8 +28,6 @@ from devices import *
from deviceaction import *
import formats
from udev import *
-import parted
-import platform

import gettext
_ = lambda x: gettext.ldgettext("anaconda", x)
@@ -117,7 +115,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.
"
+ "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.

@@ -778,32 +795,15 @@ class DeviceTree(object):
device = self.getDeviceByName(name)
if device is None:
try:
+ cb=lambda:questionInitializeDisk(self.intf, name)
device = DiskDevice(name,
major=udev_device_get_major(info),
minor=udev_device_get_minor(info),
- sysfsPath=sysfs_path)
+ sysfsPath=sysfs_path,
+ initcb=cb)
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.
"
- "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)
@@ -954,27 +954,38 @@ class DeviceTree(object):
# FIXME: Should handle not finding a dmriad dev better
pass

- dm_array = self.getDeviceByName(rs.name)
- if dm_array is not None:
- # We add the new device.
- dm_array._addDevice(device)
+ if rs.name not in self.ignoredDisks:
+ dm_array = self.getDeviceByName(rs.name)
+ if dm_array is not None:
+ # We add the new device.
+ dm_array._addDevice(device)
+ else:
+ # Activate the Raid set.
+ rs.activate(mknod=True)
+
+ # Create the DMRaidArray
+ try:
+ cb=lambda:questionInitializeDisk(self.intf,rs.name )
+ dm_array = DMRaidArrayDevice(rs.name,
+ major=major, minor=minor,
+ raidSet=rs,
+ level=rs.level,
+ parents=[device],
+ initcb=cb)
+ except DeviceUserDeniedFormatError:
+ self.ignoredDisks.append(rs.name)
+ rs.deactivate()
+
+ self._addDevice(dm_array)
+
+ # Use the rs's object on the device.
+ device.format.raidmem = block.getMemFromRaidSet(dm_array,
+ major=major, minor=minor,
+ uuid=uuid, name=name)
else:
- # Activate the Raid set.
- rs.activate(mknod=True)
-
- # Create the DMRaidArray
- dm_array = DMRaidArrayDevice(rs.name,
- major=major, minor=minor,
- raidSet=rs,
- level=rs.level,
- parents=[device])
-
- self._addDevice(dm_array)
-
- # Use the rs's object on the device.
- device.format.raidmem = block.getMemFromRaidSet(dm_array,
- major=major, minor=minor,
- uuid=uuid, name=name)
+ # Here we might want to make sure we ignore all of the
+ # devices that compose the dmriad.
+ pass
elif format.type == "lvmpv":
# lookup/create the VG and LVs
try:
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
--
1.6.0.6

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 

Thread Tools




All times are GMT. The time now is 09:34 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org