[blive:rhel7/master 2/3] Refactor to use ObjectID class (#1043763)

mulhern amulhern at redhat.com
Tue Jan 7 20:10:20 UTC 2014


Related: rhbz#1043763

Refactor Device and DeviceAction classes to use ObjectID instead of
their own internally implemented ids.

Signed-off-by: mulhern <amulhern at redhat.com>
---
 blivet/deviceaction.py | 11 +++--------
 blivet/devices.py      | 10 ++--------
 2 files changed, 5 insertions(+), 16 deletions(-)

diff --git a/blivet/deviceaction.py b/blivet/deviceaction.py
index a53fdb5..bb480a9 100644
--- a/blivet/deviceaction.py
+++ b/blivet/deviceaction.py
@@ -23,6 +23,7 @@
 
 from udev import *
 import math
+import util
 
 from devices import StorageDevice
 from devices import PartitionDevice
@@ -100,7 +101,7 @@ def resize_type_from_string(type_string):
         if v.lower() == type_string.lower():
             return k
 
-class DeviceAction(object):
+class DeviceAction(util.ObjectID):
     """ An action that will be carried out in the future on a Device.
 
         These classes represent actions to be performed on devices or
@@ -147,19 +148,13 @@ class DeviceAction(object):
     type = ACTION_TYPE_NONE
     obj = ACTION_OBJECT_NONE
     typeDesc = ""
-    _id = 0
 
     def __init__(self, device):
+        ObjectID.__init__(self)
         if not isinstance(device, StorageDevice):
             raise ValueError("arg 1 must be a StorageDevice instance")
         self.device = device
 
-        # Establish a unique id for each action instance. Making shallow or
-        # deep copyies of DeviceAction instances will require __copy__ and
-        # __deepcopy__ methods to handle incrementing the id in the copy
-        self.id = DeviceAction._id
-        DeviceAction._id += 1
-
     def execute(self):
         """ perform the action """
         pass
diff --git a/blivet/devices.py b/blivet/devices.py
index 5794d95..135ddc0 100644
--- a/blivet/devices.py
+++ b/blivet/devices.py
@@ -169,7 +169,7 @@ def deviceNameToDiskByPath(deviceName=None):
         return ret
     raise DeviceNotFoundError(deviceName)
 
-class Device(object):
+class Device(util.ObjectID):
     """ A generic device.
 
         Device instances know which devices they depend upon (parents
@@ -203,9 +203,6 @@ class Device(object):
 
     """
 
-    # This is a counter for generating unique ids for Devices.
-    _id = 0
-
     _type = "device"
     _packages = []
     _services = []
@@ -222,6 +219,7 @@ class Device(object):
                 parents -- a list of required Device instances
 
         """
+        util.ObjectID.__init__(self)
         self._name = name
         if parents is None:
             parents = []
@@ -230,10 +228,6 @@ class Device(object):
         self.parents = parents
         self.kids = 0
 
-        # Set this instance's id and increment the counter.
-        self.id = Device._id
-        Device._id += 1
-
         for parent in self.parents:
             parent.addChild()
 
-- 
1.8.3.1



More information about the anaconda-patches mailing list