[blivet:rhel7/master 1/2] Make a class that creates a unique-per-class id for objects (#1043763)

mulhern amulhern at redhat.com
Mon Jan 6 21:16:13 UTC 2014


Related: rhbz#1043763

There are some objects that we would prefer to be able to track across a copy
or a deep copy. This is most likely when numerous instances of
more or less indistinguishable objects are created and when they are likely to
be copied during an anaconda run. DeviceFormat objects are the motivating
example.

Signed-off-by: mulhern <amulhern at redhat.com>
---
 blivet/util.py | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/blivet/util.py b/blivet/util.py
index d43b252..07dd77e 100644
--- a/blivet/util.py
+++ b/blivet/util.py
@@ -1,3 +1,4 @@
+import itertools
 import os
 import shutil
 import selinux
@@ -333,3 +334,20 @@ def insert_colons(a_string):
         return insert_colons(a_string[:-2]) + ':' + suffix
     else:
         return suffix
+
+class ObjectID(object):
+    """This class is meant to be extended by other classes which require
+       an ID which is preserved when an object copy is made.
+       The value returned by the builtin function id() is not adequate:
+       that value represents object identity so it is not in general
+       preserved when the object is copied.
+
+       The name of the identifier property is object_id, its type is int.
+
+       The constructor always sets object_id to a new value which is unique
+       for the object type.
+    """
+    _newid_gen = itertools.count().next
+
+    def __init__(self):
+        self.object_id = self._newid_gen()
-- 
1.8.3.1



More information about the anaconda-patches mailing list