summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Jones <pjones@redhat.com>2009-08-06 10:16:54 -0400
committerPeter Jones <pjones@redhat.com>2009-08-06 14:37:46 -0400
commitd8c8d1fce78ce019209f1e1843b02bbaf6627004 (patch)
tree24308bfa74bb32e5a5925f693373b4e7282356d4
parent3c1254a255c60933fcbd41191b784e642a838256 (diff)
downloadanaconda-d8c8d1fce78ce019209f1e1843b02bbaf6627004.tar.gz
anaconda-d8c8d1fce78ce019209f1e1843b02bbaf6627004.tar.xz
anaconda-d8c8d1fce78ce019209f1e1843b02bbaf6627004.zip
Make DiskDevice.partedDisk a property.
This allows for the backing DiskDevice._partedDisk to be created just-in-time, instead of when the instance is created.
-rw-r--r--storage/devices.py49
1 files changed, 30 insertions, 19 deletions
diff --git a/storage/devices.py b/storage/devices.py
index 3439e8663..2d6a2942b 100644
--- a/storage/devices.py
+++ b/storage/devices.py
@@ -235,7 +235,7 @@ class Device(object):
"""
new = self.__class__.__new__(self.__class__)
memo[id(self)] = new
- shallow_copy_attrs = ('partedDisk', '_partedDevice',
+ shallow_copy_attrs = ('_partedDisk', '_partedDevice',
'_partedPartition', '_origPartedDisk',
'_raidSet')
for (attr, value) in self.__dict__.items():
@@ -722,22 +722,39 @@ class DiskDevice(StorageDevice):
StorageDevice.__init__(self, device, format=format, size=size,
major=major, minor=minor, exists=True,
sysfsPath=sysfsPath, parents=parents)
+ self._partedDisk = None
+ self._initlabel = initlabel
+ self._initcb = initcb
- self.partedDisk = None
+ # We save the actual state of the disk here. Before the first
+ # modification (addPartition or removePartition) to the partition
+ # table we reset self.partedPartition to this state so we can
+ # perform the modifications one at a time.
+ if self.partedDisk:
+ self._origPartedDisk = self.partedDisk.duplicate()
+ else:
+ self._origPartedDisk = None
+
+
+ @property
+ def partedDisk(self):
+ if self._partedDisk:
+ return self._partedDisk
log.debug("looking up parted Device: %s" % self.path)
if self.partedDevice:
log.debug("creating parted Disk: %s" % self.path)
- if initlabel:
- self.partedDisk = self.freshPartedDisk()
+ if self._initlabel:
+ self._partedDisk = self.freshPartedDisk()
else:
try:
- self.partedDisk = parted.Disk(device=self.partedDevice)
+ self._partedDisk = parted.Disk(device=self.partedDevice)
except _ped.DiskLabelException:
# 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, \
+ if self._initcb is not None and self._initcb():
+ self._partedDisk = parted.freshDisk( \
+ device=self.partedDevice, \
ty = platform.getPlatform(None).diskType)
else:
raise DeviceUserDeniedFormatError("User prefered to not format.")
@@ -745,21 +762,15 @@ class DiskDevice(StorageDevice):
# When the device has no partition table but it has a FS, it
# will be created with label type loop. Treat the same as if
# the device had no label (cause it really doesn't).
- if self.partedDisk.type == "loop":
- if initcb is not None and initcb():
- self.partedDisk = parted.freshDisk(device=self.partedDevice, \
+ if self._partedDisk.type == "loop":
+ if self._initcb is not None and self._initcb():
+ self._partedDisk = parted.freshDisk( \
+ device=self.partedDevice, \
ty = platform.getPlatform(None).diskType)
else:
raise DeviceUserDeniedFormatError("User prefered to not format.")
- # We save the actual state of the disk here. Before the first
- # modification (addPartition or removePartition) to the partition
- # table we reset self.partedPartition to this state so we can
- # perform the modifications one at a time.
- if self.partedDisk:
- self._origPartedDisk = self.partedDisk.duplicate()
- else:
- self._origPartedDisk = None
+ return self._partedDisk
def __str__(self):
s = StorageDevice.__str__(self)
@@ -795,7 +806,7 @@ class DiskDevice(StorageDevice):
def resetPartedDisk(self):
""" Reset parted.Disk to reflect the actual layout of the disk. """
log_method_call(self, self.name)
- self.partedDisk = self._origPartedDisk
+ self._partedDisk = self._origPartedDisk
def removePartition(self, device):
log_method_call(self, self.name, part=device.name)