[PATCH] Add a deep copy method to Device since we can't just use copy.deepcopy.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The various parted objects cannot be copied using copy.deepcopy, so
we make shallow copies of those and deep copies of all other
attributes.
---
 storage/devices.py |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/storage/devices.py b/storage/devices.py
index aea00ea..b593ec7 100644
--- a/storage/devices.py
+++ b/storage/devices.py
@@ -92,8 +92,10 @@
 
 
 """
+
 import os
 import math
+import copy
 
 # device backend modules
 from devicelibs import mdraid
@@ -257,6 +259,24 @@ class Device(object):
         for parent in self.parents:
             parent.addChild()
 
+    def __deepcopy__(self, memo):
+        """ Create a deep copy of a Device instance.
+
+            We can't do copy.deepcopy on parted objects, which is okay.
+            For these parted objects, we just do a shallow copy.
+        """
+        new = self.__class__.__new__(self.__class__)
+        memo[id(self)] = new
+        shallow_copy_attrs = ('partedDisk', 'partedDevice',
+                             '_partedPartition', '_origPartedDisk')
+        for (attr, value) in self.__dict__.items():
+            if attr in shallow_copy_attrs:
+                setattr(new, attr, copy.copy(value))
+            else:
+                setattr(new, attr, copy.deepcopy(value, memo))
+
+        return new
+
     def removeChild(self):
         log_method_call(self, name=self.name, kids=self.kids)
         self.kids -= 1
-- 
1.6.0.6

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

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux