This allows for the backing DiskDevice._partedDisk to be created just-in-time, instead of when the instance is created. --- storage/devices.py | 49 +++++++++++++++++++++++++++++-------------------- 1 files changed, 29 insertions(+), 20 deletions(-) diff --git a/storage/devices.py b/storage/devices.py index 3439e86..3ca05aa 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,22 +762,14 @@ 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 - def __str__(self): s = StorageDevice.__str__(self) s += (" removable = %(removable)s partedDevice = %(partedDevice)r\n" @@ -795,7 +804,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) -- 1.6.4 _______________________________________________ Anaconda-devel-list mailing list Anaconda-devel-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/anaconda-devel-list